#! /bin/bash

TEMP_DIR=$(mktemp -d)
PUBLIC_URL="https://public.gardna.net"

# Apt packages
sudo add-apt-repository ppa:obsproject/obs-studio -y
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install -y curl cifs-utils ffmpeg obs-studio vlc unzip alien git dbus-x11 remmina remmina-plugin-vnc
sudo apt-get remove -y unattended-upgrades
yes | sudo DEBIAN_FRONTEND=noninteractive apt-get install -yqq jackd qjackctl

# Install WiFi drivers
sudo git clone https://github.com/morrownr/8821au-20210708.git /opt/8821au
cd /opt/8821au
yes n | sudo ./install-driver.sh
cd -

# Install ZeroTier
# curl -s https://install.zerotier.com | sudo bash
# sudo zerotier-cli join 8bd5124fd62ef069

# Install MagicQ
MQ_VERSION="beta"
MQ_PLATFORM="linux64"
MQ_URL=$(curl -Ls -o /dev/null -w %{url_effective} "https://secure.chamsys.co.uk/bugtracker/mc_software_download.php?software=magicq&platform=$MQ_PLATFORM&version=$MQ_VERSION&email=william%40madebycounter.com")

wget $MQ_URL -O $TEMP_DIR/magicq.deb
sudo dpkg -i $TEMP_DIR/magicq.deb
sudo mv /opt/magicq/lib/libstdc.so.6 /opt/magicq/lib/libstdc.so.6~

# Install Reaper
wget https://www.reaper.fm/files/7.x/reaper722_linux_x86_64.tar.xz -O $TEMP_DIR/reaper.tar.xz
tar xf $TEMP_DIR/reaper.tar.xz -C $TEMP_DIR
sudo sh $TEMP_DIR/reaper_*/install-reaper.sh --install /opt --integrate-desktop

# Install BRAW player
wget $PUBLIC_URL/assets/Blackmagic_RAW_Linux_4.2.tar.gz -O $TEMP_DIR/braw.tar.gz
tar xf $TEMP_DIR/braw.tar.gz -C $TEMP_DIR
sudo alien "$TEMP_DIR/Blackmagic RAW/blackmagic-raw-4.2.x86_64.rpm"
mv blackmagic-raw*.deb $TEMP_DIR/braw.deb
sudo dpkg -i $TEMP_DIR/braw.deb

# Install OBS-NDI
wget https://github.com/DistroAV/DistroAV/releases/download/6.0.0/distroav-6.0.0-x86_64-linux-gnu.deb -O $TEMP_DIR/obs-ndi.deb
sudo dpkg -i $TEMP_DIR/obs-ndi.deb

# Install NoMachine
wget https://download.nomachine.com/download/9.0/Linux/nomachine_9.0.188_11_amd64.deb -O $TEMP_DIR/nomachine.deb
sudo dpkg -i $TEMP_DIR/nomachine.deb

# Fetch local files
wget $PUBLIC_URL/assets/wallpaper.png -O $HOME/Pictures/wallpaper.png
wget $PUBLIC_URL/assets/magicq.pdf -O $HOME/Documents/magicq.pdf

# Customize Gnome
gsettings set org.gnome.desktop.sound event-sounds false
gsettings set org.gnome.shell last-selected-power-profile 'performance'
gsettings set org.gnome.desktop.session idle-delay 'uint32 0'
gsettings set org.gnome.shell.extensions.dash-to-dock dash-max-icon-size 36
gsettings set org.gnome.shell.extensions.dash-to-dock dock-fixed false
gsettings set org.gnome.shell.extensions.dash-to-dock extend-height false
gsettings set org.gnome.shell.extensions.dash-to-dock show-trash false
gsettings set org.gnome.shell.extensions.ding show-home false
gsettings set org.gnome.desktop.notifications show-banners false
gsettings set org.gnome.desktop.media-handling autorun-never true
gsettings set org.gnome.desktop.wm.keybindings toggle-fullscreen "['<Alt>F11']"
gsettings set org.gnome.desktop.background color-shading-type 'solid'
gsettings set org.gnome.desktop.background picture-options 'zoom'
gsettings set org.gnome.desktop.background picture-uri "file:///$HOME/Pictures/wallpaper.png"
gsettings set org.gnome.desktop.background picture-uri-dark "file:///$HOME/Pictures/wallpaper.png"
gsettings set org.gnome.desktop.background primary-color '#000000'
gsettings set org.gnome.desktop.background secondary-color '#000000'
gsettings set org.gnome.shell favorite-apps "['firefox_firefox.desktop', 'magicq.desktop', 'cockos-reaper.desktop', 'com.obsproject.Studio.desktop', 'org.gnome.Nautilus.desktop', 'org.gnome.Terminal.desktop', 'org.rncbc.qjackctl.desktop']"

# Clean up
rm -rf $TEMP_DIR
echo "Done. Reboot recommended"