seeed-voicecard/install.sh

117 lines
3.4 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
ver="0.3"
uname_r=$(uname -r)
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"
2019-01-26 15:19:45 +01:00
# update and install required packages
which apt &>/dev/null
if [[ $? -eq 0 ]]; then
apt update -y
apt-get -y install raspberrypi-kernel-headers raspberrypi-kernel
apt-get -y install dkms git i2c-tools libasound2-plugins
fi
# Arch Linux
which pacman &>/dev/null
if [[ $? -eq 0 ]]; then
pacman -Syu --needed git gcc automake make dkms linux-raspberrypi-headers i2c-tools
fi
2017-05-22 12:20:29 +02:00
# 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-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
2018-02-10 09:57:30 +01:00
dkms remove --force -m $mod -v $ver --all
2017-05-22 12:20:29 +02:00
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
2018-02-10 09:57:30 +01:00
dkms build $kernels -m $mod -v $ver && dkms install --force $kernels -m $mod -v $ver
2017-05-22 12:20:29 +02:00
mkdir -p /var/lib/dkms/$mod/$ver/$marker
}
install_module "./" "seeed-voicecard"
# install dtbos
cp seeed-2mic-voicecard.dtbo /boot/overlays
cp seeed-4mic-voicecard.dtbo /boot/overlays
2018-02-10 09:57:30 +01:00
cp seeed-8mic-voicecard.dtbo /boot/overlays
#install alsa plugins
2018-02-10 09:57:30 +01:00
# 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 moduels
2019-01-26 15:01:46 +01:00
grep -q "^snd-soc-seeed-voicecard$" /etc/modules || \
echo "snd-soc-seeed-voicecard" >> /etc/modules
2019-01-26 15:01:46 +01:00
grep -q "^snd-soc-ac108$" /etc/modules || \
2017-09-14 11:26:04 +02:00
echo "snd-soc-ac108" >> /etc/modules
2019-01-26 15:01:46 +01:00
grep -q "^snd-soc-wm8960$" /etc/modules || \
2017-09-14 11:26:04 +02:00
echo "snd-soc-wm8960" >> /etc/modules
2017-09-14 10:29:26 +02:00
#set dtoverlays
sed -i -e 's:#dtparam=i2c_arm=on:dtparam=i2c_arm=on:g' /boot/config.txt || true
2019-01-26 15:01:46 +01:00
grep -q "^dtoverlay=i2s-mmap$" /boot/config.txt || \
2017-05-22 12:20:29 +02:00
echo "dtoverlay=i2s-mmap" >> /boot/config.txt
2017-09-14 10:29:26 +02:00
2019-01-26 15:01:46 +01:00
grep -q "^dtparam=i2s=on$" /boot/config.txt || \
2017-05-22 12:20:29 +02:00
echo "dtparam=i2s=on" >> /boot/config.txt
#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 "respeaker@seeed.cc"
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"
cp seeed-voicecard /usr/bin/
cp seeed-voicecard.service /lib/systemd/system/
systemctl enable seeed-voicecard.service
2017-09-14 11:26:04 +02:00
2017-05-22 12:20:29 +02:00
echo "------------------------------------------------------"
echo "Please reboot your raspberry pi to apply all settings"
echo "Enjoy!"
echo "------------------------------------------------------"