butterknife-provisioning-image/overlay/sbin/butterknife-select-disk

34 lines
878 B
Plaintext
Raw Permalink Normal View History

2021-02-22 22:32:51 +00:00
#!/bin/sh
if [ -z "$(ls /sys/class/block/)" ]; then
dialog --msgbox "Butterknife was unable to detect any harddisks,\
are you sure harddisk is connected and we have drivers for it?" 0 0
exit 255
fi
for disk in /sys/class/block/*; do
if [ -d $disk/device ]; then
slug=$(basename $disk)
sector_count=$(cat $disk/size)
sector_size=$(cat $disk/queue/hw_sector_size)
# Hack around these dumbass cardreaders
if [ "$sector_count" == "0" ]; then
continue
fi
size=$(expr $sector_count / 1000000 \* $sector_size / 1000 || true)G
if [ -f $disk/device/model ]; then
echo "$slug \"$(cat $disk/device/model | xargs) ($size)\"";
else
echo "$slug \"$size\"";
fi
fi
done > /tmp/disks
dialog \
--menu "Target disk" 0 0 0 \
--file /tmp/disks