Skip to content

Instantly share code, notes, and snippets.

@Tobiaqs
Last active June 12, 2020 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tobiaqs/547e152a0aecad0db28c96dad5626a96 to your computer and use it in GitHub Desktop.
Save Tobiaqs/547e152a0aecad0db28c96dad5626a96 to your computer and use it in GitHub Desktop.
Script that can transform a mint Raspberry Pi OS / Raspbian installation into a Bluetooth audio receiver
#!/bin/bash
# this script sets up a mint raspbian installation as follows:
# - all packages updated
# - my public ssh key is authorized
# - bluetooth audio relay through pulseaudio
# - hostname of the installation set to $NEW_HOSTNAME
#
# tested on Raspberry Pi OS on June 13, 2020
# note: you need to connect to your device with bluetoothctl, if you want the opposite to be possible, trust your device.
if [ "$EUID" -ne 0 ]; then
echo "Run as root pal"
exit
fi
NEW_HOSTNAME=woolbirdlite
# 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 pulseaudio pulseaudio-module-bluetooth
# 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 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
# 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, so kind of irrelevant for this script but meh, doesn't hurt)
usermod -aG pulse-access pi
# set output volume of analog output to 100%
amixer -c0 set Headphone 100%
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment