diff --git a/src/freedombone-controlpanel b/src/freedombone-controlpanel index 4c5f0331..7fed3188 100755 --- a/src/freedombone-controlpanel +++ b/src/freedombone-controlpanel @@ -857,7 +857,10 @@ function backup_data { dialog --title $"Backup data to USB" \ --msgbox $"Plug in a LUKS encrypted USB drive" 6 40 clear - echo ' ' + detect_usb_drive + echo '' + echo $"Detected USB drive $USB_DRIVE" + echo '' echo $'Enter the passphrase for your LUKS encrypted backup drive:' ${PROJECT_NAME}-backup-local any_key @@ -873,22 +876,7 @@ function restore_data_from_storage { restore_command="${PROJECT_NAME}-restore-remote $remote_domain_name configuration;;" else remote_domain_name="$1" - if [ ! -b $USB_DRIVE ]; then - 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 - + detect_usb_drive restore_command="${PROJECT_NAME}-restore-local $USB_DRIVE" fi @@ -1122,34 +1110,13 @@ function reset_tripwire { } function format_drive { - drive= + detect_usb_drive data=$(tempfile 2>/dev/null) trap "rm -f $data" 0 1 2 5 15 - dialog --backtitle $"Freedombone Control Panel" \ - --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" \ + dialog --title $"Format USB drive $USB_DRIVE" \ --backtitle $"Freedombone Control Panel" \ --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=$? case $sel in 1) return;; @@ -1157,36 +1124,18 @@ function format_drive { esac clear - ${PROJECT_NAME}-format $drive + echo '' + echo $"Formatting drive $USB_DRIVE. ALL CONTENTS WILL BE LOST." + echo '' + ${PROJECT_NAME}-format $USB_DRIVE any_key } function remove_backups { - drive= + detect_usb_drive data=$(tempfile 2>/dev/null) trap "rm -f $data" 0 1 2 5 15 - dialog --backtitle $"Freedombone Control Panel" \ - --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" \ + dialog --title $"Remove backups from a USB drive $USB_DRIVE" \ --backtitle $"Freedombone Control Panel" \ --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 @@ -1197,7 +1146,7 @@ function remove_backups { esac clear - ${PROJECT_NAME}-backup-local $drive remove + ${PROJECT_NAME}-backup-local $USB_DRIVE remove any_key } diff --git a/src/freedombone-format b/src/freedombone-format index 620b02c0..96ea836a 100755 --- a/src/freedombone-format +++ b/src/freedombone-format @@ -38,7 +38,12 @@ if [ ! $1 ]; then exit 1 fi -USB_DRIVE=/dev/${1}1 +if [[ "$1" == "/dev/"* ]]; then + USB_DRIVE=$1 +else + USB_DRIVE=/dev/${1}1 +fi + LABEL="${PROJECT_NAME}" echo $'Partitioning drive' diff --git a/src/freedombone-utils-setup b/src/freedombone-utils-setup index f22660e0..e40c8c49 100755 --- a/src/freedombone-utils-setup +++ b/src/freedombone-utils-setup @@ -81,6 +81,38 @@ CHECK_MESSAGE="Check your internet connection, /etc/network/interfaces and /etc/ # Default diffie-hellman key length in bits 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 { if [[ $EUID != 0 ]] ; then echo "0"