added sshbackupv03 draft with a nice little unfinished option handler
This commit is contained in:
parent
70704f01c7
commit
e4d95f75f0
|
@ -1,26 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
# shell option handler
|
||||
|
||||
version="0.1"
|
||||
author="david@socialnerds.org"
|
||||
|
||||
|
||||
while getopts c:s:vh options
|
||||
do
|
||||
case "$options" in
|
||||
c)
|
||||
echo "configfile = $OPTARG";;
|
||||
s)
|
||||
echo "sourcefile = $OPTARG";;
|
||||
v)
|
||||
echo "version message";;
|
||||
h)
|
||||
echo "help message";;
|
||||
?)
|
||||
echo "questionmark";;
|
||||
*)
|
||||
echo "nothing";;
|
||||
esac
|
||||
done
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
#!/bin/sh
|
||||
|
||||
# ************************************* #
|
||||
# #
|
||||
# sshbackup #
|
||||
# #
|
||||
# ************************************* #
|
||||
|
||||
# **** config section ****
|
||||
version="0.3.0"
|
||||
author="david@socialnerds.org"
|
||||
|
||||
configfile="$HOME/.sshbackup"
|
||||
sourcefile=""
|
||||
#rsync options.
|
||||
rsyncoptions="-pogEthrzl --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"
|
||||
|
||||
#where should i write the log file?
|
||||
logfile="/var/log/sshbackup.log"
|
||||
|
||||
sshkeyfile="$HOME/.ssh/id_rsa"
|
||||
|
||||
config=0
|
||||
sources=0
|
||||
options=$*
|
||||
|
||||
|
||||
# **** function definitions ****
|
||||
bashtrap()
|
||||
{
|
||||
|
||||
echo
|
||||
echo "CTRL+C detected."
|
||||
echo "commiting suicide."
|
||||
exit 1
|
||||
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
|
||||
echo
|
||||
echo "usage: sshbackup <options> [[user@]server:]/source/path [[user@]server:]/destination/path [versions]"
|
||||
echo
|
||||
echo "OPTIONS:"
|
||||
echo " -h, --help show this message"
|
||||
echo " -v, --version show version information"
|
||||
echo " -c, --config <config file> alternate config file"
|
||||
echo " -s, --sources <sources file> use sources from file instead of cmd"
|
||||
echo
|
||||
|
||||
}
|
||||
|
||||
version()
|
||||
{
|
||||
|
||||
echo
|
||||
echo "sshbackup"
|
||||
echo
|
||||
echo -e "vesion: \033[1;37m$version\033[0m"
|
||||
echo "author: $author"
|
||||
echo
|
||||
|
||||
}
|
||||
|
||||
|
||||
# **** start of script ****
|
||||
|
||||
#initialize bashtrap
|
||||
trap bashtrap INT
|
||||
|
||||
# **** option handler ****
|
||||
for option in $options; do
|
||||
case "$option" in
|
||||
-h|--help)
|
||||
usage
|
||||
;;
|
||||
-v|--version)
|
||||
version
|
||||
;;
|
||||
-c|--config)
|
||||
config=1
|
||||
;;
|
||||
-s|--sources)
|
||||
sources=1
|
||||
;;
|
||||
*)
|
||||
if [ $config -eq 1 ]; then
|
||||
configfile=$option
|
||||
config=0
|
||||
elif [ $sources -eq 1 ]; then
|
||||
sourcefile=$option
|
||||
sources=0
|
||||
else
|
||||
if [ -z "${option//[0-9]/}" ]; then
|
||||
versions=$option
|
||||
else
|
||||
if [ -z $sourcepath ]; then
|
||||
sourcepath=$option
|
||||
else
|
||||
destinationpath=$option
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo "sourcefile: $sourcefile"
|
||||
echo "configfile: $configfile"
|
||||
echo "versions: $versions"
|
||||
echo "sourcepath: $sourcepath"
|
||||
echo "destinationpath: $destinationpath"
|
||||
|
||||
|
||||
|
||||
# **** end of script ****
|
||||
exit 0
|
Reference in New Issue