This commit is contained in:
Bob Mottram 2016-06-04 17:34:26 +01:00
parent 152360ab96
commit f24a136e77
1 changed files with 175 additions and 175 deletions

View File

@ -65,201 +65,201 @@ TITLE='Remote Backup'
RECIPROCAL="no"
function show_help {
echo ''
echo $"${PROJECT_NAME}-remote -u [username] -l [backup list filename] -m [min password length]"
echo ''
echo $'Creates an inventory of remote backup locations'
echo ''
echo ''
echo $' -h --help Show help'
echo $' -u --username User to create the backups.list file for'
echo $' -l --list Remote backup list (usually /home/$USER/backup.list)'
echo $' -m --min Minimum password length (characters)'
echo $' -r --reciprocal Whether to add reciprocal user accounts'
echo $' -t --title Title shown'
echo ''
exit 0
echo ''
echo $"${PROJECT_NAME}-remote -u [username] -l [backup list filename] -m [min password length]"
echo ''
echo $'Creates an inventory of remote backup locations'
echo ''
echo ''
echo $' -h --help Show help'
echo $' -u --username User to create the backups.list file for'
echo $' -l --list Remote backup list (usually /home/$USER/backup.list)'
echo $' -m --min Minimum password length (characters)'
echo $' -r --reciprocal Whether to add reciprocal user accounts'
echo $' -t --title Title shown'
echo ''
exit 0
}
# Get the commandline options
while [[ $# > 1 ]]
do
key="$1"
key="$1"
case $key in
-h|--help)
show_help
;;
# backup list filename
# typically /home/$USER/backup.list
-l|--list)
case $key in
-h|--help)
show_help
;;
# backup list filename
# typically /home/$USER/backup.list
-l|--list)
shift
FRIENDS_SERVERS_LIST="$1"
;;
# username within /home
-u|--user)
shift
MY_USERNAME="$1"
;;
# Minimum password length
-m|--min)
shift
MINIMUM_PASSWORD_LENGTH="$1"
;;
# Title shown
-t|--title)
shift
TITLE="$1"
;;
# reciprocal user accounts
-r|--reciprocal)
shift
RECIPROCAL="yes"
;;
*)
# unknown option
;;
esac
shift
FRIENDS_SERVERS_LIST="$1"
;;
# username within /home
-u|--user)
shift
MY_USERNAME="$1"
;;
# Minimum password length
-m|--min)
shift
MINIMUM_PASSWORD_LENGTH="$1"
;;
# Title shown
-t|--title)
shift
TITLE="$1"
;;
# reciprocal user accounts
-r|--reciprocal)
shift
RECIPROCAL="yes"
;;
*)
# unknown option
;;
esac
shift
done
function interactive_configuration_remote_backups {
if [ ! $MY_USERNAME ]; then
echo $'Please specify a username with the -u option'
exit 7356
fi
if [ ! $MY_USERNAME ]; then
echo $'Please specify a username with the -u option'
exit 7356
fi
if [ ! /home/$MY_USERNAME ]; then
echo $"The user /home/$MY_USERNAME does not exist on the system"
exit 3689
fi
if [ ! /home/$MY_USERNAME ]; then
echo $"The user /home/$MY_USERNAME does not exist on the system"
exit 3689
fi
if [ ! $FRIENDS_SERVERS_LIST ]; then
FRIENDS_SERVERS_LIST=/home/$MY_USERNAME/backup.list
fi
if [ ! $FRIENDS_SERVERS_LIST ]; then
FRIENDS_SERVERS_LIST=/home/$MY_USERNAME/backup.list
fi
# clear any existing list
if [ -f $FRIENDS_SERVERS_LIST ]; then
rm -f $FRIENDS_SERVERS_LIST
touch $FRIENDS_SERVERS_LIST
fi
# number of entries made
entering_remote_backups_ctr=1
# clear any existing list
if [ -f $FRIENDS_SERVERS_LIST ]; then
rm -f $FRIENDS_SERVERS_LIST
touch $FRIENDS_SERVERS_LIST
fi
# number of entries made
entering_remote_backups_ctr=1
entering_remote_backups_done="no"
remote_ssh_username=""
remote_ssh_domain=""
remote_ssh_port=""
remote_ssh_password=""
remote_ssh_reciprocal_username=""
remote_ssh_reciprocal_password=""
while [[ $entering_remote_backups_done == "no" ]]
do
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
if [[ $RECIPROCAL == "yes" ]]; then
dialog --backtitle "Freedombone Configuration" \
--title "$TITLE ${entering_remote_backups_ctr}" \
--form "\nPlease specify the SSH login details for the remote server\n\nThe reciprocal entries are optional, and can be used if you wish to set up a user account on this system for whoever runs the remote server to also use for backups" 20 50 8 \
"Username:" 1 1 "$remote_ssh_username" 1 23 16 15 \
"Domain:" 2 1 "$remote_ssh_domain" 2 23 16 15 \
"SSH port:" 3 1 "2222" 3 23 5 4 \
"Password:" 4 1 "$remote_ssh_password" 4 23 20 100 \
"Reciprocal Username:" 5 1 "$remote_ssh_reciprocal_username" 5 23 20 100 \
"Reciprocal Password:" 6 1 "$remote_ssh_reciprocal_password" 6 23 20 100 \
2> $data
else
dialog --backtitle "Freedombone Configuration" \
--title "$TITLE ${entering_remote_backups_ctr}" \
--form "\nPlease specify the SSH login details for the remote server" 15 50 4 \
"Username:" 1 1 "$remote_ssh_username" 1 23 16 15 \
"Domain:" 2 1 "$remote_ssh_domain" 2 23 16 15 \
"SSH port:" 3 1 "2222" 3 23 5 4 \
"Password:" 4 1 "$remote_ssh_password" 4 23 20 100 \
2> $data
fi
sel=$?
case $sel in
1) entering_remote_backups_done="yes";;
255) entering_remote_backups_done="yes";;
esac
remote_ssh_username=$(cat $data | sed -n 1p)
remote_ssh_domain=$(cat $data | sed -n 2p)
remote_ssh_port=$(cat $data | sed -n 3p)
remote_ssh_password=$(cat $data | sed -n 4p)
remote_ssh_reciprocal_username=$(cat $data | sed -n 5p)
remote_ssh_reciprocal_password=$(cat $data | sed -n 6p)
if [[ $remote_ssh_username != "" && \
$remote_ssh_domain != "" && \
$remote_ssh_port != "" && \
$remote_ssh_password != "" ]]; then
entering_remote_backups_done="no"
remote_ssh_username=""
remote_ssh_domain=""
remote_ssh_port=""
remote_ssh_password=""
remote_ssh_reciprocal_username=""
remote_ssh_reciprocal_password=""
while [[ $entering_remote_backups_done == "no" ]]
do
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
if [[ $RECIPROCAL == "yes" ]]; then
dialog --backtitle "Freedombone Configuration" \
--title "$TITLE ${entering_remote_backups_ctr}" \
--form "\nPlease specify the SSH login details for the remote server\n\nThe reciprocal entries are optional, and can be used if you wish to set up a user account on this system for whoever runs the remote server to also use for backups" 20 50 8 \
"Username:" 1 1 "$remote_ssh_username" 1 23 16 15 \
"Domain:" 2 1 "$remote_ssh_domain" 2 23 16 15 \
"SSH port:" 3 1 "2222" 3 23 5 4 \
"Password:" 4 1 "$remote_ssh_password" 4 23 20 100 \
"Reciprocal Username:" 5 1 "$remote_ssh_reciprocal_username" 5 23 20 100 \
"Reciprocal Password:" 6 1 "$remote_ssh_reciprocal_password" 6 23 20 100 \
2> $data
else
dialog --backtitle "Freedombone Configuration" \
--title "$TITLE ${entering_remote_backups_ctr}" \
--form "\nPlease specify the SSH login details for the remote server" 15 50 4 \
"Username:" 1 1 "$remote_ssh_username" 1 23 16 15 \
"Domain:" 2 1 "$remote_ssh_domain" 2 23 16 15 \
"SSH port:" 3 1 "2222" 3 23 5 4 \
"Password:" 4 1 "$remote_ssh_password" 4 23 20 100 \
2> $data
fi
sel=$?
case $sel in
1) entering_remote_backups_done="yes";;
255) entering_remote_backups_done="yes";;
esac
remote_ssh_username=$(cat $data | sed -n 1p)
remote_ssh_domain=$(cat $data | sed -n 2p)
remote_ssh_port=$(cat $data | sed -n 3p)
remote_ssh_password=$(cat $data | sed -n 4p)
remote_ssh_reciprocal_username=$(cat $data | sed -n 5p)
remote_ssh_reciprocal_password=$(cat $data | sed -n 6p)
if [[ $remote_ssh_username != "" && \
$remote_ssh_domain != "" && \
$remote_ssh_port != "" && \
$remote_ssh_password != "" ]]; then
if [ ${#remote_ssh_password} -lt $MINIMUM_PASSWORD_LENGTH ]; then
dialog --title "Password quality check" --msgbox "The password given was too short. It must be at least $MINIMUM_PASSWORD_LENGTH characters" 6 40
else
if [ ${#remote_ssh_password} -lt $MINIMUM_PASSWORD_LENGTH ]; then
dialog --title "Password quality check" --msgbox "The password given was too short. It must be at least $MINIMUM_PASSWORD_LENGTH characters" 6 40
else
if [[ $RECIPROCAL == "yes" ]]; then
if [[ $remote_ssh_reciprocal_username != "" && \
$remote_ssh_reciprocal_password != "" ]]; then
if [ ${#remote_ssh_reciprocal_password} -lt $MINIMUM_PASSWORD_LENGTH ]; then
dialog --title "Password quality check" --msgbox "The reciprocal password given was too short. It must be at least $MINIMUM_PASSWORD_LENGTH characters" 6 40
else
echo ${remote_ssh_reciprocal_username}:${remote_ssh_reciprocal_password}::::/home/${remote_ssh_reciprocal_username}:bash | newusers
echo "$remote_ssh_username@$remote_ssh_domain $remote_ssh_port /home/$remote_ssh_username $remote_ssh_password" >> $FRIENDS_SERVERS_LIST
remote_ssh_username=""
remote_ssh_domain=""
remote_ssh_port=""
remote_ssh_password=""
remote_ssh_reciprocal_username=""
remote_ssh_reciprocal_password=""
entering_remote_backups_ctr=$((entering_remote_backups_ctr + 1))
fi
else
echo "$remote_ssh_username@$remote_ssh_domain $remote_ssh_port /home/$remote_ssh_username $remote_ssh_password" >> $FRIENDS_SERVERS_LIST
remote_ssh_username=""
remote_ssh_domain=""
remote_ssh_port=""
remote_ssh_password=""
remote_ssh_reciprocal_username=""
remote_ssh_reciprocal_password=""
entering_remote_backups_ctr=$((entering_remote_backups_ctr + 1))
fi
else
echo "$remote_ssh_username@$remote_ssh_domain $remote_ssh_port /home/$remote_ssh_username $remote_ssh_password" >> $FRIENDS_SERVERS_LIST
remote_ssh_username=""
remote_ssh_domain=""
remote_ssh_port=""
remote_ssh_password=""
entering_remote_backups_ctr=$((entering_remote_backups_ctr + 1))
fi
if [[ $RECIPROCAL == "yes" ]]; then
if [[ $remote_ssh_reciprocal_username != "" && \
$remote_ssh_reciprocal_password != "" ]]; then
if [ ${#remote_ssh_reciprocal_password} -lt $MINIMUM_PASSWORD_LENGTH ]; then
dialog --title "Password quality check" --msgbox "The reciprocal password given was too short. It must be at least $MINIMUM_PASSWORD_LENGTH characters" 6 40
else
echo ${remote_ssh_reciprocal_username}:${remote_ssh_reciprocal_password}::::/home/${remote_ssh_reciprocal_username}:bash | newusers
echo "$remote_ssh_username@$remote_ssh_domain $remote_ssh_port /home/$remote_ssh_username $remote_ssh_password" >> $FRIENDS_SERVERS_LIST
remote_ssh_username=""
remote_ssh_domain=""
remote_ssh_port=""
remote_ssh_password=""
remote_ssh_reciprocal_username=""
remote_ssh_reciprocal_password=""
entering_remote_backups_ctr=$((entering_remote_backups_ctr + 1))
fi
else
echo "$remote_ssh_username@$remote_ssh_domain $remote_ssh_port /home/$remote_ssh_username $remote_ssh_password" >> $FRIENDS_SERVERS_LIST
remote_ssh_username=""
remote_ssh_domain=""
remote_ssh_port=""
remote_ssh_password=""
remote_ssh_reciprocal_username=""
remote_ssh_reciprocal_password=""
entering_remote_backups_ctr=$((entering_remote_backups_ctr + 1))
fi
else
echo "$remote_ssh_username@$remote_ssh_domain $remote_ssh_port /home/$remote_ssh_username $remote_ssh_password" >> $FRIENDS_SERVERS_LIST
remote_ssh_username=""
remote_ssh_domain=""
remote_ssh_port=""
remote_ssh_password=""
entering_remote_backups_ctr=$((entering_remote_backups_ctr + 1))
fi
fi
else
entering_remote_backups_done="yes"
fi
done
if [ -f $FRIENDS_SERVERS_LIST ]; then
chown $MY_USERNAME:$MY_USERNAME $FRIENDS_SERVERS_LIST
fi
fi
else
entering_remote_backups_done="yes"
fi
done
if [ -f $FRIENDS_SERVERS_LIST ]; then
chown $MY_USERNAME:$MY_USERNAME $FRIENDS_SERVERS_LIST
fi
}
function show_result {
clear
if (( $entering_remote_backups_ctr < 2 )); then
echo $'No remote backup locations were specified'
exit 0
fi
if [ ! -f $FRIENDS_SERVERS_LIST ]; then
echo $"No remote backups list found: $FRIENDS_SERVERS_LIST"
exit 7358
fi
echo ''
echo $"Remote backups list: $FRIENDS_SERVERS_LIST"
echo ''
echo $'Contents:'
echo ''
cat $FRIENDS_SERVERS_LIST
echo ''
clear
if (( $entering_remote_backups_ctr < 2 )); then
echo $'No remote backup locations were specified'
exit 0
fi
if [ ! -f $FRIENDS_SERVERS_LIST ]; then
echo $"No remote backups list found: $FRIENDS_SERVERS_LIST"
exit 7358
fi
echo ''
echo $"Remote backups list: $FRIENDS_SERVERS_LIST"
echo ''
echo $'Contents:'
echo ''
cat $FRIENDS_SERVERS_LIST
echo ''
}
if [ ! $FRIENDS_SERVERS_LIST ]; then