added key feature draft
This commit is contained in:
parent
7e5143bf51
commit
350d0facdf
|
@ -0,0 +1,59 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# key management funcion
|
||||||
|
|
||||||
|
interactive()
|
||||||
|
{
|
||||||
|
|
||||||
|
tty -s
|
||||||
|
return $?
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
keymgmt()
|
||||||
|
{
|
||||||
|
|
||||||
|
local username=$(id -un)
|
||||||
|
local userid=$(id -u)
|
||||||
|
|
||||||
|
#find out where running 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
|
||||||
|
|
||||||
|
if [ -z $1 ]; then
|
||||||
|
sshkeyfile="$home/.ssh/id_rsa"
|
||||||
|
else
|
||||||
|
sshkeyfile="$1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -r $sshkeyfile ]; then
|
||||||
|
#ssh key found
|
||||||
|
:
|
||||||
|
else
|
||||||
|
if ( interactive ); then
|
||||||
|
echo "no ssh key found"
|
||||||
|
echo -e "do you want to create a ssh key pair? [y/n] \c"
|
||||||
|
read choice
|
||||||
|
if [ -z $choice ]; then
|
||||||
|
echo "aborting mission. no ssh key found."
|
||||||
|
exit 1
|
||||||
|
elif [ $choice == "y" ] || [ $choice == "Y" ]; then
|
||||||
|
#creating ssh key pair
|
||||||
|
ssh-keygen
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "aborting mission. no ssh key found."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
keymgmt
|
||||||
|
|
||||||
|
#end of file
|
19
sshbackup
19
sshbackup
|
@ -7,7 +7,7 @@
|
||||||
# ************************************* #
|
# ************************************* #
|
||||||
|
|
||||||
# **** config section ****
|
# **** config section ****
|
||||||
version="0.3.1"
|
version="0.4.0"
|
||||||
author="david@socialnerds.org"
|
author="david@socialnerds.org"
|
||||||
|
|
||||||
configfile="$HOME/.sshbackup"
|
configfile="$HOME/.sshbackup"
|
||||||
|
@ -23,6 +23,7 @@ versions=999
|
||||||
config=0
|
config=0
|
||||||
sshkey=0
|
sshkey=0
|
||||||
list=0
|
list=0
|
||||||
|
bandwidth=0
|
||||||
options=$*
|
options=$*
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,6 +52,7 @@ usage()
|
||||||
echo " -l, --list <file> list of sources and destinations"
|
echo " -l, --list <file> list of sources and destinations"
|
||||||
echo " -c, --config <file> alternate config file [~/.sshbackup]"
|
echo " -c, --config <file> alternate config file [~/.sshbackup]"
|
||||||
echo " -s, --sshkey <file> alternate sshkey [~/.ssh/id_rsa]"
|
echo " -s, --sshkey <file> alternate sshkey [~/.ssh/id_rsa]"
|
||||||
|
echo " -b, --bandwidth <kbps> bandwidth limit in kbit per second"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -122,6 +124,9 @@ sshbackup()
|
||||||
cmdopt="$cmdopt --link-dest=$destpath/1"
|
cmdopt="$cmdopt --link-dest=$destpath/1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#bandwidth limit
|
||||||
|
if [
|
||||||
|
|
||||||
#run rsync
|
#run rsync
|
||||||
$localcmd $cmdopt -e "ssh -q -i $sshkeyfile" --rsync-path="$remotecmd" $sourcepath $destpath/0
|
$localcmd $cmdopt -e "ssh -q -i $sshkeyfile" --rsync-path="$remotecmd" $sourcepath $destpath/0
|
||||||
if [ $? -ne "0" ]; then
|
if [ $? -ne "0" ]; then
|
||||||
|
@ -170,6 +175,9 @@ for option in $options; do
|
||||||
-s|--sshkey)
|
-s|--sshkey)
|
||||||
sshkey=1
|
sshkey=1
|
||||||
;;
|
;;
|
||||||
|
-b|--bandwidth)
|
||||||
|
bandwidth=1
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
if [ $config -eq 1 ]; then
|
if [ $config -eq 1 ]; then
|
||||||
if [ -r "$option" ]; then
|
if [ -r "$option" ]; then
|
||||||
|
@ -187,6 +195,15 @@ for option in $options; do
|
||||||
echo "aborting mission. cannot read sshkeyfile. [$option]"
|
echo "aborting mission. cannot read sshkeyfile. [$option]"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
elif [ $bandwidth -eq 1 ];then
|
||||||
|
#TODO: better check if its a number (from 1 to gigabit)
|
||||||
|
if [ -z $option ]; then
|
||||||
|
limit=$option
|
||||||
|
bandwidth=0
|
||||||
|
else
|
||||||
|
echo "aborting mission. bandwidth limit not given. [-b $option]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
elif [ $list -eq 1 ]; then
|
elif [ $list -eq 1 ]; then
|
||||||
if [ -r $option ]; then
|
if [ -r $option ]; then
|
||||||
listfile=$option
|
listfile=$option
|
||||||
|
|
Reference in New Issue