From b1687681f88edab911fade00ff606ded184ac753 Mon Sep 17 00:00:00 2001 From: Gerd Naschenweng Date: Sun, 18 Dec 2022 11:34:44 +0100 Subject: [PATCH 1/2] 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 --- 99-ssh-keys.sh | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/99-ssh-keys.sh b/99-ssh-keys.sh index e503d02..ec7bb01 100755 --- a/99-ssh-keys.sh +++ b/99-ssh-keys.sh @@ -1,9 +1,27 @@ #!/bin/sh -user_authorized_keys_file="/mnt/data/ssh/authorized_keys" +# 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 /mnt/data/ssh/authorized_keys is missing print error message +# 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 From df41bff4fee80eddea2a25b9e96970a8d4d0af8f Mon Sep 17 00:00:00 2001 From: Gerd Naschenweng Date: Sun, 18 Dec 2022 11:37:41 +0100 Subject: [PATCH 2/2] Supporting new firmwares Supporting new data-directories for new firmwares. Tested un UDM Pro 2.4.23 --- install.sh | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index 6407a58..9f621be 100644 --- a/install.sh +++ b/install.sh @@ -1,15 +1,33 @@ #!/bin/sh -user_authorized_keys_file="/mnt/data/ssh/authorized_keys" +# 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" curl -sO https://raw.githubusercontent.com/fire1ce/UDM-Persistent-SSH-Keys/main/99-ssh-keys.sh -mv 99-ssh-keys.sh /mnt/data/on_boot.d/99-ssh-keys.sh -chmod +x /mnt/data/on_boot.d/99-ssh-keys.sh +mv 99-ssh-keys.sh $DATA_DIR/on_boot.d/99-ssh-keys.sh +chmod +x $DATA_DIR/on_boot.d/99-ssh-keys.sh echo "99-ssh-keys.sh installed" if [ ! -f "$user_authorized_keys_file" ]; then echo "Creating $user_authorized_keys_file" - mkdir -p /mnt/data/ssh + mkdir -p $DATA_DIR/ssh touch "$user_authorized_keys_file" chmod 0644 "$user_authorized_keys_file" fi