Last active
September 22, 2025 20:48
-
-
Save semhoun/926334fcc56fea82d988851c5a6e53ac to your computer and use it in GitHub Desktop.
Pirate Audio / Raspberry Pi 0 W : Full installation
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
| ####################### | |
| ### ==> Global params | |
| ####################### | |
| PRETTY_NAME="Pirate Audio Pi" | |
| SPOTIFY_USER="" | |
| SPOTIFY_PASS="" | |
| HOSTNAME="`echo "$PRETTY_NAME" | awk '{print tolower($0)}' | sed 's/ /-/g'`" | |
| ####################### | |
| ### ==> Raspberry config | |
| ####################### | |
| sudo raspi-config nonint do_hostname "$HOSTNAME" | |
| sudo sudo raspi-config nonint do_memory_split 16 | |
| ####################### | |
| ### ==> Software installation | |
| ####################### | |
| sudo apt-get update | |
| sudo apt-get -y install curl apt-transport-https | |
| wget -q -O - https://apt.mopidy.com/mopidy.gpg | sudo apt-key add - | |
| sudo wget -q -O /etc/apt/sources.list.d/mopidy.list https://apt.mopidy.com/buster.list | |
| sudo wget -q -O /usr/share/keyrings/lesbonscomptes.gpg https://www.lesbonscomptes.com/pages/lesbonscomptes.gpg | |
| sudo wget -q -O /etc/apt/sources.list.d/upmpdcli.list https://www.lesbonscomptes.com/upmpdcli/pages/upmpdcli-rbuster.list | |
| curl -sSL https://dtcooper.github.io/raspotify/key.asc | sudo apt-key add -v - | |
| echo 'deb https://dtcooper.github.io/raspotify raspotify main' | sudo tee /etc/apt/sources.list.d/raspotify.list | |
| sudo apt-get update | |
| sudo apt-get upgrade | |
| sudo apt-get install -y \ | |
| mopidy \ | |
| mopidy-spotify \ | |
| mopidy-tunein \ | |
| mopidy-mpd \ | |
| mopidy-local \ | |
| mopidy-local-sqlite \ | |
| mopidy-alsamixer \ | |
| python3-pip \ | |
| upmpdcli \ | |
| raspotify \ | |
| mpc \ | |
| nginx \ | |
| samba \ | |
| exfat-fuse ntfs-3g \ | |
| usbmount | |
| sudo python3 -m pip install Mopidy-Iris | |
| sudo python3 -m pip install Mopidy-Muse | |
| cd /tmp | |
| wget http://spui.uk/usbmount/usbmount_0.0.24_all.deb | |
| sudo dpkg -i usbmount_0.0.24_all.deb | |
| ####################### | |
| ### ==> Sudo for iris | |
| ####################### | |
| echo "mopidy ALL=NOPASSWD: /usr/local/lib/python3.7/dist-packages/mopidy_iris/system.sh" | sudo tee -a /etc/sudoers.d/010_mopidy-nopasswd | |
| ####################### | |
| ### ==> Fix for audio | |
| ### http://eequalspi.com/index.php/2019/08/25/mopidy-and-multiple-audio-streams-from-the-command-line-on-raspberry-pi/ | |
| ####################### | |
| sudo tee /etc/asound.conf > /dev/null << 'EOF' | |
| pcm.!default { | |
| type plug | |
| slave.pcm "softvol" | |
| } | |
| pcm.softvol { | |
| type softvol | |
| slave { | |
| pcm "dmix" #redirect the output to dmix | |
| } | |
| control { | |
| name "PCM" #override PCM slider to set softvol lvl globally | |
| card 0 | |
| } | |
| } | |
| EOF | |
| ####################### | |
| ### ==> mopidy | |
| ####################### | |
| sudo tee /etc/mopidy/mopidy.conf > /dev/null << 'EOF' | |
| # For information about configuration values that can be set in this file see: | |
| # | |
| # https://docs.mopidy.com/en/latest/config/ | |
| # | |
| # Run `sudo mopidyctl config` to see the current effective config, based on | |
| # both defaults and this configuration file. | |
| [iris] | |
| enabled = true | |
| country = FR | |
| locale = fr_FR | |
| [http] | |
| hostname = 0.0.0.0 | |
| csrf_protection = false | |
| zeroconf = Mopidy HTTP server on PRETTY_NAME | |
| [spotify] | |
| enabled = true | |
| username = SPOTIFY_USER | |
| password = SPOTIFY_PASS | |
| client_id = 4a739cd7-12c5-4504-a872-1a1eeb217c28 | |
| client_secret = 3dXgL5DkeSNlzwAu3U6XayGXGswj9xA1zoEPP-zMrwM= | |
| bitrate = 320 | |
| [mpd] | |
| hostname = 0.0.0.0 | |
| [file] | |
| media_dirs = | |
| /var/lib/mopidy/media|Local Music | |
| /media|USB Drive | |
| metadata_timeout = 5000 | |
| [audio] | |
| mixer_volume = 40 | |
| mixer = alsamixer | |
| output = alsasink device=plug:softvol | |
| [alsamixer] | |
| card = 0 | |
| control = PCM | |
| [raspberry-gpio] | |
| enabled = true | |
| bcm5 = play_pause,active_low,250 | |
| bcm6 = volume_down,active_low,250 | |
| bcm16 = next,active_low,250 | |
| bcm20 = volume_up,active_low,250 | |
| bcm24 = volume_up,active_low,250 | |
| [local] | |
| scan_timeout = 5000 | |
| scan_flush_threshold = 10 | |
| [m3u] | |
| playlists_dir = /var/lib/mopidy/m3u | |
| [pidi] | |
| enabled = true | |
| display = st7789 | |
| EOF | |
| sudo sed \ | |
| -e "s/SPOTIFY_USER/${SPOTIFY_USER}/" \ | |
| -e "s/SPOTIFY_PASS/${SPOTIFY_PASS}/" \ | |
| -e "s/PRETTY_NAME/${PRETTY_NAME}/" \ | |
| -i /etc/mopidy/mopidy.conf | |
| ####################### | |
| ### ==> Raspotify | |
| ####################### | |
| sudo tee /etc/default/raspotify > /dev/null << 'EOF' | |
| # /etc/default/raspotify -- Arguments/configuration for librespot | |
| # Device name on Spotify Connect | |
| DEVICE_NAME="PRETTY_NAME" | |
| # Bitrate, one of 96 (low quality), 160 (default quality), or 320 (high quality) | |
| BITRATE="320" | |
| # Additional command line arguments for librespot can be set below. | |
| # See `librespot -h` for more info. Make sure whatever arguments you specify | |
| # aren't already covered by other variables in this file. (See the daemon's | |
| # config at `/lib/systemd/system/raspotify.service` for more technical details.) | |
| # | |
| # To make your device visible on Spotify Connect across the Internet add your | |
| # username and password which can be set via "Set device password", on your | |
| # account settings, use `--username` and `--password`. | |
| # | |
| # To choose a different output device (ie a USB audio dongle or HDMI audio out), | |
| # use `--device` with something like `--device hw:0,1`. Your mileage may vary. | |
| # | |
| #OPTIONS="--username <USERNAME> --password <PASSWORD>" | |
| OPTIONS="--onevent /opt/raspotify.sh --mixer alsa -- device plug:softvol" | |
| # Uncomment to use a cache for downloaded audio files. Cache is disabled by | |
| # default. It's best to leave this as-is if you want to use it, since | |
| # permissions are properly set on the directory `/var/cache/raspotify'. | |
| #CACHE_ARGS="--cache /var/cache/raspotify" | |
| # By default, the volume normalization is enabled, add alternative volume | |
| # arguments here if you'd like, but these should be fine. | |
| #VOLUME_ARGS="--enable-volume-normalisation --linear-volume --initial-volume=100" | |
| # Backend could be set to pipe here, but it's for very advanced use cases of | |
| # librespot, so you shouldn't need to change this under normal circumstances. | |
| #BACKEND_ARGS="--backend alsa" | |
| # The displayed device type in Spotify clients. | |
| # Can be "unknown", "computer", "tablet", "smartphone", "speaker", "tv", | |
| # "avr" (Audio/Video Receiver), "stb" (Set-Top Box), and "audiodongle". | |
| DEVICE_TYPE="speaker" | |
| EOF | |
| sudo sed \ | |
| -e "s/PRETTY_NAME/${PRETTY_NAME}/" \ | |
| -e "s/SPOTIFY_USER/${SPOTIFY_USER}/" \ | |
| -e "s/SPOTIFY_PASS/${SPOTIFY_PASS}/" \ | |
| -i /etc/default/raspotify | |
| sudo tee /opt/raspotify.sh > /dev/null << 'EOF' | |
| #!/bin/bash | |
| # https://github.com/pimoroni/pirate-audio/issues/17 | |
| if [ "$PLAYER_EVENT" = "start" ]; then | |
| mpc clear | |
| mpc add spotify:track:$TRACK_ID | |
| mpc play | |
| sleep 1 | |
| mpc pause | |
| elif [ "$PLAYER_EVENT" = "change" ]; then | |
| mpc clear | |
| mpc add spotify:track:$TRACK_ID | |
| mpc play | |
| sleep 1 | |
| mpc pause | |
| elif [ "$PLAYER_EVENT" = "stop" ]; then | |
| # mpc play | |
| mpc clear | |
| elif [ "$PLAYER_EVENT" = "volume_set" ]; then | |
| mpc_volume=$(($VOLUME * 100 / 65536)) | |
| mpc volume $mpc_volume | |
| fi | |
| EOF | |
| sudo chmod 755 /opt/raspotify.sh | |
| ####################### | |
| ### ==> Upmpd | |
| ####################### | |
| sudo tee /etc/systemd/system/upmpdcli.service > /dev/null << 'EOF' | |
| [Unit] | |
| Description=UPnP Renderer front-end to MPD | |
| After=network.target mpd.service | |
| [Service] | |
| Type=simple | |
| # Add wait otherwise bug CPU usage at start and GPIO problem | |
| ExecStartPre=/bin/sleep 90 | |
| # Note: if start fails check with "systemctl status upmpdcli" | |
| ExecStart=/usr/bin/upmpdcli -c /etc/upmpdcli.conf | |
| # For some reason, the first start of libupnp fails. Probably this should | |
| # be started later in the start sequence, but I don't know how. Retry a bit | |
| # later. | |
| Restart=always | |
| RestartSec=1min | |
| [Install] | |
| WantedBy=multi-user.target | |
| EOF | |
| sudo sed \ | |
| -e "s/#friendlyname.*/friendlyname = ${PRETTY_NAME}/" \ | |
| -i /etc/upmpdcli.conf | |
| ####################### | |
| ### ==> Samba | |
| ####################### | |
| sudo tee /etc/samba/smb.conf > /dev/null << 'EOF' | |
| [global] | |
| # Disable printer lookups | |
| load printers = No | |
| printing = bsd | |
| printcap name = /dev/null | |
| disable spoolss = Yes | |
| ## Browsing/Identification ### | |
| # Change this to the workgroup/NT-domain name your Samba server will part of | |
| workgroup = DUNE | |
| # server string is the equivalent of the NT Description field | |
| netbios name = HOSTNAME.local | |
| server string = PRETTY_NAME | |
| # Windows Internet Name Serving Support Section: | |
| # WINS Support - Tells the NMBD component of Samba to enable its WINS Server | |
| wins support = no | |
| # This will prevent nmbd to search for NetBIOS names through DNS. | |
| dns proxy = no | |
| #### Networking #### | |
| hostname lookups = yes | |
| name resolve order = bcast lmhosts host wins | |
| #### Debugging/Accounting #### | |
| # This tells Samba to use a separate log file for each machine | |
| # that connects | |
| log file = /var/log/samba/log.%m | |
| # Cap the size of the individual log files (in KiB). | |
| max log size = 100 | |
| security = user | |
| map to guest = bad user | |
| guest account = mopidy | |
| restrict anonymous = no | |
| follow symlinks = yes | |
| [Music] | |
| path = /var/lib/mopidy/media | |
| comment = Directory for music files | |
| writable = yes | |
| browseable = yes | |
| guest only = yes | |
| create mask = 0666 | |
| directory mask = 0777 | |
| EOF | |
| sudo sed \ | |
| -e "s/PRETTY_NAME/${PRETTY_NAME}/" \ | |
| -e "s/HOSTNAME/${HOSTNAME}/" \ | |
| -i /etc/samba/smb.conf | |
| ####################### | |
| ### ==> nginx port 80 | |
| ####################### | |
| sudo tee /etc/nginx/sites-enabled/default > /dev/null << 'EOF' | |
| server { | |
| listen 80; ## listen for ipv4; this line is default and implied | |
| #listen [::]:80 default_server ipv6only=on; ## listen for ipv6 | |
| root /usr/share/nginx/www; | |
| index index.html index.htm; | |
| # Make site accessible from http://localhost/ | |
| server_name localhost; | |
| location / { | |
| # First attempt to serve request as file, then | |
| # as directory, then fall back to displaying a 404. | |
| # try_files $uri $uri/ /index.html; | |
| # Uncomment to enable naxsi on this location | |
| # include /etc/nginx/naxsi.rules | |
| proxy_pass http://localhost:6680; | |
| proxy_http_version 1.1; | |
| proxy_set_header Upgrade $http_upgrade; | |
| proxy_set_header Connection "upgrade"; | |
| } | |
| } | |
| EOF | |
| ####################### | |
| ### ==> usbmount | |
| ####################### | |
| sudo tee /etc/usbmount/usbmount.conf > /dev/null << 'EOF' | |
| # Configuration file for the usbmount package, which mounts removable | |
| # storage devices when they are plugged in and unmounts them when they | |
| # are removed. | |
| # Change to zero to disable usbmount | |
| ENABLED=1 | |
| # Mountpoints: These directories are eligible as mointpoints for | |
| # removable storage devices. A newly plugged in device is mounted on | |
| # the first directory in this list that exists and on which nothing is | |
| # mounted yet. | |
| MOUNTPOINTS="/media/USB1 /media/USB2 /media/USB3 /media/USB4" | |
| # Filesystem types: removable storage devices are only mounted if they | |
| # contain a filesystem type which is in this list. | |
| FILESYSTEMS="vfat ext2 ext3 ext4 hfsplus fuseblk exfat ntfs" | |
| ############################################################################# | |
| # WARNING! # | |
| # # | |
| # The "sync" option may not be a good choice to use with flash drives, as # | |
| # it forces a greater amount of writing operating on the drive. This makes # | |
| # the writing speed considerably lower and also leads to a faster wear out # | |
| # of the disk. # | |
| # # | |
| # If you omit it, don't forget to use the command "sync" to synchronize the # | |
| # data on your disk before removing the drive or you may experience data # | |
| # loss. # | |
| # # | |
| # It is highly recommended that you use the pumount command (as a regular # | |
| # user) before unplugging the device. It makes calling the "sync" command # | |
| # and mounting with the sync option unnecessary---this is similar to other # | |
| # operating system's "safely disconnect the device" option. # | |
| ############################################################################# | |
| # Mount options: Options passed to the mount command with the -o flag. | |
| # See the warning above regarding removing "sync" from the options. | |
| MOUNTOPTIONS="ro,noexec,nodev,noatime,nodiratime" | |
| # Filesystem type specific mount options: This variable contains a space | |
| # separated list of strings, each which the form "-fstype=TYPE,OPTIONS". | |
| # | |
| # If a filesystem with a type listed here is mounted, the corresponding | |
| # options are appended to those specificed in the MOUNTOPTIONS variable. | |
| # | |
| # For example, "-fstype=vfat,gid=floppy,dmask=0007,fmask=0117" would add | |
| # the options "gid=floppy,dmask=0007,fmask=0117" when a vfat filesystem | |
| # is mounted. | |
| FS_MOUNTOPTIONS="" | |
| # If set to "yes", more information will be logged via the syslog | |
| # facility. | |
| VERBOSE=no | |
| EOF | |
| sudo rm -rf /media/usb* | |
| sudo mkdir -p /media/USB1 /media/USB2 /media/USB3 /media/USB4 | |
| ####################### | |
| ### ==> Pirate Audio | |
| ####################### | |
| sudo apt-get install -y python3-rpi.gpio python3-spidev python3-pil python3-numpy | |
| sudo pip3 install Mopidy-PiDi pidi-display-pil pidi-display-st7789 mopidy-raspberry-gpio | |
| sudo usermod -a -G spi,i2c,gpio,video mopidy | |
| sudo tee -a /boot/config.txt > /dev/null << 'EOF' | |
| dtparam=spi=on | |
| dtoverlay=hifiberry-dac | |
| gpio=25=op,dh | |
| gpio=5,6,16,20,24=ip,pu | |
| EOF | |
| ####################### | |
| ### ==> Enable services | |
| ####################### | |
| sudo systemctl enable nginx | |
| sudo systemctl enable mopidy | |
| sudo systemctl enable upmpdcli | |
| sudo systemctl enable raspotify | |
| ####################### | |
| ### ==> Restart services | |
| ####################### | |
| sudo service mopidy restart | |
| sudo service upmpdcli restart | |
| sudo service raspotify restart | |
| sudo service nginx restart | |
| sudo service smbd restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment