Bläddra i källkod

Automatic detection of the usb drive

Bob Mottram 8 år sedan
förälder
incheckning
05cb1404da
3 ändrade filer med 53 tillägg och 67 borttagningar
  1. 15
    66
      src/freedombone-controlpanel
  2. 6
    1
      src/freedombone-format
  3. 32
    0
      src/freedombone-utils-setup

+ 15
- 66
src/freedombone-controlpanel Visa fil

@@ -857,7 +857,10 @@ function backup_data {
857 857
     dialog --title $"Backup data to USB" \
858 858
            --msgbox $"Plug in a LUKS encrypted USB drive" 6 40
859 859
     clear
860
-    echo ' '
860
+    detect_usb_drive
861
+    echo ''
862
+    echo $"Detected USB drive $USB_DRIVE"
863
+    echo ''
861 864
     echo $'Enter the passphrase for your LUKS encrypted backup drive:'
862 865
     ${PROJECT_NAME}-backup-local
863 866
     any_key
@@ -873,22 +876,7 @@ function restore_data_from_storage {
873 876
         restore_command="${PROJECT_NAME}-restore-remote $remote_domain_name configuration;;"
874 877
     else
875 878
         remote_domain_name="$1"
876
-        if [ ! -b $USB_DRIVE ]; then
877
-            if [ -b /dev/sdb1 ]; then
878
-                USB_DRIVE=/dev/sdb1
879
-            fi
880
-            if [ -b /dev/sdc1 ]; then
881
-                USB_DRIVE=/dev/sdc1
882
-            fi
883
-            if [ -b /dev/sdd1 ]; then
884
-                USB_DRIVE=/dev/sdd1
885
-            fi
886
-            if [ -b /dev/sde1 ]; then
887
-                USB_DRIVE=/dev/sde1
888
-            fi
889
-            write_config_param USB_DRIVE "$USB_DRIVE"
890
-        fi
891
-
879
+        detect_usb_drive
892 880
         restore_command="${PROJECT_NAME}-restore-local $USB_DRIVE"
893 881
     fi
894 882
 
@@ -1122,34 +1110,13 @@ function reset_tripwire {
1122 1110
 }
1123 1111
 
1124 1112
 function format_drive {
1125
-    drive=
1113
+    detect_usb_drive
1126 1114
     data=$(tempfile 2>/dev/null)
1127 1115
     trap "rm -f $data" 0 1 2 5 15
1128
-    dialog --backtitle $"Freedombone Control Panel" \
1129
-           --title $"Format a USB drive (LUKS encrypted)" \
1130
-           --radiolist $"Choose a drive:" 12 70 5 \
1131
-           1 $"sda (Beaglebone Black)" off \
1132
-           2 $"sdb" off \
1133
-           3 $"sdc" off \
1134
-           4 $"sdd" off \
1135
-           5 $"Back to Backup and Restore menu" on 2> $data
1136
-    sel=$?
1137
-    case $sel in
1138
-        1) return;;
1139
-        255) return;;
1140
-    esac
1141
-    case $(cat $data) in
1142
-        1) drive='sda';;
1143
-        2) drive='sdb';;
1144
-        3) drive='sdc';;
1145
-        4) drive='sdd';;
1146
-        5) return;;
1147
-    esac
1148
-
1149
-    dialog --title $"Format USB drive" \
1116
+    dialog --title $"Format USB drive $USB_DRIVE" \
1150 1117
            --backtitle $"Freedombone Control Panel" \
1151 1118
            --defaultno \
1152
-           --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
1119
+           --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
1153 1120
     sel=$?
1154 1121
     case $sel in
1155 1122
         1) return;;
@@ -1157,36 +1124,18 @@ function format_drive {
1157 1124
     esac
1158 1125
 
1159 1126
     clear
1160
-    ${PROJECT_NAME}-format $drive
1127
+    echo ''
1128
+    echo $"Formatting drive $USB_DRIVE. ALL CONTENTS WILL BE LOST."
1129
+    echo ''
1130
+    ${PROJECT_NAME}-format $USB_DRIVE
1161 1131
     any_key
1162 1132
 }
1163 1133
 
1164 1134
 function remove_backups {
1165
-    drive=
1135
+    detect_usb_drive
1166 1136
     data=$(tempfile 2>/dev/null)
1167 1137
     trap "rm -f $data" 0 1 2 5 15
1168
-    dialog --backtitle $"Freedombone Control Panel" \
1169
-           --title $"Remove backups from a USB drive" \
1170
-           --radiolist $"Choose a drive:" 12 70 5 \
1171
-           1 $"sda (Beaglebone Black)" off \
1172
-           2 $"sdb" off \
1173
-           3 $"sdc" off \
1174
-           4 $"sdd" off \
1175
-           5 $"Back to Backup and Restore menu" on 2> $data
1176
-    sel=$?
1177
-    case $sel in
1178
-        1) return;;
1179
-        255) return;;
1180
-    esac
1181
-    case $(cat $data) in
1182
-        1) drive='sda';;
1183
-        2) drive='sdb';;
1184
-        3) drive='sdc';;
1185
-        4) drive='sdd';;
1186
-        5) return;;
1187
-    esac
1188
-
1189
-    dialog --title $"Remove backups from a USB drive" \
1138
+    dialog --title $"Remove backups from a USB drive $USB_DRIVE" \
1190 1139
            --backtitle $"Freedombone Control Panel" \
1191 1140
            --defaultno \
1192 1141
            --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 {
1197 1146
     esac
1198 1147
 
1199 1148
     clear
1200
-    ${PROJECT_NAME}-backup-local $drive remove
1149
+    ${PROJECT_NAME}-backup-local $USB_DRIVE remove
1201 1150
     any_key
1202 1151
 }
1203 1152
 

+ 6
- 1
src/freedombone-format Visa fil

@@ -38,7 +38,12 @@ if [ ! $1 ]; then
38 38
    exit 1
39 39
 fi
40 40
 
41
-USB_DRIVE=/dev/${1}1
41
+if [[ "$1" == "/dev/"* ]]; then
42
+    USB_DRIVE=$1
43
+else
44
+    USB_DRIVE=/dev/${1}1
45
+fi
46
+
42 47
 LABEL="${PROJECT_NAME}"
43 48
 
44 49
 echo $'Partitioning drive'

+ 32
- 0
src/freedombone-utils-setup Visa fil

@@ -81,6 +81,38 @@ CHECK_MESSAGE="Check your internet connection, /etc/network/interfaces and /etc/
81 81
 # Default diffie-hellman key length in bits
82 82
 DH_KEYLENGTH=2048
83 83
 
84
+function detect_usb_drive {
85
+    # sets to the highest available drive letter
86
+    # which is likely to be the last drive connected
87
+    read_config_param USB_DRIVE
88
+    partition_number='1'
89
+    if [[ "$1" == "nopath" ]]; then
90
+        partition_number=''
91
+    fi
92
+    if [ -b /dev/sdb${partition_number} ]; then
93
+        USB_DRIVE=/dev/sdb${partition_number}
94
+    fi
95
+    if [ -b /dev/sdc${partition_number} ]; then
96
+        USB_DRIVE=/dev/sdc${partition_number}
97
+    fi
98
+    if [ -b /dev/sdd${partition_number} ]; then
99
+        USB_DRIVE=/dev/sdd${partition_number}
100
+    fi
101
+    if [ -b /dev/sde${partition_number} ]; then
102
+        USB_DRIVE=/dev/sde${partition_number}
103
+    fi
104
+    if [ -b /dev/sdf${partition_number} ]; then
105
+        USB_DRIVE=/dev/sdf${partition_number}
106
+    fi
107
+    if [ -b /dev/sdg${partition_number} ]; then
108
+        USB_DRIVE=/dev/sdg${partition_number}
109
+    fi
110
+    if [ -b /dev/sdh${partition_number} ]; then
111
+        USB_DRIVE=/dev/sdh${partition_number}
112
+    fi
113
+    write_config_param USB_DRIVE "$USB_DRIVE"
114
+}
115
+
84 116
 function running_as_root {
85 117
     if [[ $EUID != 0 ]] ; then
86 118
         echo "0"