Last active
May 19, 2022 10:37
-
-
Save Tobiaqs/62cbb28cf64836ba7681da35b1fe50ef to your computer and use it in GitHub Desktop.
Script that can transform a mint raspbian installation into a media center with external I2S DAC that runs Kodi and can play audio over the network and bluetooth via pulseaudio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# this script sets up a mint raspbian installation as follows: | |
# - all packages updated | |
# - my public ssh key is authorized | |
# - onboard bluetooth disabled | |
# - onboard analog audio disabled | |
# - PCM5102a DAC as audio output | |
# - network audio relay through pulseaudio with zeroconf support | |
# - bluetooth audio relay through pulseaudio | |
# - kodi media center with inputstream.adaptive plugin that starts up on boot | |
# - hostname of the installation set to $NEW_HOSTNAME | |
if [ "$EUID" -ne 0 ]; then | |
echo "Run as root pal" | |
exit | |
fi | |
NEW_HOSTNAME=woolbird | |
# disable onboard audio | |
sed -i 's/# Enable audio (loads snd_bcm2835)//' /boot/config.txt | |
sed -i 's/dtparam=audio=on//' /boot/config.txt | |
# disable onboard bt | |
echo "dtoverlay=pi3-disable-bt" >> /boot/config.txt | |
# enable I2S dac | |
echo "dtoverlay=hifiberry-dac" >> /boot/config.txt | |
# install public ssh key | |
mkdir /home/pi/.ssh | |
echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDFObzc4AM01Qmz4ULOsqm7UCSqh6XInbjSakiva56Otox+0Hni8blwYh28NIUGUeb1SSeyvU3iX/SVjqBZlmrMrklgx/ITnEo1e+kJrL7jhqxDHG3lssw5p60iMss/qFEkScbkNisPS0xERC8tlhmo6aul+EQfyEZIEnd7Uf9Njfz56zuyntrEKl9MUZTdks2ZlylAqaalEB+VJmtpcs2mFUtpE/QDiIjl08hpLuZW9y6bae4YWW5U7n3XBDwBOb1Vax1X+pLr7kwrZAaquwThO6cde6USEm5YfTVokNS9W8k+37UL4LBeATkwAFwjyfIGqEyFnyTxnK/K8yGIHiXP me@LTT" > /home/pi/.ssh/authorized_keys | |
# set permissions | |
chown -R pi:pi /home/pi/.ssh | |
# get system up to date | |
apt-get -y update | |
apt-get -y upgrade | |
# install packages | |
apt-get -y install kodi kodi-inputstream-adaptive pulseaudio pulseaudio-module-bluetooth pulseaudio-module-zeroconf | |
# install the proper bluetooth.conf | |
wget -O /etc/dbus-1/system.d/bluetooth.conf https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/src/bluetooth.conf?id=8eb993e983013e8a12145d4a1eefbde45de9d421 | |
# configure pulseaudio for network audio | |
echo "" >> /etc/pulse/system.pa | |
echo "load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;192.168.178.0/24 auth-anonymous=1 auth-cookie-enabled=0" >> /etc/pulse/system.pa | |
# configure pulseaudio for bluetooth audio | |
echo "" >> /etc/pulse/system.pa | |
echo "load-module module-bluetooth-policy" >> /etc/pulse/system.pa | |
echo "load-module module-bluetooth-discover" >> /etc/pulse/system.pa | |
# further configure pulseaudio for network audio (this needs to go at the end of the file, because of https://gist.github.com/Tobiaqs/0ef7bd2e56160650264f9b77de2db50f#segmentation-fault-on-armv6-or-dbus-related-error) | |
echo "" >> /etc/pulse/system.pa | |
echo "load-module module-zeroconf-publish" >> /etc/pulse/system.pa | |
# install pulseaudio service | |
cat <<EOF > /etc/systemd/system/pulseaudio.service | |
[Unit] | |
Description=PulseAudio Daemon | |
After=bluetooth.service | |
[Install] | |
WantedBy=multi-user.target | |
[Service] | |
Type=simple | |
PrivateTmp=true | |
ExecStart=/usr/bin/pulseaudio --system --realtime --disallow-exit --no-cpu-limit --disable-shm | |
EOF | |
# install pulseaudio service | |
systemctl daemon-reload | |
systemctl enable pulseaudio | |
# fix bluetoothd problem with avrcp plugin | |
sed -i 's/\/bluetoothd/\/bluetoothd --noplugin=avrcp/' /lib/systemd/system/bluetooth.service | |
# restart bluetoothd | |
systemctl daemon-reload | |
systemctl restart bluetooth | |
# set hostname | |
echo $NEW_HOSTNAME > /etc/hostname | |
sed -i "s/127.0.1.1.*raspberrypi/127.0.1.1\t$NEW_HOSTNAME/g" /etc/hosts | |
# allow user pi to play stuff over pulseaudio (necessary for the "play through pulseaudio" option to appear in kodi) | |
usermod -aG pulse-access pi | |
# make kodi boot up automatically | |
sed -i 's/exit 0//' /etc/rc.local | |
echo "sudo -H -u pi kodi-standalone &" >> /etc/rc.local | |
echo "exit 0" >> /etc/rc.local | |
reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment