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.

114 lines
3.1 KiB

7 years ago
  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. # Given a list of strings representing options, display each option
  8. # preceded by a number (1 to N), display a prompt, check input until
  9. # a valid number within the selection range is entered.
  10. selectN() {
  11. for ((i=1; i<=$#; i++)); do
  12. echo $i. ${!i}
  13. done
  14. echo
  15. REPLY=""
  16. while :
  17. do
  18. echo -n "SELECT 1-$#: "
  19. read
  20. if [[ $REPLY -ge 1 ]] && [[ $REPLY -le $# ]]; then
  21. return $REPLY
  22. fi
  23. done
  24. }
  25. clear
  26. echo "This script downloads and installs"
  27. echo "retrogame, a GPIO-to-keypress utility"
  28. echo "for adding buttons and joysticks, plus"
  29. echo "one of several configuration files."
  30. echo "Run time <1 minute. Reboot recommended."
  31. echo
  32. echo "Select configuration:"
  33. selectN "PiGRRL 2 controls" \
  34. "Pocket PiGRRL" \
  35. "PiGRRL Zero" \
  36. "Super Game Pi" \
  37. "Two buttons + joystick" \
  38. "Six buttons + joystick" \
  39. "Adafruit Arcade Bonnet" \
  40. "Cupcade (gen 1 & 2 only)" \
  41. "Quit without installing"
  42. RETROGAME_SELECT=$?
  43. # These are the retrogame.cfg.* filenames on Github corresponding in
  44. # order to each of the above selections (e.g. retrogame.cfg.pigrrl2):
  45. CONFIGNAME=(pigrrl2 pocket zero super 2button 6button bonnet cupcade-orig)
  46. if [ $RETROGAME_SELECT -lt 9 ]; then
  47. if [ -e /boot/retrogame.cfg ]; then
  48. echo "/boot/retrogame.cfg already exists."
  49. echo "Continuing will overwrite file."
  50. echo -n "CONTINUE? [y/N] "
  51. read
  52. if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
  53. echo "Canceled."
  54. exit 0
  55. fi
  56. fi
  57. echo -n "Downloading, installing retrogame..."
  58. # Download to tmpfile because might already be running
  59. curl -f -s -o /tmp/retrogame https://raw.githubusercontent.com/adafruit/Adafruit-Retrogame/master/retrogame
  60. if [ $? -eq 0 ]; then
  61. mv /tmp/retrogame /usr/local/bin
  62. chmod 755 /usr/local/bin/retrogame
  63. echo "OK"
  64. else
  65. echo "ERROR"
  66. fi
  67. echo -n "Downloading, installing retrogame.cfg..."
  68. curl -f -s -o /boot/retrogame.cfg https://raw.githubusercontent.com/adafruit/Adafruit-Retrogame/master/configs/retrogame.cfg.${CONFIGNAME[$RETROGAME_SELECT-1]}
  69. if [ $? -eq 0 ]; then
  70. echo "OK"
  71. else
  72. echo "ERROR"
  73. fi
  74. echo -n "Performing other system configuration..."
  75. # Add udev rule (will overwrite if present)
  76. echo "SUBSYSTEM==\"input\", ATTRS{name}==\"retrogame\", ENV{ID_INPUT_KEYBOARD}=\"1\"" > /etc/udev/rules.d/10-retrogame.rules
  77. if [ $RETROGAME_SELECT -eq 7 ]; then
  78. # If Bonnet, make sure I2C is enabled. Call the I2C
  79. # setup function in raspi-config (noninteractive):
  80. raspi-config nonint do_i2c 0
  81. fi
  82. # Start on boot
  83. grep retrogame /etc/rc.local >/dev/null
  84. if [ $? -eq 0 ]; then
  85. # retrogame already in rc.local, but make sure correct:
  86. sed -i "s/^.*retrogame.*$/\/usr\/local\/bin\/retrogame \&/g" /etc/rc.local >/dev/null
  87. else
  88. # Insert retrogame into rc.local before final 'exit 0'
  89. sed -i "s/^exit 0/\/usr\/local\/bin\/retrogame \&\\nexit 0/g" /etc/rc.local >/dev/null
  90. fi
  91. echo "OK"
  92. echo
  93. echo -n "REBOOT NOW? [y/N]"
  94. read
  95. if [[ "$REPLY" =~ ^(yes|y|Y)$ ]]; then
  96. echo "Reboot started..."
  97. reboot
  98. #else
  99. echo
  100. echo "Done"
  101. fi
  102. fi