Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # SD Card Image Installer
- #
- # Formats a given SD Card and writes an image to it - now with progress bars!
- #
- # Before using, ensure "pv" is installed with Homebrew (brew install pv)
- #
- # Usage: sudo install-pi.sh disk2 your-pi-image.img
- if [ "$(id -u)" != "0" ]; then
- echo "This script must be run as root" 1>&2
- exit 1
- fi
- if [ $# -lt 2 ]; then
- echo "Usage: install diskN target.img"
- exit 1
- fi
- if ! which -s pv; then
- echo "pv required - please install with homebrew (brew install pv)"
- exit 2
- fi
- if [ ! -f $2 ]; then
- echo "Image \"$2\" not found"
- exit 3
- fi
- if ! diskutil info $1 | grep -q "SD Card"; then
- echo "SD Card Reader not found at /dev/$1"
- exit 4
- fi
- TARGET="/dev/$1"
- printf "\n\e[1m\e[32mCard reader found at \e[33m$TARGET\e[0m\n"
- printf "\n\e[1m\e[32mFormatting to \e[33mFAT32\e[32m...\e[0m\n"
- diskutil eraseDisk fat32 "UNTITLED" "$TARGET"
- printf "\n\e[1m\e[32mUnmounting...\e[0m\n"
- diskutil unmountDisk "$TARGET"
- printf "\n\e[1m\e[32mCopying image...\e[0m\n"
- pv -tpreb "$2" | dd of="$TARGET" bs=1m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement