From f758c29c00572273786f17ddccf0abf70f9738d8 Mon Sep 17 00:00:00 2001 From: david Date: Mon, 1 Jul 2013 21:18:15 +0200 Subject: [PATCH] moved key management draft into preflight function --- sshbackup | 88 ++++++++++++++++++++++++------------------------------- 1 file changed, 39 insertions(+), 49 deletions(-) diff --git a/sshbackup b/sshbackup index 97d5a01..80e3487 100755 --- a/sshbackup +++ b/sshbackup @@ -89,61 +89,51 @@ preflight() return 1 fi - #if remote source or destination check for ssh key + #if there is a remote source or destination check for ssh key if [[ $sourcepath =~ .*@.* ]] || [[ $destpath =~ .*@.* ]]; then - #if [ -r $sshkeyfile ]; then - # #echo "sshkeyfile found. continuing." - # : - #else - # echo "aborting mission. no sshkey found." - # return 1 - #fi - keymgmt + + #get executing user id + local userid=$(id -u) + + #find out where executing users $HOME is + while read line; do + line=$(echo $line | sed 's/ //g') + line=$(echo $line | sed 's/:/ /g') + if [ $(echo $line | awk '{print $3}') -eq $userid ]; then + local home=$(echo $line | awk '{print $6}') + fi + done < /etc/passwd + + if [ -z $sshkeyfile ]; then + sshkeyfile="$home/.ssh/id_rsa" + fi + if [ -r $sshkeyfile ]; then + #ssh key found + : + else + if ( interactive ); then + echo "no ssh key found" + echo -e "do you want to create a ssh key pair? [y/n] \c" + read choice + if [ -z $choice ]; then + echo "aborting mission. no ssh key found." + return 1 + elif [ $choice == "y" ] || [ $choice == "Y" ]; then + #creating ssh key pair + ssh-keygen + #TODO: key should also be deployed to remote side + return 1 #for now i'll break up here + fi + else + echo "aborting mission. no ssh key found." + return 1 + fi + fi fi return 0 } -keymgmt() -{ - #get executing user id - local userid=$(id -u) - - #find out where executing users $HOME is - while read line; do - line=$(echo $line | sed 's/ //g') - line=$(echo $line | sed 's/:/ /g') - if [ $(echo $line | awk '{print $3}') -eq $userid ]; then - local home=$(echo $line | awk '{print $6}') - fi - done < /etc/passwd - - if [ -z $sshkeyfile ]; then - sshkeyfile="$home/.ssh/id_rsa" - fi - - if [ -r $sshkeyfile ]; then - #ssh key found - : - else - if ( interactive ); then - echo "no ssh key found" - echo -e "do you want to create a ssh key pair? [y/n] \c" - read choice - if [ -z $choice ]; then - echo "aborting mission. no ssh key found." - exit 1 - elif [ $choice == "y" ] || [ $choice == "Y" ]; then - #creating ssh key pair - ssh-keygen - fi - else - echo "aborting mission. no ssh key found." - exit 1 - fi - fi -} - sshbackup() { #creating local rsync options var