#!/bin/bash

# Load Jacktrip binaries (1.3 and 1.4 -- leaving the plain "jacktrip" command at 1.3 for the moment) 
# Load Jacktrip licenses
# Load JMess binary 
# Make them executable

curl -o /usr/local/bin/jacktrip   https://PGJTT.com/Binaries/jacktrip
curl -o /usr/local/bin/jacktrip1.3   https://PGJTT.com/Binaries/jacktrip1.3
curl -o /usr/local/bin/jacktrip1.4   https://PGJTT.com/Binaries/jacktrip1.4
curl -o /usr/local/bin/Jacktrip_Licenses.zip   https://PGJTT.com/Binaries/Jacktrip_Licenses.zip
curl -o /usr/local/bin/jmess   https://PGJTT.com/Binaries/jmess
curl -o /usr/local/bin/connect_players  https://PGJTT.com/Binaries/connect_players

chmod +x /usr/local/bin/jacktrip
chmod +x /usr/local/bin/jacktrip1.3
chmod +x /usr/local/bin/jacktrip1.4
chmod +x /usr/local/bin/jmess
chmod +x /usr/local/bin/connect_players

# Install utility apps

sudo apt-get update && apt-get -y upgrade # get all the latest packages  > /dev/null

DEBIAN_FRONTEND='noninteractive' sudo apt-get install -y --no-install-recommends build-essential qt5-default autoconf automake libtool make git gcc-8-base net-tools lighttpd zip unzip  > /dev/null


# create needed rtaudio memory-management settings
cat << EOF >/etc/security/limits.conf
* hard rtprio 95
* hard memlock unlimited
* soft rtprio 95
* soft memlock unlimited
root hard rtprio 95
root hard memlock unlimited
root soft rtprio 95
root soft memlock unlimited
EOF

# Configure the web server to provide a repository for sharing audio recordings at
# http://[server-IP-address]/Recordings, update lighttpd (web server) for directory 
# browsing, and create an alias for the folder in Root's home directory

mkdir -p /var/www/html/Recordings
#curl -o /etc/lighttpd/conf-enabled/99-unconfigured.conf  https://PGJTT.com/Web-Config/lighttpd.conf
echo '$HTTP["url"] =~ "^/Recordings($|/)" { server.dir-listing = "enable" }' >> /etc/lighttpd/conf-enabled/99-unconfigured.conf
service lighttpd restart
ln -s /var/www/html/Recordings /root/Recordings





echo " "
echo "Application installations are starting..."
echo " "
echo "Get ready to use the arrow-key to answer "YES" when the question pops up..."

# Install audio apps

DEBIAN_FRONTEND='noninteractive' sudo apt-get install -y -qq libjack-jackd2-dev librtaudio-dev qtdeclarative5-dev  > /dev/null
echo " "
echo "     1 of 10 -- Jack audio installed..."

DEBIAN_FRONTEND='noninteractive' sudo apt-get install -y -qq qjackctl 
echo " "
echo "     2 of 10 -- Qjackctl utility installed..."

DEBIAN_FRONTEND='noninteractive' sudo apt-get install -y -qq ardour  > /dev/null
echo " "
echo "     3 of 10 -- Ardour DAW installed..."


# Install alternate desktop apps (Nautilus file manager, Kate text editor, Terminology terminal-emulator)

DEBIAN_FRONTEND='noninteractive' sudo apt-get install -y -qq nautilus > /dev/null
echo " "
echo "     4 of 10 -- Nautilus graphical file-manager installed..."

DEBIAN_FRONTEND='noninteractive' sudo apt-get install -y -qq kate > /dev/null
echo " "
echo "     5 of 10 -- Kate graphical text-editor installed..."

DEBIAN_FRONTEND='noninteractive' sudo apt-get install -y -qq terminology > /dev/null
echo " "
echo "     6 of 10 -- Terminology terminal-window manager installed..."


# Install desktop/GUI apps -- xfce4, tightvncserver and gnome-icon-theme 

# BYPASSED - Put these in if you don't have a windowing system installed
# 
# DEBIAN_FRONTEND='noninteractive' sudo apt-get install -y -qq xfce4 > /dev/null
# echo " "
# echo "     7 of 10 -- Xfce4 software installed..."
# 
# DEBIAN_FRONTEND='noninteractive' sudo apt-get install -y -qq gnome-icon-theme > /dev/null
# echo " "
# echo "     8 of 10 -- Gnome-icon-theme installed..."
# 
# END BYPASSED


DEBIAN_FRONTEND='noninteractive' sudo apt-get install -y -qq tightvncserver > /dev/null
DEBIAN_FRONTEND='noninteractive' sudo apt-get install -y -qq autocutsel > /dev/null
echo " "
echo "     8 of 10 -- TightVNCserver installed..."


# Add audio hardware-abstraction settings to modules

echo "snd-bcm2835" >>/etc/modules
echo "snd-dummy" >>/etc/modules

echo " "
echo "Upload sample Mixing templates into the Root-home and Recordings directories.  These can be "
echo "imported into Ardour through the Templates function, which is located in"
echo "the Window/Templates/Import menu of Ardour"
echo " "

curl -o ~/Recordings/Import_These_Mixing_Templates_2.2.2.tar.xz     https://PGJTT.com/Tmplts_Ardour/Import_These_Mixing_Templates_2.2.2.tar.xz 
curl -o ~/Recordings/Import_These_Mixing_Templates_2.2.2.tar.xz     https://PGJTT.com/Tmplts_Ardour/Import_These_Mixing_Templates_2.2.2.tar.xz 

echo " "
echo "Upload the Jmess template into the Recordings directory. This is used by the" 
echo "connect_players script to bring newly-connected players into the mixing session "
echo " "


curl -o ~/Recordings/jmess20StereoBroadcastJT-connect_2.2.2_v1.xml 	https://PGJTT.com/Tmplts_JMess/jmess20StereoBroadcastJT-connect_2.2.2_v1.xml

echo " "
echo "     9 of 10 -- Template downloads complete..."


# NOTE -- This is used to remind people of VNC commands when logging in remotely
# 
# 
# Add the shell-session script to root's .profile file.  
# This makes the "tips" file appear every time a person logs in with SSH. 
# Edit the .profile file to remove this if it becomes annoying

curl -s -O https://PGJTT.com/Tips-files/shell-session-tips-2.2.2.txt 
echo "cat shell-session-tips-2.2.2.txt">>.profile



