forked from respeaker/seeed-voicecard
-
Notifications
You must be signed in to change notification settings - Fork 2
/
install_arm64.sh
executable file
·233 lines (192 loc) · 6.58 KB
/
install_arm64.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/bin/bash
# Color
RED='\033[0;31m'
NC='\033[0m' # No Color
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root (use sudo)" 1>&2
exit 1
fi
# Check for enough space on / volume
boot_line=$(df -h | grep / | head -n 1)
if [ "x${boot_line}" = "x" ]; then
echo "Warning: /boot volume not found .."
else
boot_space=$(echo $boot_line | awk '{print $4;}')
free_space=$(echo "${boot_space%?}")
unit="${boot_space: -1}"
if [[ "$unit" = "K" ]]; then
echo "Error: Not enough space left ($boot_space) on /boot"
exit 1
elif [[ "$unit" = "M" ]]; then
if [ "$free_space" -lt "25" ]; then
echo "Error: Not enough space left ($boot_space) on /boot"
exit 1
fi
fi
fi
#
# make sure that we are on something Armbian/RockPi related
# Armbian/RockPi stuff available
# - check for /boot/overlay-user
# - dtparam and dtoverlay is available
errorFound=0
OVERLAYS=/boot/overlay-user
[ -d /boot/firmware/overlays ] && OVERLAYS=/boot/firmware/overlays
if [ ! -d $OVERLAYS ] ; then
echo "$OVERLAYS not found or not a directory" 1>&2
errorFound=1
fi
# should we also check for alsactl and amixer used in seeed-voicecard?
PATH=$PATH:/opt/vc/bin
for cmd in alsactl amixer ; do
if ! which $cmd &>/dev/null ; then
echo "$cmd not found" 1>&2
echo "You may need to run ./ubuntu-prerequisite.sh"
errorFound=1
fi
done
if [ $errorFound = 1 ] ; then
echo "Errors found, exiting." 1>&2
exit 1
fi
ver="0.3"
uname_r=$(uname -r)
# we create a dir with this version to ensure that 'dkms remove' won't delete
# the sources during kernel updates
marker="0.0.0"
COMPAT_KERNEL_VER="5.10.43"
COMPAT_PACKAGE_VER="21.05.4"
_VER_RUN=
function get_kernel_version() {
local ZIMAGE IMG_OFFSET
_VER_RUN=`uname -r`
echo "$_VER_RUN"
return 0
}
function check_kernel_headers() {
VER_RUN=$(get_kernel_version)
VER_HDR=$(dpkg -L linux-headers-current-rockchip64 | egrep -m1 "/lib/modules/[[:print:]]+/build" | awk -F'/' '{ print $4; }')
echo $VER_RUN
echo $VER_HDR
[ "X$VER_RUN" == "X$VER_HDR" ] && {
return 0
}
# Only compatible with kernel version
[ "X$VER_RuN" == "X${COMPAT_KERNEL_VER}"] && {
return 0
}
apt-get -y --reinstall install linux-headers-current-rockchip64=$(COMPAT_PACKAGE_VER) linux-image-current-rockchip64=$(COMPAT_PACKAGE_VER)
echo 'Please reboot to load new kernel and re-run this script'
}
# update and install required packages
which apt &>/dev/null
if [[ $? -eq 0 ]]; then
# apt update -y
# Armbian RockPi kernel packages
apt-get -y install linux-headers-current-rockchip64=21.05.4 linux-image-current-rockchip64=21.05.4
apt-get -y install dkms git i2c-tools libasound2-plugins
# update checker
check_kernel_headers
fi
# Arch Linux
which pacman &>/dev/null
if [[ $? -eq 0 ]]; then
pacman -Syu --needed git gcc automake make dkms linux-headers-current-rockchip64 i2c-tools
fi
# locate currently installed kernels (may be different to running kernel if
# it's just been updated)
base_ver=$(get_kernel_version)
base_ver=${base_ver%%[-+]*}
#kernels="${base_ver}+ ${base_ver}-v7+ ${base_ver}-v7l+"
kernels=$(uname -r)
kernel_base_ver=${kernels%%[-+]*}
if [[ "$base_ver" != "$kernel_base_ver" ]] ; then
echo "------------------------------------------------------"
echo -e " ${RED}WARNING${NC} Your loaded kernel version is $kernel_base_ver"
echo " Not matching the updated version $base_ver."
echo " Kernel was updated, but new kernel was not loaded yet"
echo -e " Please ${RED}reboot${NC} your machine AND THEN run this script ${RED}again"
exit 1;
fi
function install_module {
local _i
src=$1
mod=$2
if [[ -d /var/lib/dkms/$mod/$ver/$marker ]]; then
rmdir /var/lib/dkms/$mod/$ver/$marker
fi
if [[ -e /usr/src/$mod-$ver || -e /var/lib/dkms/$mod/$ver ]]; then
dkms remove --force -m $mod -v $ver --all
rm -rf /usr/src/$mod-$ver
fi
mkdir -p /usr/src/$mod-$ver
cp -a $src/* /usr/src/$mod-$ver/
dkms add -m $mod -v $ver
for _i in $kernels; do
dkms build -k $_i -m $mod -v $ver && {
dkms install --force -k $_i -m $mod -v $ver
}
done
mkdir -p /var/lib/dkms/$mod/$ver/$marker
}
install_module "./" "seeed-voicecard"
# install dts overlays
armbian-add-overlay seeed-2mic-voicecard-overlay.dts
# armbian-add-overlay seeed-4mic-voicecard-overlay.dts
# armbian-add-overlay seeed-8mic-voicecard-overlay.dts
#install alsa plugins
# no need this plugin now
# install -D ac108_plugin/libasound_module_pcm_ac108.so /usr/lib/arm-linux-gnueabihf/alsa-lib/
rm -f /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_ac108.so
#set kernel modules
grep -q "^snd-soc-seeed-voicecard$" /etc/modules || \
echo "snd-soc-seeed-voicecard" >> /etc/modules
grep -q "^snd-soc-ac108$" /etc/modules || \
echo "snd-soc-ac108" >> /etc/modules
grep -q "^snd-soc-wm8960$" /etc/modules || \
echo "snd-soc-wm8960" >> /etc/modules
#set dtoverlays
CONFIG=/boot/armbianEnv.txt
[ -f /boot/firmware/usercfg.txt ] && CONFIG=/boot/firmware/usercfg.txt
# check that i2c7 is enabled
I2C7=`sed -rn 's/^.*overlays=.*(i2c7).*$/\1/p' $CONFIG`
if [[ -z $I2C7 ]]; then
echo 'i2c7 is not enabled. You may need to enable this in armbian-config?'
exit 1
fi
sed -i -e 's:#dtparam=i2c_arm=on:dtparam=i2c_arm=on:g' $CONFIG || true
grep -q "^dtoverlay=i2s-mmap$" $CONFIG || \
echo "dtoverlay=i2s-mmap" >> $CONFIG
grep -q "^dtparam=i2s=on$" $CONFIG || \
echo "dtparam=i2s=on" >> $CONFIG
grep -q "^param_spidev_spi_bus=1$" $CONFIG || \
echo "param_spidev_spi_bus=1" >> $CONFIG
grep -q "^param_spidev_spi_bus=1$" $CONFIG || \
echo "param_spidev_spi_bus=1" >> $CONFIG
#install config files
mkdir /etc/voicecard || true
cp *.conf /etc/voicecard
cp *.state /etc/voicecard
#create git repo
git_email=$(git config --global --get user.email)
git_name=$(git config --global --get user.name)
if [ "x${git_email}" == "x" ] || [ "x${git_name}" == "x" ] ; then
echo "setup git config"
git config --global user.email "[email protected]"
git config --global user.name "respeaker"
fi
echo "git init"
git --git-dir=/etc/voicecard/.git init
echo "git add --all"
git --git-dir=/etc/voicecard/.git --work-tree=/etc/voicecard/ add --all
echo "git commit -m \"origin configures\""
git --git-dir=/etc/voicecard/.git --work-tree=/etc/voicecard/ commit -m "origin configures"
# We don't want a service updating this every time
# cp seeed-voicecard /usr/bin/
# cp seeed-voicecard.service /lib/systemd/system/
# systemctl enable seeed-voicecard.service
# systemctl start seeed-voicecard
echo "------------------------------------------------------"
echo "Please reboot your Rock Pi to apply all settings"
echo "Enjoy!"
echo "------------------------------------------------------"