Repository: RayViljoen/Raspberry-PI-SD-Installer-OS-X Branch: master Commit: 201ff5b3998b Files: 3 Total size: 3.9 KB Directory structure: gitextract_ha_92_1_/ ├── .gitignore ├── README.md └── install ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ .DS_Store ================================================ FILE: README.md ================================================ # Raspberry PI SD Installer OS X ### Shell Script for creating Raspberry PI SD card on OS X. --- ##### Usage: 1. Simply execute the install script from Terminal and pass the image to write. (Image, not ZIP) eg. `sudo ./install ~/Downloads/wheezyDebian.img` 2. Select the disk to write the image to by selecting the disk number provided in the output. 3. Wait for disk to finish writing. You can check the write progress with `Ctrl+T`. --- ##### CAUTION: **Make absolutely sure to select the correct disk from the list of mounted disks output by the script. Selecting your system drive WILL overwrite it!** If you are unsure which disk you need to select you can remove the SD card, check the mounted disks by running `df -hl` and then re-check after re-inserting the SD card. The disk name will likely be something similar to: `/dev/disk2s1` --- #### [Download SD Card Images here.](http://www.raspberrypi.org/downloads) ================================================ FILE: install ================================================ #!/bin/bash # Raspberry PI Install Script # Author: Ray Viljoen # Quit on error set -e _piline="------------------------------------------------------------------------------------" # Display colorized information output function _info() { COLOR='\033[00;32m' # green RESET='\033[00;00m' # white echo -e "${COLOR}${@}${RESET}" } # Display colorized warning output function _warn() { COLOR='\033[00;31m' # red RESET='\033[00;00m' # white echo -e "${COLOR}${@}${RESET}" } _info ' __________.___ .___ __ .__ .__ \______ \ | | | ____ _______/ |______ | | | | ___________ | ___/ | | |/ \ / ___/\ __\__ \ | | | | _/ __ \_ __ \ | | | | | | | \\___ \ | | / __ \| |_| |_\ ___/| | \/ |____| |___| |___|___| /____ > |__| (____ /____/____/\___ >__| \/ \/ \/ \/ ' # Set $1 as image path DISTRO="$1" # Check image path is set else exit if [ -z "$DISTRO" ]; then _warn $_piline _warn "ERR: No image path supplied" _warn $_piline exit 0 fi # Selected disk _udisk="" function promptDisk() { # ================================================ # Check connected disks and save paths to array # ================================================ # Counter i=0 echo $_piline # Loop over df -lh while read line; do # Print with local mount only and add counter to select disk if [ "$i" -gt 0 ]; then echo "$i) $line" # Asign first work (path) to array with corresponding counter _mount[i]=$( echo $line | awk '{print $1;}') else _info " $line" echo $_piline fi # Increment counter ((i++)) done <<< "$(df -h)" echo -e "$_piline\n" _opts='' for i in "${!_mount[@]}"; do [ -z "$_opts" ] && _opts="${_opts}${i}" || _opts="${_opts}, ${i}" done # Ask user to select mounted disk echo "Select the disk to use by enetering the disk number." _warn "*** MAKE SURE YOU SELECT THE CORRECT DISK ***" _warn "*** Refer to the Readme if uncertain ***" echo -n -e "\nUse disk [ $_opts ] #" read ans # Set selected disk _udisk=${_mount[$ans]} # Test if valid disk selected if [ -z "$_udisk" ]; then _warn "\n ======= Invalid selection ======= \n" promptDisk fi } # Run prompt promptDisk # =========================================================== # Past this point a valid disk has been selected, so proceed. # =========================================================== # Format disk name to raw format _rawdisk=$( echo $_udisk | awk 'sub("..$", "")' | sed 's/disk/rdisk/') # Unmount Disk echo "Unmounting Disk" diskutil unmount $_udisk echo "Writing image" echo "Ctrl+T to see progress.." sudo dd bs=1m if=${DISTRO} of=${_rawdisk} # Eject disk echo "Ejecting Disk" diskutil eject ${_rawdisk} _info "All Done!"