#!/bin/sh
sudo apt-get update
sudo apt-get install -y python3-pip libasound2-dev libxslt1-dev libxml2-dev zlib1g-dev python3-lxml python-lxml libxml2-dev libxslt-dev python-dev
sudo pip3 install --upgrade hifiberrydsp

for i in sigmatcp; do
 sudo systemctl stop $i
 sudo systemctl disable $i
done

sudo mkdir -p /var/lib/hifiberry

LOC=`which dsptoolkit`
sudo mkdir ~/.dsptoolkit

# Create systemd config for the TCP server
LOC=`which sigmatcpserver`

cat <<EOT >/tmp/sigmatcp.service
[Unit]
Description=SigmaTCP Server for HiFiBerry DSP
Wants=network-online.target
After=network.target network-online.target
[Service]
Type=simple
ExecStart=$LOC --alsa
StandardOutput=journal
[Install]
WantedBy=multi-user.target
EOT

sudo mv /tmp/sigmatcp.service /lib/systemd/system/sigmatcp.service

sudo systemctl daemon-reload

for i in sigmatcp; do
 sudo systemctl start $i
 sudo systemctl enable $i
done

cat /boot/config.txt | grep -v "dtparam=spi" >> /tmp/config.txt
echo "dtparam=spi=on" >> /tmp/config.txt
sudo mv /tmp/config.txt /boot/config.txt
