Skip to content

Instantly share code, notes, and snippets.

@abulte
Last active December 9, 2015 18:28
Show Gist options
  • Save abulte/4309828 to your computer and use it in GitHub Desktop.
Save abulte/4309828 to your computer and use it in GitHub Desktop.
Raspberry image to sd shell script (mac os)
#!/bin/bash
EXPECTED_ARGS=2
NAME=$1
if [ $# -ne $EXPECTED_ARGS ]
then
echo "Usage: `basename $0` <partition_name> <image_path>"
echo "Example: `basename $0` disk2s1 ./rpi.img"
exit $E_BADARGS
fi
echo
echo "You're probably trying to use this disk:"
df -h | grep $NAME
echo
echo
DISK_NAME="r"${NAME:0:5}
echo "Confirm you want to unmount /dev/$1 and erase /dev/$DISK_NAME by typing 'Yes, sir'"
read confirmation
if [ "$confirmation" != 'Yes, sir' ]
then
echo "Abort!"
exit 0
fi
echo
echo "sudo diskutil unmount /dev/$NAME"
sudo diskutil unmount /dev/$NAME
echo
if [ ! -f $2 ]
then
echo "File $2 does not exist."
exit 0
fi
echo "sudo dd bs=1m if=$2 of=/dev/$DISK_NAME"
echo "Please wait, might take a long time..."
sudo dd bs=1m if="$2" of=/dev/$DISK_NAME
echo
echo "sudo diskutil eject /dev/$DISK_NAME"
sudo diskutil eject /dev/$DISK_NAME
echo
echo "Well done my friend \o/ Cheers."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment