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.

i2smic.sh 2.8KB

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