Quellcode durchsuchen

Automatic detection of the usb drive

Bob Mottram vor 8 Jahren
Ursprung
Commit
05cb1404da
3 geänderte Dateien mit 53 neuen und 67 gelöschten Zeilen
  1. 15
    66
      src/freedombone-controlpanel
  2. 6
    1
      src/freedombone-format
  3. 32
    0
      src/freedombone-utils-setup

+ 15
- 66
src/freedombone-controlpanel Datei anzeigen

857
     dialog --title $"Backup data to USB" \
857
     dialog --title $"Backup data to USB" \
858
            --msgbox $"Plug in a LUKS encrypted USB drive" 6 40
858
            --msgbox $"Plug in a LUKS encrypted USB drive" 6 40
859
     clear
859
     clear
860
-    echo ' '
860
+    detect_usb_drive
861
+    echo ''
862
+    echo $"Detected USB drive $USB_DRIVE"
863
+    echo ''
861
     echo $'Enter the passphrase for your LUKS encrypted backup drive:'
864
     echo $'Enter the passphrase for your LUKS encrypted backup drive:'
862
     ${PROJECT_NAME}-backup-local
865
     ${PROJECT_NAME}-backup-local
863
     any_key
866
     any_key
873
         restore_command="${PROJECT_NAME}-restore-remote $remote_domain_name configuration;;"
876
         restore_command="${PROJECT_NAME}-restore-remote $remote_domain_name configuration;;"
874
     else
877
     else
875
         remote_domain_name="$1"
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
         restore_command="${PROJECT_NAME}-restore-local $USB_DRIVE"
880
         restore_command="${PROJECT_NAME}-restore-local $USB_DRIVE"
893
     fi
881
     fi
894
 
882
 
1122
 }
1110
 }
1123
 
1111
 
1124
 function format_drive {
1112
 function format_drive {
1125
-    drive=
1113
+    detect_usb_drive
1126
     data=$(tempfile 2>/dev/null)
1114
     data=$(tempfile 2>/dev/null)
1127
     trap "rm -f $data" 0 1 2 5 15
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
            --backtitle $"Freedombone Control Panel" \
1117
            --backtitle $"Freedombone Control Panel" \
1151
            --defaultno \
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
     sel=$?
1120
     sel=$?
1154
     case $sel in
1121
     case $sel in
1155
         1) return;;
1122
         1) return;;
1157
     esac
1124
     esac
1158
 
1125
 
1159
     clear
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
     any_key
1131
     any_key
1162
 }
1132
 }
1163
 
1133
 
1164
 function remove_backups {
1134
 function remove_backups {
1165
-    drive=
1135
+    detect_usb_drive
1166
     data=$(tempfile 2>/dev/null)
1136
     data=$(tempfile 2>/dev/null)
1167
     trap "rm -f $data" 0 1 2 5 15
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
            --backtitle $"Freedombone Control Panel" \
1139
            --backtitle $"Freedombone Control Panel" \
1191
            --defaultno \
1140
            --defaultno \
1192
            --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
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
     esac
1146
     esac
1198
 
1147
 
1199
     clear
1148
     clear
1200
-    ${PROJECT_NAME}-backup-local $drive remove
1149
+    ${PROJECT_NAME}-backup-local $USB_DRIVE remove
1201
     any_key
1150
     any_key
1202
 }
1151
 }
1203
 
1152
 

+ 6
- 1
src/freedombone-format Datei anzeigen

38
    exit 1
38
    exit 1
39
 fi
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
 LABEL="${PROJECT_NAME}"
47
 LABEL="${PROJECT_NAME}"
43
 
48
 
44
 echo $'Partitioning drive'
49
 echo $'Partitioning drive'

+ 32
- 0
src/freedombone-utils-setup Datei anzeigen

81
 # Default diffie-hellman key length in bits
81
 # Default diffie-hellman key length in bits
82
 DH_KEYLENGTH=2048
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
 function running_as_root {
116
 function running_as_root {
85
     if [[ $EUID != 0 ]] ; then
117
     if [[ $EUID != 0 ]] ; then
86
         echo "0"
118
         echo "0"