From 44b920c89dbefd1a503e8bf2b033b7ce2afb5730 Mon Sep 17 00:00:00 2001 From: Mollusk Date: Thu, 29 Oct 2026 14:19:19 -0400 Subject: [PATCH] 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 --- format-buddy.sh | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/format-buddy.sh b/format-buddy.sh index 8eada66..eae36b8 100755 --- a/format-buddy.sh +++ b/format-buddy.sh @@ -1,30 +1,48 @@ #!/bin/bash -while [ 1=1 ];do +while true; do clear echo "[1] - Format device as Fat32" + echo "[2] - Exit" echo echo -n ">>: " read choice - if [ "$choice" = "1" ];then + if [ "${choice}" = "1" ];then echo lsblk echo echo -n "Type full path to device (/dev/xx1): " 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 - echo "Fuck....." + echo "Invalid option" + read -n 1 -p "Press any key..." fi done