From 1713d292d181484d4c66b2f56a823e68c92b656f Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 31 Oct 2015 20:26:00 +0000 Subject: [PATCH] Check for ssh public key --- src/freedombone-adduser | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/freedombone-adduser b/src/freedombone-adduser index f92a82fd..4a61f6e7 100755 --- a/src/freedombone-adduser +++ b/src/freedombone-adduser @@ -1,6 +1,6 @@ #!/bin/bash MY_USERNAME=$1 -SSH_PUBLIC_KEY=$2 +SSH_PUBLIC_KEY="$2" GPG_KEYSERVER='hkp://keys.gnupg.net' SSH_PORT=2222 COMPLETION_FILE=$HOME/freedombone-completed.txt @@ -30,19 +30,21 @@ if [ ! -d /home/$MY_USERNAME ]; then exit 4 fi -if [ $2 ]; then - if [ -f $SSH_PUBLIC_KEY ]; then - mkdir /home/$MY_USERNAME/.ssh - cp $SSH_PUBLIC_KEY /home/$MY_USERNAME/.ssh/authorized_keys - echo 'ssh public key installed' - else - if [[ $SSH_PUBLIC_KEY == "ssh-"* ]]; then +if [ "$SSH_PUBLIC_KEY" ]; then + if [ ${#SSH_PUBLIC_KEY} -gt 5 ]; then + if [ -f $SSH_PUBLIC_KEY ]; then mkdir /home/$MY_USERNAME/.ssh - echo $SSH_PUBLIC_KEY > /home/$MY_USERNAME/.ssh/authorized_keys + cp $SSH_PUBLIC_KEY /home/$MY_USERNAME/.ssh/authorized_keys echo 'ssh public key installed' else - echo 'The second parameter does not look like an ssh key' - exit 5 + if [[ $SSH_PUBLIC_KEY == "ssh-"* ]]; then + mkdir /home/$MY_USERNAME/.ssh + echo $SSH_PUBLIC_KEY > /home/$MY_USERNAME/.ssh/authorized_keys + echo 'ssh public key installed' + else + echo 'The second parameter does not look like an ssh key' + exit 5 + fi fi fi fi