UDM-Persistent-SSH-Keys/99-ssh-keys.sh
Gerd Naschenweng b1687681f8
Adjusted script to cater for UDM Pro 2.4.23
Adjusted script to cater for new data locations supporting UDM firmwares 1.x, 2.x and 3.x
2022-12-18 11:34:44 +01:00

37 lines
831 B
Bash
Executable File

#!/bin/sh
# Get DataDir location
DATA_DIR="/mnt/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
user_authorized_keys_file="$DATA_DIR/ssh/authorized_keys"
udm_authorized_keys_file="/root/.ssh/authorized_keys"
# if $DATA_DIR/ssh/authorized_keys is missing print error message
if [ ! -f "$user_authorized_keys_file" ]; then
echo "ERROR: $user_authorized_keys_file is missing"
exit 1
fi
# Reads the user file line by line and adds the key to the authorized_keys file
file=$user_authorized_keys_file
while IFS= read -r line || [ -n "$line" ]; do
echo $line >>$udm_authorized_keys_file
done <"$file"
exit 0