Created
September 10, 2015 21:44
-
-
Save EyePulp/f565288be31fda517a27 to your computer and use it in GitHub Desktop.
Make resin.io SD image burning a little less painful on a Mac
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 | |
echo "------------------------------------------------------------------------" | |
if [[ "$#" -ne 2 ]]; then | |
echo "IMG Burner -- Built for macbook pros w/ the SD card slot on the right." | |
echo " - Insert a blank SD card" | |
echo " - run with two args - img file and destination disk (typically disk2, disk3, etc. NEVER disk1 or sda1)" | |
echo " - run $ mount to see what disks are available" | |
echo " - Example: $ ./resin.img.burn.sh path/to/resin.img disk2" | |
exit | |
fi | |
SRC=$1 | |
DEVICE=$2 | |
DEST="/dev/${DEVICE}s1" | |
DDOF="/dev/r${DEVICE}" | |
# make sure our source image exists | |
if [[ -f "$SRC" ]]; then | |
IFS=' ' read -ra BYTES <<< `wc -c $SRC` | |
# figure out the destination file size | |
echo " + Found $SRC -- $BYTES bytes" | |
else | |
echo " ! Could not find $SRC" | |
exit 1 | |
fi | |
# make sure we have a device @ the expected location | |
if mount | grep $DEST > /dev/null; then | |
echo " + Found an SD Card @ $DEST (hope you don't have anything important on it)" | |
else | |
echo " ! Cannot find an SD card @ $DEST -- insert one and verify $DEVICE is the right disk" | |
exit 1 | |
fi | |
# start a clock | |
START=$(date +%s) | |
echo " + Unmounting $DEST (requires your password)" | |
sudo diskutil unmount $DEST | |
echo " + Burning $SRC to $DEST" | |
echo " + Writing $BYTES bytes total..." | |
echo " (CTRL+t for progress...)" | |
# do the actual work | |
sudo dd bs=1m if=$SRC of=$DDOF | |
afplay /System/Library/Sounds/Ping.aiff | |
sudo diskutil unmountDisk $DDOF | |
# stop the clock | |
END=$(date +%s) | |
DIFF=$(echo "$END - $START" | bc) | |
echo " + Finished in $DIFF seconds!" | |
echo " + The SD card is unmounted, so yank it out and do another." | |
echo "------------------------------------------------------------------------" | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment