Skip to content

Instantly share code, notes, and snippets.

@alenbasic
Last active October 3, 2015 00:13
Show Gist options
  • Save alenbasic/67987e4bb27bccfdd5a0 to your computer and use it in GitHub Desktop.
Save alenbasic/67987e4bb27bccfdd5a0 to your computer and use it in GitHub Desktop.
A simple script for OSX for taking ISOs and imaging them onto USBs.
#!/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
printf "\nNOTE: If you do not see ${GREEN}## \
COMPLETED SUCCESSFULLY ##${NC} prior to the script \
exitingthen 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 "${GREEN}## FILE CONVERSION ##${NC}\n\n"
img="${1%iso}img"
printf "original: ${CYAN}$1${NC}\n"
printf "new file: ${PURPLE}$img${NC}\n"
read -p "proceed (y/n): " ans
if [ "$ans" == "y" ]; then
hdiutil convert -format UDRW -o "$img" "$1"
mv "$img.dmg" "$img"
else
printf "exiting script..\n"
exit 0
fi
printf "\n${GREEN}## EJECT USB ##${NC}\n\n"
diskutil list
echo ""
read -p "which disk is being ejected - enter number only: " usrinp
printf "eject ${GREEN}/dev/disk$usrinp${NC} and img (y/n): "
read ans
if [ "$ans" == "y" ]; then
diskutil unmountDisk "/dev/disk$usrinp"
printf "\n${GREEN}## IMAGING USB ##${NC}\n\n"
printf "If requested, enter password to begin imaging..\n"
printf "\n${GREEN}NOTE: dd produces no output until completion. It will look like it is not doing anything. This is perfectly normal. Please be patient.${NC}\n\n"
sudo dd if="$img" of="/dev/rdisk$usrinp" bs=1m
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