david/sshbackup
david
/
sshbackup
Archived
1
0
Fork 0

done some work on the new option handler

This commit is contained in:
david 2013-04-25 22:58:49 +02:00
parent 7efc856aa8
commit 3f6bb94542
1 changed files with 64 additions and 20 deletions

View File

@ -7,7 +7,7 @@
# ************************************* #
# **** config section ****
version="0.3.0"
version="0.3"
author="david@socialnerds.org"
configfile="$HOME/.sshbackup"
@ -24,7 +24,7 @@ logfile="/var/log/sshbackup.log"
sshkeyfile="$HOME/.ssh/id_rsa"
config=0
sources=0
sshkey=0
options=$*
@ -49,7 +49,7 @@ usage()
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 " -s, --sshkey <sshkeyfile> use alternate sshkeyfile"
echo
}
@ -57,8 +57,6 @@ usage()
version()
{
echo
echo "sshbackup"
echo
echo -e "vesion: \033[1;37m$version\033[0m"
echo "author: $author"
@ -66,6 +64,28 @@ version()
}
preflight()
{
if [ -r $sshkeyfile ]; then
#echo "sshkeyfile found"
:
else
#am i being run by cron?
tty -s
if [ $? -eq 0 ]; then
echo "im running in interactive mode"
echo "you have no ssh key configured."
echo "do you want to create a new keypair? [y] "
else
echo "aborting mission. no sshkey found."
exit 1
fi
fi
}
# **** start of script ****
@ -92,24 +112,42 @@ for option in $options; do
-c|--config)
config=1
;;
-s|--sources)
sources=1
-s|--sshkey)
sshkey=1
;;
*)
if [ $config -eq 1 ]; then
configfile=$option
config=0
elif [ $sources -eq 1 ]; then
sourcefile=$option
sources=0
if [ -r $option ]; then
configfile=$option
config=0
else
echo "aborting mission. cannot read configfile. [$option]"
exit 1
fi
elif [ $sshkey -eq 1 ]; then
if [ -r $option ]; then
sshkeyfile=$option
sshkey=0
else
echo "aborting mission. cannot read sshkeyfile. [$option]"
exit 1
fi
else
if [ -z "${option//[0-9]/}" ]; then
versions=$option
if [[ $option =~ ^-.* ]]; then
echo "aborting mission. unknown option given. [$option]"
exit 1
#TODO: what if source or dest is a number?
elif [ -z "${option//[0-9]/}" ]; then
if [ -z $versions ]; then
versions=$option
fi
else
if [ -z $sourcepath ]; then
sourcepath=$option
else
destinationpath=$option
if [ -z $destinationpath ]; then
destinationpath=$option
fi
fi
fi
fi
@ -117,11 +155,17 @@ for option in $options; do
esac
done
echo "sourcefile: $sourcefile"
echo "configfile: $configfile"
echo "versions: $versions"
echo "sourcepath: $sourcepath"
echo "destinationpath: $destinationpath"
if [ -z $sourcepath ]; then
echo "aborting mission. no source path given."
exit 1
elif [ -z $destinationpath ]; then
destinationpath="."
fi
source $configfile
#running preflight checks
preflight