format-buddy.sh: add device validation and format confirmation

Validate the device path, require typing YES before formatting, quote
the device, fix the mkfs.fat label argument, and add an exit option.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 14:22:37 -04:00
co-authored by Claude Opus 5.5
parent dd004108f2
commit 44b920c89d
+23 -5
View File
@@ -1,30 +1,48 @@
#!/bin/bash #!/bin/bash
while [ 1=1 ];do while true; do
clear clear
echo "[1] - Format device as Fat32" echo "[1] - Format device as Fat32"
echo "[2] - Exit"
echo echo
echo -n ">>: " echo -n ">>: "
read choice read choice
if [ "$choice" = "1" ];then if [ "${choice}" = "1" ];then
echo echo
lsblk lsblk
echo echo
echo -n "Type full path to device (/dev/xx1): " echo -n "Type full path to device (/dev/xx1): "
read device read device
mkfs.fat -F32 -v -l -n $device if [[ ! "${device}" =~ ^/dev/[a-z]+[0-9]*$ ]]; then
echo "Error: Invalid device path"
read -n 1 -p "Press any key..."
continue
fi
echo "WARNING: This will destroy ALL data on ${device}"
echo -n "Type 'YES' to confirm: "
read confirm
if [ "${confirm}" != "YES" ]; then
echo "Aborted."
read -n 1 -p "Press any key..."
continue
fi
mkfs.fat -F32 -v -n "FAT32" "${device}"
echo "Format complete."
read -n 1 -p "Press any key..."
elif [ "${choice}" = "2" ];then
break
else else
echo "Fuck....." echo "Invalid option"
read -n 1 -p "Press any key..."
fi fi
done done