Skip to content

Commit e924a8a

Browse files
committed
oem-factory-reset : Prompt user for any connected block device, give storage size and loop until none is connected to exit loop.
Warn user if connected usb block device is less then 128mb, since creating LUKS container of less then 8mb might cause issues. Signed-off-by: Thierry Laurion <insurgo@riseup.net>
1 parent 23c967f commit e924a8a

File tree

1 file changed

+50
-13
lines changed

1 file changed

+50
-13
lines changed

initrd/bin/oem-factory-reset

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,6 @@ prompt_insert_to_be_wiped_thumb_drive() {
326326
die "Error displaying warning about having only desired to be wiped thumb drive inserted"
327327
}
328328

329-
#list blkid devices (removing partition numbers)
330-
list_blkid_devices() {
331-
TRACE "Under oem-factory-reset:list_blkid_devices"
332-
blkid | cut -d: -f1 | sed 's/[0-9]$//'
333-
}
334-
335329
#export master key and subkeys to thumbdrive's private LUKS contained partition
336330
export_master_key_subkeys_and_revocation_key_to_private_LUKS_container() {
337331
TRACE "Under oem-factory-reset:export_master_key_subkeys_and_revocation_key_to_private_LUKS_container"
@@ -422,16 +416,59 @@ export_public_key_to_thumbdrive_public_partition() {
422416
wipe_thumb_drive_and_copy_gpg_key_material() {
423417
TRACE "Under oem-factory-reset:wipe_thumb_drive_and_copy_gpg_key_material"
424418
prompt_disconnect_external_USB_storage_device
425-
actual_devices=$(list_blkid_devices)
426419
#enable usb storage
427420
enable_usb
428421
enable_usb_storage
429-
prompt_insert_to_be_wiped_thumb_drive
430-
new_devices=$(list_blkid_devices)
431-
thumb_drive=$(echo "$new_devices" | grep -v "$actual_devices" | uniq)
432-
if [ -z "$thumb_drive" ]; then
433-
whiptail_error_die "No new thumb drive detected! Aborting."
434-
fi
422+
423+
#loop until user chooses a disk
424+
thumb_drive=""
425+
while [ -z "$thumb_drive" ]; do
426+
prompt_insert_to_be_wiped_thumb_drive
427+
#list usb storage devices
428+
list_usb_storage disks >/tmp/usb_disk_list
429+
if [ $(cat /tmp/usb_disk_list | wc -l) -gt 0 ]; then
430+
file_selector "/tmp/usb_disk_list" "Select USB device to partition"
431+
if [ "$FILE" == "" ]; then
432+
#No USB storage device selected
433+
warn "No USB storage device selected!"
434+
else
435+
# Obtain size of thumb drive to be wiped with fdisk
436+
disk_size_bytes="$(blockdev --getsize64 "$FILE")"
437+
#Convert disk size to GB
438+
thumb_drive_size_mb=$((disk_size_bytes / 1024 / 1024))
439+
thumb_drive_size_gb=$((thumb_drive_size_mb / 1024 ))
440+
441+
#if thumb_drive_size_gb is 0, then disk size is less than 1GB
442+
thumb_drive_size_message=""
443+
if [ "$thumb_drive_size_gb" -eq 0 ]; then
444+
thumb_drive_size_message="$thumb_drive_size_mb MB"
445+
if [ "$thumb_drive_size_mb" -lt 128 ]; then
446+
warn "Thumb drive size is less than 128MB!"
447+
warn "LUKS container needs to be at least 8mb!"
448+
warn "If the next operation fails, try with a bigger thumb drive"
449+
fi
450+
else
451+
thumb_drive_size_message="$thumb_drive_size_gb GB"
452+
fi
453+
454+
# confirm with user size of thumb drive to be wiped
455+
whiptail --title "Confirm thumb drive to be wiped" --yesno "Are you sure you want to wipe the following thumb drive?\n\n$FILE\n\nSize: $thumb_drive_size_message" 0 0
456+
if [ $? -ne 0 ]; then
457+
warn "Thumb drive wipe aborted by user!"
458+
continue
459+
fi
460+
461+
#User chose and confirmed a thumb drive and its size to be wiped
462+
thumb_drive=$FILE
463+
fi
464+
else
465+
#No USB storage device detected
466+
warn "No USB storage device detected! Aborting OEM Factory Reset / Re-Ownership"
467+
sleep 3
468+
die "No USB storage device detected! User decided to not wipe any thumb drive"
469+
fi
470+
done
471+
435472
select_luks_container_size_percent
436473
#Wipe thumb drive with a LUKS container of size $(cat /tmp/luks_container_size_percent)
437474
prepare_thumb_drive --device "$thumb_drive" --percentage "$(cat /tmp/luks_container_size_percent)" --pass "${ADMIN_PIN}"

0 commit comments

Comments
 (0)