From 13b56064db3bfdc02aa52a01d8e8c50543a5e021 Mon Sep 17 00:00:00 2001 From: david Date: Sat, 6 Jul 2013 13:00:39 +0200 Subject: [PATCH] moved config section to down script start and put the find home routine into a function --- sshbackup | 75 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 32 deletions(-) diff --git a/sshbackup b/sshbackup index e0f0b9b..c0babad 100755 --- a/sshbackup +++ b/sshbackup @@ -1,32 +1,12 @@ #!/bin/bash + # ************************************* # # # # sshbackup # # # # ************************************* # -# **** config section **** -version="0.4.0" -author="david@socialnerds.org" - -configfile="$HOME/.sshbackup" -#rsync options. -rsyncoptions="-qpogEthrzl --numeric-ids --no-motd" -#dotglob option removes bug while rsyncing folder with no visible files in it. -remotecmd="shopt -s dotglob; /usr/bin/sudo /usr/bin/rsync" -localcmd="/usr/bin/rsync" - -versions=999 -config=0 -sshkey=0 -bandwidth=0 -limit=0 -list=0 -noroot=0 -deploy=0 -options=$* - # **** function definitions **** bashtrap() @@ -116,6 +96,23 @@ amiroot() fi } +findhome() +{ + #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 + #return home directory + echo $home +} + preflight() { #amiroot? @@ -135,18 +132,9 @@ preflight() #if there is a remote source or destination check for ssh key if [[ $sourcepath =~ .*@.* ]] || [[ $destpath =~ .*@.* ]]; then - - #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 + #find the executing users home directory + local home=$(findhome) #if $sshkeyfile is not set use this path if [ -z $sshkeyfile ]; then @@ -227,6 +215,29 @@ sshbackup() } +# **** config section **** +version="0.4.0" +author="david@socialnerds.org" + +configfile="$HOME/.sshbackup" + +#rsync options. +rsyncoptions="-qpogEthrzl --numeric-ids --no-motd" +#dotglob option removes bug while rsyncing folder with no visible files in it. +remotecmd="shopt -s dotglob; /usr/bin/sudo /usr/bin/rsync" +localcmd="/usr/bin/rsync" + +versions=999 +config=0 +sshkey=0 +bandwidth=0 +limit=0 +list=0 +noroot=0 +deploy=0 +options=$* + + # **** start of script **** #initialize bashtrap