From 3ad19c717a773db6d43a2756e22fcc26e2814edc Mon Sep 17 00:00:00 2001 From: Fazle Arefin Date: Sun, 22 Feb 2015 22:56:33 +1100 Subject: [PATCH] Minor changes to make script more versatile --- ssh-copy-id-auto.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/ssh-copy-id-auto.sh b/ssh-copy-id-auto.sh index afb644f..82cd8a3 100755 --- a/ssh-copy-id-auto.sh +++ b/ssh-copy-id-auto.sh @@ -6,25 +6,25 @@ # TODO: change this path to the file containing your password # the password can be in plain-text or base64 encoded; don't add any blank line -# if the password is base64 encoded, change the value of $BASE64_ENC -export PWDFILE='/home/fazle/.passwd/fazle' +# if the password is base64 encoded, change the value of $Base64_Enc +export Pwd_File='/home/fazle/.passwd/fazle' # TODO: base64 encoding; 0 is off, 1 is on -export BASE64_ENC=0 +export Base64_Enc=0 # TODO: number of hosts to copy your key in parallel -PARALLEL_COPY=10 +Parallel_Copy=10 -HOSTS=$@ +Hosts=$@ # some basic checks -if [ "$1" == "" ]; then +if [[ "$1" == "" ]]; then echo "No host(s) provided" 1>&2 exit 44 -elif [ 0 -ne $(which sshpass &> /dev/null)$? ]; then +elif [[ 0 -ne $(hash sshpass &> /dev/null)$? ]]; then echo "Install sshpass first" 1>&2 exit 55 -elif ! [ -f $PWDFILE ]; then +elif ! [[ -f $Pwd_File ]]; then echo "Password file missing" 1>&2 exit 66 fi @@ -32,13 +32,13 @@ fi copy_ssh_id() { host=$(echo -n $1) # strip the newline character from $1 - if [ $BASE64_ENC -eq 1 ]; then - sshpass -p "$(base64 -d $PWDFILE)" ssh-copy-id -o ConnectTimeout=5 $host &> /dev/null + if [[ $Base64_Enc -eq 1 ]]; then + sshpass -p "$(base64 -d $Pwd_File)" ssh-copy-id -o ConnectTimeout=5 $host &> /dev/null else - sshpass -p "$(cat $PWDFILE)" ssh-copy-id -o ConnectTimeout=5 $host &> /dev/null + sshpass -p "$(cat $Pwd_File)" ssh-copy-id -o ConnectTimeout=5 $host &> /dev/null fi - if [ $? -eq 0 ]; then + if [[ $? -eq 0 ]]; then echo "✔ Copied ssh public key to $host" 1>&2 else echo "✘ Could not copy ssh public key to $host" 1>&2 @@ -47,5 +47,5 @@ copy_ssh_id() { export -f copy_ssh_id -echo ${HOSTS[*]} | xargs -d' ' -n1 -P${PARALLEL_COPY} bash -c 'copy_ssh_id "$@"' _ +echo ${Hosts[*]} | xargs -d' ' -n1 -P${Parallel_Copy} bash -c 'copy_ssh_id "$@"' _