Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # SD Card Image Installer
  4. #
  5. # Formats a given SD Card and writes an image to it - now with progress bars!
  6. #
  7. # Before using, ensure "pv" is installed with Homebrew (brew install pv)
  8. #
  9. # Usage: sudo install-pi.sh disk2 your-pi-image.img
  10.  
  11.  
  12. if [ "$(id -u)" != "0" ]; then
  13. echo "This script must be run as root" 1>&2
  14. exit 1
  15. fi
  16.  
  17. if [ $# -lt 2 ]; then
  18. echo "Usage: install diskN target.img"
  19. exit 1
  20. fi
  21.  
  22. if ! which -s pv; then
  23. echo "pv required - please install with homebrew (brew install pv)"
  24. exit 2
  25. fi
  26.  
  27. if [ ! -f $2 ]; then
  28. echo "Image \"$2\" not found"
  29. exit 3
  30. fi
  31.  
  32. if ! diskutil info $1 | grep -q "SD Card"; then
  33. echo "SD Card Reader not found at /dev/$1"
  34. exit 4
  35. fi
  36.  
  37.  
  38.  
  39. TARGET="/dev/$1"
  40.  
  41. printf "\n\e[1m\e[32mCard reader found at \e[33m$TARGET\e[0m\n"
  42.  
  43. printf "\n\e[1m\e[32mFormatting to \e[33mFAT32\e[32m...\e[0m\n"
  44. diskutil eraseDisk fat32 "UNTITLED" "$TARGET"
  45.  
  46. printf "\n\e[1m\e[32mUnmounting...\e[0m\n"
  47. diskutil unmountDisk "$TARGET"
  48.  
  49. printf "\n\e[1m\e[32mCopying image...\e[0m\n"
  50. pv -tpreb "$2" | dd of="$TARGET" bs=1m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement