34 lines
878 B
Bash
Executable File
34 lines
878 B
Bash
Executable File
#!/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
|
|
|
|
|