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