Skip to content

Instantly share code, notes, and snippets.

@alenbasic
Created August 12, 2020 12:21
Show Gist options
  • Save alenbasic/82b1f00fc70ae5746cf0e4aaa48b2521 to your computer and use it in GitHub Desktop.
Save alenbasic/82b1f00fc70ae5746cf0e4aaa48b2521 to your computer and use it in GitHub Desktop.
Linux version of an earlier iso2usb script I made
#!/bin/bash
# iso2usb is a simple script for OSX to ease the conversion of an iso to an img file
# and then dd that img file to a USB of your choosing. You simply give it the iso
# as a parameter and then the disk number and it will take care of the rest.
# based on the commands here: http://www.ubuntu.com/download/desktop/create-a-usb-stick-on-mac-osx
# and the color commands here: http://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
# exits out of the script upon error
set -e
# colors
# feel free to replace the color choices
# I made below with any of the following
BLACK='\033[0;30m'
DGRAY='\033[1;30m'
RED='\033[0;31m'
LRED='\033[1;31m'
GREEN='\033[0;32m'
LGREEN='\033[1;32m'
ORANGE='\033[0;33m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
LBLUE='\033[1;34m'
PURPLE='\033[0;35m'
LPURPLE='\033[1;35m'
CYAN='\033[0;36m'
LCYAN='\033[1;36m'
LGRAY='\033[0;37m'
WHITE='\033[1;37m'
NC='\033[0m'
# beginning of actual script
if [ ! -z "$1" ]; then
img="$1"
printf "\nNOTE: If you do not see ${GREEN}## \
COMPLETED SUCCESSFULLY ##${NC} prior to the script \
exiting then something has gone wrong and you will \
need to investigate further.\n"
printf "\n${RED}DO NOT ASSUME THAT THE USB IS USABLE!${NC}\n\n"
printf "\n${GREEN}## WRITE TO USB ##${NC}\n\n"
lsblk -io KNAME,TYPE,SIZE,MODEL | grep "disk"
echo ""
read -p "which disk is being written to: " usrinp
printf "image ${GREEN}/dev/$usrinp${NC} (y/n): "
read ans
if [ "$ans" == "y" ]; then
printf "\n${GREEN}## IMAGING USB ##${NC}\n\n"
printf "If requested, enter password to begin imaging..\n"
sudo dd if="$img" of="/dev/$usrinp" status=progress
printf "\n${GREEN}## COMPLETED SUCCESSFULLY ##${NC}\n\n"
else
printf "exiting script..\n"
exit 0
fi
else
printf "${RED}ERROR:${NC} No file name given\n"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment