mirror of
https://github.com/unifi-utilities/unifios-utilities.git
synced 2024-08-30 18:32:21 +00:00
[on-boot-script] Improve example scripts (add-cron-jobs, add-root-ssh-key(s)) (#270)
* [on-boot-script] Improve add-cron-jobs example script * Add .sh extension for consistency * Small improvements to documentation * [on-boot-script] Improve add-root-ssh-key(s) example script * Complete rewrite of script * Rename from "add-root-ssh-key" to "add-root-ssh-keys"
This commit is contained in:
parent
cb9c5435fd
commit
feac1111d7
@ -1,31 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
#####################################################
|
|
||||||
# ADD RSA KEYS AS BELOW - CHANGE BEFORE RUNNING #
|
|
||||||
#####################################################
|
|
||||||
# set -- "ssh-rsa first key here all keys quoted" \ #
|
|
||||||
# "ssh-rsa each line appended with slash " \ #
|
|
||||||
# "ssh-rsa last one has no backslash" #
|
|
||||||
#####################################################
|
|
||||||
set -- "ssh-rsa AAAABUNCHOFCHARACTERSANDSTUFF me on MyMachine" \
|
|
||||||
"ssh-rsa AAAADIFFERENTKEYWITHCHARSETC! user@myhost"
|
|
||||||
|
|
||||||
KEYS_FILE="/root/.ssh/authorized_keys"
|
|
||||||
|
|
||||||
counter=0
|
|
||||||
for key in "$@"
|
|
||||||
do
|
|
||||||
## Places public key in ~/.ssh/authorized_keys if not present
|
|
||||||
if ! grep -Fxq "$key" "$KEYS_FILE"; then
|
|
||||||
let counter++
|
|
||||||
echo "$key" >> "$KEYS_FILE"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
echo $counter keys added to $KEYS_FILE
|
|
||||||
|
|
||||||
echo Converting SSH private key to dropbear format
|
|
||||||
#convert ssh key to dropbear for shell interaction
|
|
||||||
dropbearconvert openssh dropbear /mnt/data/ssh/id_rsa /root/.ssh/id_dropbear
|
|
||||||
|
|
||||||
exit 0;
|
|
@ -0,0 +1,29 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
## Places public keys in ~/.ssh/authorized_keys
|
||||||
|
|
||||||
|
KEYS_SOURCE_FILE="/mnt/data/on_boot.d/settings/ssh/authorized_keys"
|
||||||
|
KEYS_TARGET_FILE="/root/.ssh/authorized_keys"
|
||||||
|
|
||||||
|
count_added=0
|
||||||
|
count_skipped=0
|
||||||
|
while read -r key; do
|
||||||
|
# Places public key in ~/.ssh/authorized_keys if not present
|
||||||
|
if ! grep -Fxq "$key" "$KEYS_TARGET_FILE"; then
|
||||||
|
let count_added++
|
||||||
|
echo "$key" >> "$KEYS_TARGET_FILE"
|
||||||
|
else
|
||||||
|
let count_skipped++
|
||||||
|
fi
|
||||||
|
done < "$KEYS_SOURCE_FILE"
|
||||||
|
|
||||||
|
echo "${count_added} keys added to ${KEYS_TARGET_FILE}"
|
||||||
|
if [ $count_skipped -gt 0 ]; then
|
||||||
|
echo "${count_skipped} already added keys skipped"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Convert ssh key to dropbear for shell interaction
|
||||||
|
echo "Converting SSH private key to dropbear format"
|
||||||
|
dropbearconvert openssh dropbear /mnt/data/ssh/id_rsa /root/.ssh/id_dropbear
|
||||||
|
|
||||||
|
exit 0
|
@ -1,8 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# store crontab files in /mnt/data/cronjobs/ (you will need to create this foler)
|
|
||||||
# this script will re-add them on startup
|
|
||||||
|
|
||||||
cp /mnt/data/cronjobs/* /etc/cron.d/
|
|
||||||
/etc/init.d/crond restart
|
|
||||||
|
|
||||||
exit 0
|
|
@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
## Store crontab files in /mnt/data/cronjobs/ (you will need to create this folder).
|
||||||
|
## This script will re-add them on startup.
|
||||||
|
|
||||||
|
cp /mnt/data/cronjobs/* /etc/cron.d/
|
||||||
|
/etc/init.d/crond restart
|
||||||
|
|
||||||
|
exit 0
|
Loading…
x
Reference in New Issue
Block a user