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.

184 lines
4.8 KiB

  1. #!/bin/bash
  2. if [ $(id -u) -ne 0 ]; then
  3. echo "Installer must be run as root."
  4. echo "Try 'sudo bash $0'"
  5. exit 1
  6. fi
  7. clear
  8. echo "This script installs software for the Adafruit"
  9. echo "Arcade Bonnet for Raspberry Pi. Steps include:"
  10. echo "- Update package index files (apt-get update)."
  11. echo "- Install Python libraries: smbus, evdev."
  12. echo "- Install arcadeBonnet.py in /boot and"
  13. echo " configure /etc/rc.local to auto-start script."
  14. echo "- Enable I2C bus."
  15. echo "- OPTIONAL: disable overscan."
  16. echo "I2S audio IS NOT INSTALLED by this script!"
  17. echo "Run the i2samp.sh script separately for that."
  18. echo "Run time ~10 minutes. Reboot required."
  19. echo "EXISTING INSTALLATION, IF ANY, WILL BE OVERWRITTEN."
  20. echo
  21. echo -n "CONTINUE? [y/N] "
  22. read
  23. if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
  24. echo "Canceled."
  25. exit 0
  26. fi
  27. # FEATURE PROMPTS ----------------------------------------------------------
  28. # Installation doesn't begin until after all user input is taken.
  29. DISABLE_OVERSCAN=0
  30. INSTALL_HALT=0
  31. # Given a list of strings representing options, display each option
  32. # preceded by a number (1 to N), display a prompt, check input until
  33. # a valid number within the selection range is entered.
  34. selectN() {
  35. for ((i=1; i<=$#; i++)); do
  36. echo $i. ${!i}
  37. done
  38. echo
  39. REPLY=""
  40. while :
  41. do
  42. echo -n "SELECT 1-$#: "
  43. read
  44. if [[ $REPLY -ge 1 ]] && [[ $REPLY -le $# ]]; then
  45. return $REPLY
  46. fi
  47. done
  48. }
  49. echo -n "Disable overscan? [y/N] "
  50. read
  51. if [[ "$REPLY" =~ (yes|y|Y)$ ]]; then
  52. DISABLE_OVERSCAN=1
  53. fi
  54. echo -n "Install GPIO-halt utility? [y/N] "
  55. read
  56. if [[ "$REPLY" =~ (yes|y|Y)$ ]]; then
  57. INSTALL_HALT=1
  58. echo -n "GPIO pin for halt: "
  59. read
  60. HALT_PIN=$REPLY
  61. fi
  62. echo
  63. if [ $DISABLE_OVERSCAN -eq 1 ]; then
  64. echo "Overscan: disable."
  65. else
  66. echo "Overscan: keep current setting."
  67. fi
  68. if [ $INSTALL_HALT -eq 1 ]; then
  69. echo "Install GPIO-halt: YES (GPIO$HALT_PIN)"
  70. else
  71. echo "Install GPIO-halt: NO"
  72. fi
  73. echo
  74. echo -n "CONTINUE? [y/N] "
  75. read
  76. if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
  77. echo "Canceled."
  78. exit 0
  79. fi
  80. # START INSTALL ------------------------------------------------------------
  81. # All selections are validated at this point...
  82. # Given a filename, a regex pattern to match and a replacement string,
  83. # perform replacement if found, else append replacement to end of file.
  84. # (# $1 = filename, $2 = pattern to match, $3 = replacement)
  85. reconfig() {
  86. grep $2 $1 >/dev/null
  87. if [ $? -eq 0 ]; then
  88. # Pattern found; replace in file
  89. sed -i "s/$2/$3/g" $1 >/dev/null
  90. else
  91. # Not found; append (silently)
  92. echo $3 | sudo tee -a $1 >/dev/null
  93. fi
  94. }
  95. echo
  96. echo "Starting installation..."
  97. echo "Updating package index files..."
  98. apt-get update
  99. echo "Installing Python libraries..."
  100. apt-get install -y --force-yes python-pip python-dev python-smbus
  101. pip install evdev
  102. echo "Installing Adafruit code in /boot..."
  103. cd /tmp
  104. curl -LO https://raw.githubusercontent.com/adafruit/Adafruit-Retrogame/master/arcadeBonnet.py
  105. # Moving between filesystems requires copy-and-delete:
  106. cp -r arcadeBonnet.py /boot
  107. rm -f arcadeBonnet.py
  108. if [ $INSTALL_HALT -ne 0 ]; then
  109. echo "Installing gpio-halt in /usr/local/bin..."
  110. curl -LO https://github.com/adafruit/Adafruit-GPIO-Halt/archive/master.zip
  111. unzip master.zip
  112. cd Adafruit-GPIO-Halt-master
  113. make
  114. mv gpio-halt /usr/local/bin
  115. cd ..
  116. rm -rf Adafruit-GPIO-Halt-master
  117. fi
  118. # CONFIG -------------------------------------------------------------------
  119. echo "Configuring system..."
  120. # Enable I2C using raspi-config
  121. raspi-config nonint do_i2c 0
  122. # Disable overscan compensation (use full screen):
  123. if [ $DISABLE_OVERSCAN -eq 1 ]; then
  124. raspi-config nonint do_overscan 1
  125. fi
  126. if [ $INSTALL_HALT -ne 0 ]; then
  127. # Add gpio-halt to /rc.local:
  128. grep gpio-halt /etc/rc.local >/dev/null
  129. if [ $? -eq 0 ]; then
  130. # gpio-halt already in rc.local, but make sure correct:
  131. sed -i "s/^.*gpio-halt.*$/\/usr\/local\/bin\/gpio-halt $HALT_PIN \&/g" /etc/rc.local >/dev/null
  132. else
  133. # Insert gpio-halt into rc.local before final 'exit 0'
  134. sed -i "s/^exit 0/\/usr\/local\/bin\/gpio-halt $HALT_PIN \&\\nexit 0/g" /etc/rc.local >/dev/null
  135. fi
  136. fi
  137. # Auto-start arcadeBonnet.py on boot
  138. grep arcadeBonnet.py /etc/rc.local >/dev/null
  139. if [ $? -eq 0 ]; then
  140. # arcadeBonnet.py already in rc.local, but make sure correct:
  141. sed -i "s/^.*arcadeBonnet.py.*$/cd \/boot;python arcadeBonnet.py \&/g" /etc/rc.local >/dev/null
  142. else
  143. # Insert arcadeBonnet.py into rc.local before final 'exit 0'
  144. sed -i "s/^exit 0/cd \/boot;python arcadeBonnet.py \&\\nexit 0/g" /etc/rc.local >/dev/null
  145. fi
  146. # Add udev rule (will overwrite if present)
  147. echo "SUBSYSTEM==\"input\", ATTRS{name}==\"retrogame\", ENV{ID_INPUT_KEYBOARD}=\"1\"" > /etc/udev/rules.d/10-retrogame.rules
  148. # PROMPT FOR REBOOT --------------------------------------------------------
  149. echo "Done."
  150. echo
  151. echo "Settings take effect on next boot."
  152. echo
  153. echo -n "REBOOT NOW? [y/N] "
  154. read
  155. if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
  156. echo "Exiting without reboot."
  157. exit 0
  158. fi
  159. echo "Reboot started..."
  160. reboot
  161. exit 0