2023-02-19 03:31:32 +00:00
|
|
|
#!/bin/sh
|
2023-02-22 16:49:54 +00:00
|
|
|
# Get DataDir location
|
|
|
|
DATA_DIR="/data"
|
|
|
|
case "$(ubnt-device-info firmware || true)" in
|
|
|
|
1*)
|
|
|
|
DATA_DIR="/mnt/data"
|
|
|
|
;;
|
|
|
|
2*)
|
|
|
|
DATA_DIR="/data"
|
|
|
|
;;
|
|
|
|
3*)
|
|
|
|
DATA_DIR="/data"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "ERROR: No persistent storage found." 1>&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2023-02-19 03:31:32 +00:00
|
|
|
## Places public keys in ~/.ssh/authorized_keys
|
|
|
|
|
2023-02-22 16:49:54 +00:00
|
|
|
KEYS_SOURCE_FILE="${DATA_DIR}/on_boot.d/settings/ssh/authorized_keys"
|
2023-02-19 03:31:32 +00:00
|
|
|
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++
|
2023-02-22 16:49:54 +00:00
|
|
|
echo "$key" >>"$KEYS_TARGET_FILE"
|
2023-02-19 03:31:32 +00:00
|
|
|
else
|
2023-02-22 16:49:54 +00:00
|
|
|
let count_skipped++
|
2023-02-19 03:31:32 +00:00
|
|
|
fi
|
2023-02-22 16:49:54 +00:00
|
|
|
done <"$KEYS_SOURCE_FILE"
|
2023-02-19 03:31:32 +00:00
|
|
|
|
|
|
|
echo "${count_added} keys added to ${KEYS_TARGET_FILE}"
|
|
|
|
if [ $count_skipped -gt 0 ]; then
|
2023-02-22 16:49:54 +00:00
|
|
|
echo "${count_skipped} already added keys skipped"
|
2023-02-19 03:31:32 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Convert ssh key to dropbear for shell interaction
|
|
|
|
echo "Converting SSH private key to dropbear format"
|
2023-02-22 16:49:54 +00:00
|
|
|
dropbearconvert openssh dropbear ${DATA_DIR}/ssh/id_rsa /root/.ssh/id_dropbear
|
2023-02-19 03:31:32 +00:00
|
|
|
|
|
|
|
exit 0
|