seeed-voicecard/install.sh

111 lines
3.3 KiB
Bash
Raw Normal View History

2017-05-22 12:20:29 +02:00
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root (use sudo)" 1>&2
exit 1
fi
2017-09-14 12:39:38 +02:00
is_Raspberry=$(cat /proc/device-tree/model | awk '{print $1}')
if [ "x${is_Raspberry}" != "xRaspberry" ] ; then
echo "Sorry, this drivers only works on raspberry pi"
exit 1
fi
2017-09-14 10:29:26 +02:00
ver="0.2"
2017-09-14 11:26:04 +02:00
card=$1
if [ "x${card}" = "x" ] ; then
echo "Usage: ./install 2mic|4mic"
exit 1
fi
2017-05-22 12:20:29 +02:00
# we create a dir with this version to ensure that 'dkms remove' won't delete
# the sources during kernel updates
marker="0.0.0"
apt update
apt-get -y install raspberrypi-kernel-headers raspberrypi-kernel
apt-get -y install dkms
# locate currently installed kernels (may be different to running kernel if
# it's just been updated)
2017-08-11 03:21:56 +02:00
kernels=$(ls /lib/modules | sed "s/^/-k /")
2017-09-14 11:26:04 +02:00
uname_r=$(uname -r)
2017-05-22 12:20:29 +02:00
function install_module {
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 -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
2017-08-11 03:21:56 +02:00
dkms build $kernels -m $mod -v $ver && dkms install $kernels -m $mod -v $ver
2017-05-22 12:20:29 +02:00
mkdir -p /var/lib/dkms/$mod/$ver/$marker
}
2017-09-22 12:12:17 +02:00
if [ ! -f "/boot/overlays/seeed-4mic-voicecard.dtbo" ] && [ ! -f "/lib/modules/${uname_r}/kernel/sound/soc/codecs/snd-soc-ac108.ko" ] ; then
2017-09-14 11:26:04 +02:00
install_module "./" "seeed-voicecard"
2017-09-14 10:29:26 +02:00
cp seeed-2mic-voicecard.dtbo /boot/overlays
cp seeed-4mic-voicecard.dtbo /boot/overlays
install -D ac108_plugin/libasound_module_pcm_ac108.so /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_ac108.so
2017-09-14 11:26:04 +02:00
else
echo "card driver already installed"
fi
2017-05-22 12:20:29 +02:00
2017-09-14 11:26:04 +02:00
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
2017-09-14 10:29:26 +02:00
2017-05-22 12:20:29 +02:00
grep -q "dtoverlay=i2s-mmap" /boot/config.txt || \
echo "dtoverlay=i2s-mmap" >> /boot/config.txt
2017-09-14 10:29:26 +02:00
2017-05-22 12:20:29 +02:00
grep -q "dtparam=i2s=on" /boot/config.txt || \
echo "dtparam=i2s=on" >> /boot/config.txt
2017-09-14 12:39:38 +02:00
has_2mic=$(grep seeed-2mic-voicecard /boot/config.txt)
2017-09-15 04:01:53 +02:00
has_4mic=$(grep seeed-4mic-voicecard /boot/config.txt)
2017-09-14 11:26:04 +02:00
case "${card}" in
"2mic")
2017-09-14 14:14:10 +02:00
echo "cp wm8960_asound.state /var/lib/alsa/asound.state"
2017-09-14 11:26:04 +02:00
cp wm8960_asound.state /var/lib/alsa/asound.state
cp asound_2mic.conf /etc/asound.conf
2017-09-14 12:39:38 +02:00
if [ "x${has_4mic}" != x ] ; then
2017-09-14 14:14:10 +02:00
echo "has 4mic before, now remove it"
2017-09-14 14:03:17 +02:00
sed -i "s/dtoverlay=seeed-4mic-voicecard//g" /boot/config.txt
2017-09-14 12:39:38 +02:00
fi
2017-09-14 14:03:17 +02:00
grep -q "dtoverlay=seeed-2mic-voicecard" /boot/config.txt || \
echo "dtoverlay=seeed-2mic-voicecard" >> /boot/config.txt
2017-09-14 12:39:38 +02:00
2017-09-14 11:26:04 +02:00
;;
"4mic")
2017-09-14 14:14:10 +02:00
echo "cp ac108_asound.state /var/lib/alsa/asound.state"
2017-09-14 11:26:04 +02:00
cp ac108_asound.state /var/lib/alsa/asound.state
cp asound_4mic.conf /etc/asound.conf
2017-09-14 12:39:38 +02:00
if [ "x${has_2mic}" != x ] ; then
2017-09-14 14:14:10 +02:00
echo "has 2mic before, now remove it"
2017-09-14 14:03:17 +02:00
sed -i "s/dtoverlay=seeed-2mic-voicecard//g" /boot/config.txt
2017-09-14 12:39:38 +02:00
fi
2017-09-14 14:03:17 +02:00
grep -q "dtoverlay=seeed-4mic-voicecard" /boot/config.txt || \
echo "dtoverlay=seeed-4mic-voicecard" >> /boot/config.txt
2017-09-14 11:26:04 +02:00
;;
*)
echo "Please use 2mic or 4mic"
;;
esac
2017-05-22 12:20:29 +02:00
echo "------------------------------------------------------"
echo "Please reboot your raspberry pi to apply all settings"
echo "Enjoy!"
echo "------------------------------------------------------"