Skip to content

Instantly share code, notes, and snippets.

@posva posva/boot-key.sh
Last active Aug 29, 2015

Embed
What would you like to do?
Creates a bootable key on OSX
#! /bin/bash
good() {
echo "$@"
}
msg() {
echo "$@"
}
error() {
echo "$@"
}
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
You can’t perform that action at this time.