Creates a bootable key on OSX
This file contains 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 | |
good() { | |
echo "[32m$@[0m" | |
} | |
msg() { | |
echo "[34m$@[0m" | |
} | |
error() { | |
echo "[31m$@[0m" | |
} | |
if [[ -z "$1" ]]; then | |
echo "Usage: $0 iso-file" >&2 | |
exit 1 | |
fi | |
if [[ -r "$1" ]]; then | |
F="$1" | |
OUT=`echo "$F" | sed 's/iso$/img/'` | |
if [[ "$F" = "$OUT" ]]; then | |
error "$F isn't an ISO!" >&2 | |
exit 3 | |
fi | |
if [[ -r "$OUT" ]]; then | |
msg "$OUT already exists, using it without converting" | |
else | |
msg "Converting $F to $OUT" | |
if hdiutil convert -format UDRW -o "$OUT" "$F"; then | |
good "OK" | |
else | |
error "KO" | |
exit 1 | |
fi | |
if [[ ! -r "$OUT" && -r "${OUT}.dmg" ]]; then | |
mv "${OUT}.dmg" "$OUT" | |
fi | |
fi | |
msg "Unplug the USB where you want to create a bootable key and press ENTER" | |
read | |
msg "Here you have a list of the current USB plugged" | |
diskutil list | tee "$0-list-before" | |
msg "Now plug in the USB and press ENTER" | |
read | |
diskutil list | tee "$0-list-after" | |
DISK=`diff "$0-list-after" "$0-list-before" | grep "/dev/disk[0-9][0-9]*" | sed 's#^.*/dev#/dev#'` | |
msg "Is the disk ${DISK} the right one to install?(y/n)" | |
read A | |
if [[ "$A" = "y" ]]; then | |
diskutil unmountDisk "${DISK}" || exit 1 | |
msg "Copying the ISO. You can go take a coffee" | |
sudo dd if=${OUT} of=/${DISK} bs=1m | |
RES="$?" | |
if [[ "$RES" = 0 ]]; then | |
good "Your USB is ready!" | |
else | |
error "There was an error copying the ISO" | |
exit 2 | |
fi | |
else | |
msg "Exititing" | |
exit 0 | |
fi | |
else | |
echo "$1 cannot be readed">&2 | |
exit 2 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment