install.sh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/bash
  2. if [[ $EUID -ne 0 ]]; then
  3. echo "This script must be run as root (use sudo)" 1>&2
  4. exit 1
  5. fi
  6. is_Raspberry=$(cat /proc/device-tree/model | awk '{print $1}')
  7. if [ "x${is_Raspberry}" != "xRaspberry" ] ; then
  8. echo "Sorry, this drivers only works on raspberry pi"
  9. exit 1
  10. fi
  11. ver="1.0"
  12. # we create a dir with this version to ensure that 'dkms remove' won't delete
  13. # the sources during kernel updates
  14. marker="0.0.0"
  15. apt update
  16. apt-get -y install raspberrypi-kernel-headers raspberrypi-kernel
  17. apt-get -y install dkms git i2c-tools libasound2-plugins
  18. # locate currently installed kernels (may be different to running kernel if
  19. # it's just been updated)
  20. kernels=$(ls /lib/modules | sed "s/^/-k /")
  21. uname_r=$(uname -r)
  22. function install_module {
  23. src=$1
  24. mod=$2
  25. if [[ -d /var/lib/dkms/$mod/$ver/$marker ]]; then
  26. rmdir /var/lib/dkms/$mod/$ver/$marker
  27. fi
  28. if [[ -e /usr/src/$mod-$ver || -e /var/lib/dkms/$mod/$ver ]]; then
  29. dkms remove --force -m $mod -v $ver --all
  30. rm -rf /usr/src/$mod-$ver
  31. fi
  32. mkdir -p /usr/src/$mod-$ver
  33. cp -a $src/* /usr/src/$mod-$ver/
  34. dkms add -m $mod -v $ver
  35. dkms build $uname_r -m $mod -v $ver && dkms install --force $uname_r -m $mod -v $ver
  36. mkdir -p /var/lib/dkms/$mod/$ver/$marker
  37. }
  38. install_module "./" "wm8960-soundcard"
  39. # install dtbos
  40. cp wm8960-soundcard.dtbo /boot/overlays
  41. #set kernel moduels
  42. grep -q "i2c-dev" /etc/modules || \
  43. echo "i2c-dev" >> /etc/modules
  44. grep -q "snd-soc-wm8960" /etc/modules || \
  45. echo "snd-soc-wm8960" >> /etc/modules
  46. grep -q "snd-soc-wm8960-soundcard" /etc/modules || \
  47. echo "snd-soc-wm8960-soundcard" >> /etc/modules
  48. #set dtoverlays
  49. sed -i -e 's:#dtparam=i2c_arm=on:dtparam=i2c_arm=on:g' /boot/config.txt || true
  50. grep -q "dtoverlay=i2s-mmap" /boot/config.txt || \
  51. echo "dtoverlay=i2s-mmap" >> /boot/config.txt
  52. grep -q "dtparam=i2s=on" /boot/config.txt || \
  53. echo "dtparam=i2s=on" >> /boot/config.txt
  54. #grep -q "dtoverlay=wm8960-soundcard" /boot/config.txt || \
  55. # echo "dtoverlay=wm8960-soundcard" >> /boot/config.txt
  56. #install config files
  57. mkdir /etc/wm8960-soundcard || true
  58. cp *.conf /etc/wm8960-soundcard
  59. cp *.state /etc/wm8960-soundcard
  60. #set service
  61. cp wm8960-soundcard /usr/bin/
  62. cp wm8960-soundcard.service /lib/systemd/system/
  63. systemctl enable wm8960-soundcard.service
  64. systemctl start wm8960-soundcard
  65. echo "------------------------------------------------------"
  66. echo "Please reboot your raspberry pi to apply all settings"
  67. echo "Enjoy!"
  68. echo "------------------------------------------------------"