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.

119 lines
2.6 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. #!/bin/bash
  2. #-------------------------------------------------------------------------
  3. # Installer script for I2S microphone support on Raspberry Pi
  4. #
  5. # 2020/04/15
  6. # 2020/07/08 remove DKMS
  7. #-------------------------------------------------------------------------
  8. ############################ Script assisters ############################
  9. # Given a list of strings representing options, display each option
  10. # preceded by a number (1 to N), display a prompt, check input until
  11. # a valid number within the selection range is entered.
  12. selectN() {
  13. for ((i=1; i<=$#; i++)); do
  14. echo $i. ${!i}
  15. done
  16. echo
  17. REPLY=""
  18. while :
  19. do
  20. echo -n "SELECT 1-$#: "
  21. read
  22. if [[ $REPLY -ge 1 ]] && [[ $REPLY -le $# ]]; then
  23. return $REPLY
  24. fi
  25. done
  26. }
  27. function ask() {
  28. # http://djm.me/ask
  29. while true; do
  30. if [ "${2:-}" = "Y" ]; then
  31. prompt="Y/n"
  32. default=Y
  33. elif [ "${2:-}" = "N" ]; then
  34. prompt="y/N"
  35. default=N
  36. else
  37. prompt="y/n"
  38. default=
  39. fi
  40. # Ask the question
  41. read -p "$1 [$prompt] " REPLY
  42. # Default?
  43. if [ -z "$REPLY" ]; then
  44. REPLY=$default
  45. fi
  46. # Check if the reply is valid
  47. case "$REPLY" in
  48. Y*|y*) return 0 ;;
  49. N*|n*) return 1 ;;
  50. esac
  51. done
  52. }
  53. ####################################################### MAIN
  54. clear
  55. echo "This script downloads and installs"
  56. echo "I2S microphone support."
  57. echo
  58. echo "Select Pi Model:"
  59. selectN "Pi 0 or 0W" \
  60. "Pi 2 or 3" \
  61. "Pi 4"
  62. PIMODEL_SELECT=$(($?-1))
  63. ask "Auto load module at boot?"
  64. AUTO_LOAD=$?
  65. echo
  66. echo "Installing..."
  67. # Get needed packages
  68. apt-get -y install git raspberrypi-kernel-headers
  69. # Clone the repo
  70. git clone https://github.com/adafruit/Raspberry-Pi-Installer-Scripts.git
  71. # Build and install the module
  72. cd Raspberry-Pi-Installer-Scripts/i2s_mic_module
  73. make clean
  74. make
  75. make install
  76. # Setup auto load at boot if selected
  77. if [ $AUTO_LOAD = 0 ]; then
  78. cat > /etc/modules-load.d/snd-i2smic-rpi.conf<<EOF
  79. snd-i2smic-rpi
  80. EOF
  81. cat > /etc/modprobe.d/snd-i2smic-rpi.conf<<EOF
  82. options snd-i2smic-rpi rpi_platform_generation=$PIMODEL_SELECT
  83. EOF
  84. fi
  85. # Enable I2S overlay
  86. sed -i -e 's/#dtparam=i2s/dtparam=i2s/g' /boot/config.txt
  87. # Done
  88. echo "DONE."
  89. echo
  90. echo "Settings take effect on next boot."
  91. echo
  92. echo -n "REBOOT NOW? [y/N] "
  93. read
  94. if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
  95. echo "Exiting without reboot."
  96. exit 0
  97. fi
  98. echo "Reboot started..."
  99. reboot
  100. exit 0