Skip to content

Instantly share code, notes, and snippets.

@MaiLinhGroup
Last active July 18, 2019 15:15
Show Gist options
  • Save MaiLinhGroup/0b13c6bde42bc8f93401c92bd07778b8 to your computer and use it in GitHub Desktop.
Save MaiLinhGroup/0b13c6bde42bc8f93401c92bd07778b8 to your computer and use it in GitHub Desktop.
Download and install a raspbian image on a SD card for a Raspberry Pi 3 on OSX. Use "chmod +x setup_raspbian_osx.sh" to make it executable.
#!/usr/bin/env bash
# download and write image to sd card
image() {
read -p "Enter raspbian image download link: " link
if [ -n "$link" ]; then
echo "Download latest raspbian image from:" $link
else
link=https://downloads.raspberrypi.org/raspbian_lite_latest
echo "No link provided. Using default link:" $link
fi
zip="${link##*/}"
curl -L $link > $zip && unzip $zip -d .
img=$(ls -t -U *-raspbian-*-lite.img)
echo "Write" $img "with dd to" /dev/$disk
sudo dd bs=1m if=$img of=/dev/$disk conv=sync
echo "dd finished, eject sd card now"
sudo diskutil eject /dev/$disk
# remove artifacts after setup
rm -f $zip && echo "rm" $zip
rm -f $img && echo "rm" $img
}
# discover disk of sd card and unmount sd card
diskutil list
echo "Identify the disk (not the partition) of your SD card, e.g. disk4, not disk4s1"
read -p "Enter disk identifier to be unmounted: " disk
if [ -n $disk ]; then
diskutil unmountDisk /dev/$disk
image "$disk"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment