moved config section to down script start and put the find home routine into a function
This commit is contained in:
parent
b4ba7b50a2
commit
13b56064db
75
sshbackup
75
sshbackup
|
@ -1,32 +1,12 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
# ************************************* #
|
# ************************************* #
|
||||||
# #
|
# #
|
||||||
# sshbackup #
|
# 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 ****
|
# **** function definitions ****
|
||||||
bashtrap()
|
bashtrap()
|
||||||
|
@ -116,6 +96,23 @@ amiroot()
|
||||||
fi
|
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()
|
preflight()
|
||||||
{
|
{
|
||||||
#amiroot?
|
#amiroot?
|
||||||
|
@ -135,18 +132,9 @@ preflight()
|
||||||
|
|
||||||
#if there is a 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 [[ $sourcepath =~ .*@.* ]] || [[ $destpath =~ .*@.* ]]; then
|
||||||
|
|
||||||
#get executing user id
|
|
||||||
local userid=$(id -u)
|
|
||||||
|
|
||||||
#find out where executing users $HOME is
|
#find the executing users home directory
|
||||||
while read line; do
|
local home=$(findhome)
|
||||||
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 $sshkeyfile is not set use this path
|
#if $sshkeyfile is not set use this path
|
||||||
if [ -z $sshkeyfile ]; then
|
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 ****
|
# **** start of script ****
|
||||||
|
|
||||||
#initialize bashtrap
|
#initialize bashtrap
|
||||||
|
|
Reference in New Issue