summaryrefslogtreecommitdiff
path: root/burnit.sh
blob: f6792ab75ccdfe36882acc260903501f1abd95dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# burnit.sh - Interactive ISO-to-USB writer with menu

set -euo pipefail

ISO_DIR="/gigapool/vms/isos"  # Change this to wherever you keep ISOs

echo "๐Ÿ”ฅ Welcome to burnit.sh โ€“ ISO burner for Unix junkies."
echo

# Step 1: List ISOs in ISO_DIR
echo "๐Ÿ“ Scanning for ISOs in: $ISO_DIR"
mapfile -t isos < <(find "$ISO_DIR" -maxdepth 1 -type f \( -iname "*.iso" -o -iname "*.img" \) | sort)

if [[ ${#isos[@]} -eq 0 ]]; then
  echo "โŒ No ISO or IMG files found in $ISO_DIR."
  exit 1
fi

echo "๐Ÿ“ฆ Available ISO/IMG files:"
for i in "${!isos[@]}"; do
  printf "  [%d] %s\n" "$i" "$(basename "${isos[$i]}")"
done

echo
read -rp "๐ŸŽฏ Pick an image number: " index

if ! [[ "$index" =~ ^[0-9]+$ ]] || (( index < 0 || index >= ${#isos[@]} )); then
  echo "โŒ Invalid selection."
  exit 1
fi

iso="${isos[$index]}"
echo "โœ… Selected: $(basename "$iso")"
echo

# Step 2: List available removable devices
echo "๐Ÿ’ฝ Scanning removable block devices..."
lsblk -o NAME,SIZE,MODEL,MOUNTPOINT,TRAN,VENDOR,HOTPLUG | grep -E '1$' || true
echo

read -rp "๐Ÿงจ Enter the target device (e.g., /dev/sdX): " target
if [[ ! -b "$target" ]]; then
  echo "โŒ Device not found: $target"
  exit 1
fi

echo
read -rp "โš ๏ธ ARE YOU SURE you want to overwrite $target with $iso? [y/N]: " confirm
if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
  echo "๐Ÿ›‘ Aborted."
  exit 1
fi

echo
echo "๐Ÿš€ Flashing image..."
sleep 1

pv "$iso" | sudo dd of="$target" bs=4M status=progress oflag=sync

echo
echo "โœ… Done writing to $target."

# Optional: Eject
if mount | grep "$target" > /dev/null; then
  sudo umount "${target}"* || true
fi
if command -v eject &> /dev/null; then
  sudo eject "$target" || true
fi

echo "๐Ÿ’ฟ Bootable media is ready to rock."