No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rgb-matrix.sh.bak 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #!/bin/bash
  2. # INSTALLER SCRIPT FOR ADAFRUIT RGB MATRIX BONNET OR HAT
  3. # hzeller/rpi-rgb-led-matrix sees lots of active development!
  4. # That's cool and all, BUT, to avoid tutorial breakage,
  5. # we reference a specific commit (update this as needed):
  6. GITUSER=https://github.com/hzeller
  7. REPO=rpi-rgb-led-matrix
  8. COMMIT=58830f7bb5dfb47fc24f1fd26cd7c4e3a20f13f7
  9. if [ $(id -u) -ne 0 ]; then
  10. echo "Installer must be run as root."
  11. echo "Try 'sudo bash $0'"
  12. exit 1
  13. fi
  14. clear
  15. echo "This script installs software for the Adafruit"
  16. echo "RGB Matrix Bonnet or HAT for Raspberry Pi."
  17. echo "Steps include:"
  18. echo "- Update package index files (apt-get update)"
  19. echo "- Install prerequisite software"
  20. echo "- Install RGB matrix driver software"
  21. echo "- Configure boot options"
  22. echo "Run time ~10 minutes. Some options require reboot."
  23. echo "EXISTING INSTALLATION, IF ANY, WILL BE OVERWRITTEN."
  24. echo
  25. echo -n "CONTINUE? [y/N] "
  26. read
  27. if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
  28. echo "Canceled."
  29. exit 0
  30. fi
  31. # FEATURE PROMPTS ----------------------------------------------------------
  32. # Installation doesn't begin until after all user input is taken.
  33. INTERFACE_TYPE=0
  34. INSTALL_RTC=0
  35. QUALITY_MOD=0
  36. # Given a list of strings representing options, display each option
  37. # preceded by a number (1 to N), display a prompt, check input until
  38. # a valid number within the selection range is entered.
  39. # Can we pass an array?
  40. selectN() {
  41. args=("${@}")
  42. for ((i=0; i<$#; i++)); do
  43. echo $((i+1)). ${args[$i]}
  44. done
  45. echo
  46. REPLY=""
  47. while :
  48. do
  49. echo -n "SELECT 1-$#: "
  50. read
  51. if [[ $REPLY -ge 1 ]] && [[ $REPLY -le $# ]]; then
  52. return $REPLY
  53. fi
  54. done
  55. }
  56. OPTION_NAMES=(NO YES)
  57. INTERFACES=( \
  58. "Adafruit RGB Matrix Bonnet" \
  59. "Adafruit RGB Matrix HAT + RTC" \
  60. )
  61. QUALITY_OPTS=( \
  62. "Quality (disables sound, requires soldering)" \
  63. "Convenience (sound on, no soldering)" \
  64. )
  65. echo
  66. echo "Select interface board type:"
  67. selectN "${INTERFACES[@]}"
  68. INTERFACE_TYPE=$?
  69. if [ $INTERFACE_TYPE -eq 2 ]; then
  70. # For matrix HAT, ask about RTC install
  71. echo
  72. echo -n "Install realtime clock support? [y/N] "
  73. read
  74. if [[ "$REPLY" =~ (yes|y|Y)$ ]]; then
  75. INSTALL_RTC=1
  76. fi
  77. fi
  78. echo
  79. echo "Now you must choose between QUALITY and CONVENIENCE."
  80. echo
  81. echo "QUALITY: best output from the LED matrix requires"
  82. echo "commandeering hardware normally used for sound, plus"
  83. echo "some soldering. If you choose this option, there will"
  84. echo "be NO sound from the audio jack or HDMI (USB audio"
  85. echo "adapters will work and sound best anyway), AND you"
  86. echo "must SOLDER a wire between GPIO4 and GPIO18 on the"
  87. echo "Bonnet or HAT board."
  88. echo
  89. echo "CONVENIENCE: sound works normally, no extra soldering."
  90. echo "Images on the LED matrix are not quite as steady, but"
  91. echo "maybe OK for most uses. If eager to get started, use"
  92. echo "'CONVENIENCE' for now, you can make the change and"
  93. echo "reinstall using this script later!"
  94. echo
  95. echo "What is thy bidding?"
  96. selectN "${QUALITY_OPTS[@]}"
  97. QUALITY_MOD=$?
  98. # VERIFY SELECTIONS BEFORE CONTINUING --------------------------------------
  99. echo
  100. echo "Interface board type: ${INTERFACES[$INTERFACE_TYPE-1]}"
  101. if [ $INTERFACE_TYPE -eq 2 ]; then
  102. echo "Install RTC support: ${OPTION_NAMES[$INSTALL_RTC]}"
  103. fi
  104. echo "Optimize: ${QUALITY_OPTS[$QUALITY_MOD-1]}"
  105. if [ $QUALITY_MOD -eq 1 ]; then
  106. echo "Reminder: you must SOLDER a wire between GPIO4"
  107. echo "and GPIO18, and internal sound is DISABLED!"
  108. fi
  109. echo
  110. echo -n "CONTINUE? [y/N] "
  111. read
  112. if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
  113. echo "Canceled."
  114. exit 0
  115. fi
  116. # START INSTALL ------------------------------------------------------------
  117. # All selections are validated at this point...
  118. # Given a filename, a regex pattern to match and a replacement string,
  119. # perform replacement if found, else append replacement to end of file.
  120. # (# $1 = filename, $2 = pattern to match, $3 = replacement)
  121. reconfig() {
  122. grep $2 $1 >/dev/null
  123. if [ $? -eq 0 ]; then
  124. # Pattern found; replace in file
  125. sed -i "s/$2/$3/g" $1 >/dev/null
  126. else
  127. # Not found; append (silently)
  128. echo $3 | sudo tee -a $1 >/dev/null
  129. fi
  130. }
  131. echo
  132. echo "Starting installation..."
  133. echo "Updating package index files..."
  134. apt-get update
  135. echo "Downloading prerequisites..."
  136. apt-get install -y --force-yes python-dev python-imaging
  137. echo "Downloading RGB matrix software..."
  138. curl -L $GITUSER/$REPO/archive/$COMMIT.zip -o $REPO-$COMMIT.zip
  139. unzip -q $REPO-$COMMIT.zip
  140. rm $REPO-$COMMIT.zip
  141. mv $REPO-$COMMIT rpi-rgb-led-matrix
  142. echo "Building RGB matrix software..."
  143. cd rpi-rgb-led-matrix
  144. if [ $QUALITY_MOD -eq 1 ]; then
  145. HARDWARE_DESC=adafruit-hat-pwm make
  146. cd bindings/python
  147. python setup.py install
  148. else
  149. HARDWARE_DESC=adafruit-hat make USER_DEFINES="-DDISABLE_HARDWARE_PULSES"
  150. cd bindings/python
  151. python setup.py install
  152. fi
  153. # Change ownership to user calling sudo
  154. cd ../../..
  155. chown -R $SUDO_USER:$(id -g $SUDO_USER) rpi-rgb-led-matrix
  156. # CONFIG -------------------------------------------------------------------
  157. echo "Configuring system..."
  158. if [ $INSTALL_RTC -ne 0 ]; then
  159. # Enable I2C for RTC
  160. raspi-config nonint do_i2c 0
  161. # Do additional RTC setup for DS1307
  162. reconfig /boot/config.txt "^.*dtoverlay=i2c-rtc.*$" "dtoverlay=i2c-rtc,ds1307"
  163. apt-get -y remove fake-hwclock
  164. update-rc.d -f fake-hwclock remove
  165. sudo sed --in-place '/if \[ -e \/run\/systemd\/system \] ; then/,+2 s/^#*/#/' /lib/udev/hwclock-set
  166. fi
  167. if [ $QUALITY_MOD -eq 1 ]; then
  168. # Disable sound ('easy way' -- kernel module not blacklisted)
  169. reconfig /boot/config.txt "^.*dtparam=audio.*$" "dtparam=audio=off"
  170. else
  171. # Enable sound (ditto)
  172. reconfig /boot/config.txt "^.*dtparam=audio.*$" "dtparam=audio=on"
  173. fi
  174. # PROMPT FOR REBOOT --------------------------------------------------------
  175. echo "Done."
  176. echo
  177. echo "Settings take effect on next boot."
  178. if [ $INSTALL_RTC -ne 0 ]; then
  179. echo "RTC will be enabled then but time must be set"
  180. echo "up using the 'date' and 'hwclock' commands."
  181. fi
  182. echo
  183. echo -n "REBOOT NOW? [y/N] "
  184. read
  185. if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
  186. echo "Exiting without reboot."
  187. exit 0
  188. fi
  189. echo "Reboot started..."
  190. reboot
  191. exit 0