Automatic detection of the usb drive

This commit is contained in:
Bob Mottram 2016-10-25 10:40:49 +01:00
parent 13f22d1960
commit 05cb1404da
3 changed files with 53 additions and 67 deletions

View File

@ -857,7 +857,10 @@ function backup_data {
dialog --title $"Backup data to USB" \ dialog --title $"Backup data to USB" \
--msgbox $"Plug in a LUKS encrypted USB drive" 6 40 --msgbox $"Plug in a LUKS encrypted USB drive" 6 40
clear clear
echo ' ' detect_usb_drive
echo ''
echo $"Detected USB drive $USB_DRIVE"
echo ''
echo $'Enter the passphrase for your LUKS encrypted backup drive:' echo $'Enter the passphrase for your LUKS encrypted backup drive:'
${PROJECT_NAME}-backup-local ${PROJECT_NAME}-backup-local
any_key any_key
@ -873,22 +876,7 @@ function restore_data_from_storage {
restore_command="${PROJECT_NAME}-restore-remote $remote_domain_name configuration;;" restore_command="${PROJECT_NAME}-restore-remote $remote_domain_name configuration;;"
else else
remote_domain_name="$1" remote_domain_name="$1"
if [ ! -b $USB_DRIVE ]; then detect_usb_drive
if [ -b /dev/sdb1 ]; then
USB_DRIVE=/dev/sdb1
fi
if [ -b /dev/sdc1 ]; then
USB_DRIVE=/dev/sdc1
fi
if [ -b /dev/sdd1 ]; then
USB_DRIVE=/dev/sdd1
fi
if [ -b /dev/sde1 ]; then
USB_DRIVE=/dev/sde1
fi
write_config_param USB_DRIVE "$USB_DRIVE"
fi
restore_command="${PROJECT_NAME}-restore-local $USB_DRIVE" restore_command="${PROJECT_NAME}-restore-local $USB_DRIVE"
fi fi
@ -1122,34 +1110,13 @@ function reset_tripwire {
} }
function format_drive { function format_drive {
drive= detect_usb_drive
data=$(tempfile 2>/dev/null) data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15 trap "rm -f $data" 0 1 2 5 15
dialog --backtitle $"Freedombone Control Panel" \ dialog --title $"Format USB drive $USB_DRIVE" \
--title $"Format a USB drive (LUKS encrypted)" \
--radiolist $"Choose a drive:" 12 70 5 \
1 $"sda (Beaglebone Black)" off \
2 $"sdb" off \
3 $"sdc" off \
4 $"sdd" off \
5 $"Back to Backup and Restore menu" on 2> $data
sel=$?
case $sel in
1) return;;
255) return;;
esac
case $(cat $data) in
1) drive='sda';;
2) drive='sdb';;
3) drive='sdc';;
4) drive='sdd';;
5) return;;
esac
dialog --title $"Format USB drive" \
--backtitle $"Freedombone Control Panel" \ --backtitle $"Freedombone Control Panel" \
--defaultno \ --defaultno \
--yesno $"\nPlease confirm that you wish to format drive\n\n ${drive}\n\nAll current data on the drive will be lost, and you will be prompted to give a password used to encrypt the drive.\n\nDANGER: If you screw up here and format the wrong drive it's your own fault!" 16 60 --yesno $"\nPlease confirm that you wish to format drive\n\n ${USB_DRIVE}\n\nAll current data on the drive will be lost, and you will be prompted to give a password used to encrypt the drive.\n\nDANGER: If you screw up here and format the wrong drive it's your own fault!" 16 60
sel=$? sel=$?
case $sel in case $sel in
1) return;; 1) return;;
@ -1157,36 +1124,18 @@ function format_drive {
esac esac
clear clear
${PROJECT_NAME}-format $drive echo ''
echo $"Formatting drive $USB_DRIVE. ALL CONTENTS WILL BE LOST."
echo ''
${PROJECT_NAME}-format $USB_DRIVE
any_key any_key
} }
function remove_backups { function remove_backups {
drive= detect_usb_drive
data=$(tempfile 2>/dev/null) data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15 trap "rm -f $data" 0 1 2 5 15
dialog --backtitle $"Freedombone Control Panel" \ dialog --title $"Remove backups from a USB drive $USB_DRIVE" \
--title $"Remove backups from a USB drive" \
--radiolist $"Choose a drive:" 12 70 5 \
1 $"sda (Beaglebone Black)" off \
2 $"sdb" off \
3 $"sdc" off \
4 $"sdd" off \
5 $"Back to Backup and Restore menu" on 2> $data
sel=$?
case $sel in
1) return;;
255) return;;
esac
case $(cat $data) in
1) drive='sda';;
2) drive='sdb';;
3) drive='sdc';;
4) drive='sdd';;
5) return;;
esac
dialog --title $"Remove backups from a USB drive" \
--backtitle $"Freedombone Control Panel" \ --backtitle $"Freedombone Control Panel" \
--defaultno \ --defaultno \
--yesno $"\nPlease confirm that you wish to remove backups from this drive\n\n ${drive}\n\nYou will not be able to recover them afterwards." 12 60 --yesno $"\nPlease confirm that you wish to remove backups from this drive\n\n ${drive}\n\nYou will not be able to recover them afterwards." 12 60
@ -1197,7 +1146,7 @@ function remove_backups {
esac esac
clear clear
${PROJECT_NAME}-backup-local $drive remove ${PROJECT_NAME}-backup-local $USB_DRIVE remove
any_key any_key
} }

View File

@ -38,7 +38,12 @@ if [ ! $1 ]; then
exit 1 exit 1
fi fi
USB_DRIVE=/dev/${1}1 if [[ "$1" == "/dev/"* ]]; then
USB_DRIVE=$1
else
USB_DRIVE=/dev/${1}1
fi
LABEL="${PROJECT_NAME}" LABEL="${PROJECT_NAME}"
echo $'Partitioning drive' echo $'Partitioning drive'

View File

@ -81,6 +81,38 @@ CHECK_MESSAGE="Check your internet connection, /etc/network/interfaces and /etc/
# Default diffie-hellman key length in bits # Default diffie-hellman key length in bits
DH_KEYLENGTH=2048 DH_KEYLENGTH=2048
function detect_usb_drive {
# sets to the highest available drive letter
# which is likely to be the last drive connected
read_config_param USB_DRIVE
partition_number='1'
if [[ "$1" == "nopath" ]]; then
partition_number=''
fi
if [ -b /dev/sdb${partition_number} ]; then
USB_DRIVE=/dev/sdb${partition_number}
fi
if [ -b /dev/sdc${partition_number} ]; then
USB_DRIVE=/dev/sdc${partition_number}
fi
if [ -b /dev/sdd${partition_number} ]; then
USB_DRIVE=/dev/sdd${partition_number}
fi
if [ -b /dev/sde${partition_number} ]; then
USB_DRIVE=/dev/sde${partition_number}
fi
if [ -b /dev/sdf${partition_number} ]; then
USB_DRIVE=/dev/sdf${partition_number}
fi
if [ -b /dev/sdg${partition_number} ]; then
USB_DRIVE=/dev/sdg${partition_number}
fi
if [ -b /dev/sdh${partition_number} ]; then
USB_DRIVE=/dev/sdh${partition_number}
fi
write_config_param USB_DRIVE "$USB_DRIVE"
}
function running_as_root { function running_as_root {
if [[ $EUID != 0 ]] ; then if [[ $EUID != 0 ]] ; then
echo "0" echo "0"