Skip to content

Instantly share code, notes, and snippets.

@viktorstrate
Last active January 2, 2016 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viktorstrate/4ef6a27632d5d63a3685 to your computer and use it in GitHub Desktop.
Save viktorstrate/4ef6a27632d5d63a3685 to your computer and use it in GitHub Desktop.
A script for mac to install an ISO to a disk like a USB stick. Based on the guide by ubuntu http://www.ubuntu.com/download/desktop/create-a-usb-stick-on-mac-osx
#!/bin/sh
clear
echo "Install ISO on disk"
iso_path=""
# While $iso_path is empty
while [ -z $iso_path ]
do
echo "Path to ISO: "
read iso_path
if ! [ -f $iso_path ]; then
echo "File not found!"
iso_path=""
fi
done
# File found
clear
diskutil list
echo "\n\n"
echo "Which disk number should the iso be installed to? eg. disk[N]"
disk_number=""
while [ -z $disk_number ]
do
echo "Disk number: "
read disk_number
if diskutil info $disk_number | grep -q 'Could not find disk:'; then
echo "Disk not found"
disk_number=""
else
echo "Are you sure you want to install the ISO on this disk,\nthis will erase everything on that disk?"
echo "Press enter to continue, press CTRL+C to abort."
read confirm
fi
done
clear
echo "Converting disk image..."
if [ -e $HOME/TmpDiskImage.dmg ]; then
echo "Temporary disk image already exists, removing..."
rm $HOME/TmpDiskImage.dmg
fi
hdiutil convert -format UDRW -o $HOME/TmpDiskImage.dmg $iso_path
echo "\nUnmounting disk..."
if diskutil unmountDisk $disk_number | grep -q 'was successful'; then
echo "Successfully unmounted disk"
else
echo "Could not unmount disk: $disk_number"
exit 1
fi
echo "\nInstalling Disk Image on $disk_number"
sudo dd if=$HOME/TmpDiskImage.dmg of=$disk_number bs=1m
rm $HOME/TmpDiskImage.dmg
echo "\nEjecting Disk"
diskutil eject $disk_number
echo "\nISO installed on disk successfully, you can now remove it from this computer"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment