Created
March 30, 2025 19:42
-
-
Save wathika-eng/1fc40521bf1559d12567a33feea5bbee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Ensure script runs as root | |
| if [[ $EUID -ne 0 ]]; then | |
| echo "β This script must be run as root. Try: sudo $0" | |
| exit 1 | |
| fi | |
| # Enable tab completion for file paths | |
| iso_path="" | |
| usb_device="" | |
| # Function for reading input with tab completion | |
| read_with_completion() { | |
| local prompt="$1" | |
| local var_name="$2" | |
| # Enable readline support for tab completion | |
| echo -n "$prompt" | |
| read -e -r "$var_name" | |
| } | |
| # List available block devices | |
| echo "π Available storage devices:" | |
| lsblk | |
| echo "" | |
| # Ask user for the ISO file path with tab completion | |
| read_with_completion "π Enter the full path to the ISO file: " iso_path | |
| # Verify if ISO file exists | |
| if [[ ! -f "$iso_path" ]]; then | |
| echo "β ISO file not found! Exiting..." | |
| exit 1 | |
| fi | |
| # Ask user for the target USB device | |
| read_with_completion "πΎ Enter the target USB device (e.g., /dev/sdb): " usb_device | |
| # Verify if the device exists | |
| if [[ ! -b "$usb_device" ]]; then | |
| echo "β Invalid USB device! Exiting..." | |
| exit 1 | |
| fi | |
| # Ask for confirmation before proceeding | |
| echo "" | |
| echo "β WARNING: This will ERASE all data on $usb_device!" | |
| read -rp "β Are you sure? (type 'yes' to continue): " confirm | |
| if [[ "$confirm" != "yes" ]]; then | |
| echo "π« Operation cancelled!" | |
| exit 1 | |
| fi | |
| # Unmount any mounted partitions on the USB | |
| echo "π Unmounting $usb_device..." | |
| sudo umount "${usb_device}"* 2>/dev/null | |
| # Write the ISO to USB using dd | |
| echo "β³ Writing ISO to $usb_device..." | |
| sudo dd if="$iso_path" of="$usb_device" bs=4M status=progress conv=fdatasync | |
| # Ensure all data is written before ejecting | |
| sync | |
| echo "β ISO successfully written to $usb_device!" | |
| echo "π‘ You can now safely remove the USB drive." | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment