david/sshbackup
david
/
sshbackup
Archived
1
0
Fork 0

moved config section to down script start and put the find home routine into a function

This commit is contained in:
david 2013-07-06 13:00:39 +02:00
parent b4ba7b50a2
commit 13b56064db
1 changed files with 43 additions and 32 deletions

View File

@ -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