Last active
July 20, 2016 11:35
-
-
Save rey/7bc8ce9d5ef400befb41c0b57cc83c38 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| runDiskFree() { | |
| echo "Running df -h" | |
| echo | |
| df -h | |
| echo | |
| } | |
| getDeviceName() { | |
| echo "Enter the device name (eg. disk1s1)" && read DEVICE_NAME | |
| read -r -p "Is ${DEVICE_NAME} correct? [y/N] " response | |
| if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]] | |
| then | |
| echo "Unmounting..." | |
| sudo diskutil unmount /dev/${DEVICE_NAME} | |
| getDownload | |
| else | |
| echo "ERROR: Wrong device name entered" | |
| exit | |
| fi | |
| } | |
| getDownload() { | |
| echo "Enter the full path to the download (eg. /Users/rey/Downloads/2016-05-27-raspbian-jessie-lite.img)" && read DOWNLOAD_PATH | |
| read -r -p "Is ${DOWNLOAD_PATH} correct? [y/N] " response | |
| if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]] | |
| then | |
| writeImage | |
| else | |
| echo "ERROR: Wrong download path entered" | |
| exit | |
| fi | |
| } | |
| writeImage() { | |
| echo ${DEVICE_NAME} > /tmp/RAW_DEVICE_NAME | |
| sed -i -e 's/disk/rdisk/' /tmp/RAW_DEVICE_NAME | |
| sed -i -e 's/..$//' /tmp/RAW_DEVICE_NAME | |
| RAW_DEVICE_NAME=`cat /tmp/RAW_DEVICE_NAME` | |
| read -r -p "About to run | |
| dd bs=1m if=${DOWNLOAD_PATH} of=/dev/${RAW_DEVICE_NAME} | |
| [y/N] " response | |
| if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]] | |
| then | |
| sudo dd bs=1m if=${DOWNLOAD_PATH} of=/dev/${RAW_DEVICE_NAME} | |
| else | |
| echo "ERROR: Failed final confirmation" | |
| exit | |
| fi | |
| } | |
| trap EXIT | |
| runDiskFree | |
| getDeviceName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment