#!/bin/bash
#########################################################################
#									#
#	     DIREWOLF INSTALLATION SCRIPT FOR RASPBERRY PI     		#
#									#
#			     INSTRUCTIONS:      			#
#     Copy this file to /usr/src/ and make it executable by running	#
#	  "sudo chmod +x direwolf.sh", then, to run the script    	#
#	  navigate to the directory where the script is located  	#
#		      and run "bash ./direwolf.sh"			#
#	 Once installed, it's necessary to start the service and	#
#	   you can manage the app's execution with the command		#
#	 "systemctl start/restart/stop/status direwolf.service"		#
#	      To view the log file type the command below:		#
#		"journalctl -u direwolf.service -f -n 50"		#
#									#
#	     Created by Daniel K. PU5KOD on 2023/02/19 07:12		#
#		   Last update 2024/11/19 13:33 GMT-3			#
#									#
#########################################################################

sudo apt update
sudo apt full-upgrade -y
sudo apt install git gcc g++ make cmake libasound2-dev libudev-dev libavahi-client-dev gpiod libgpiod-dev -y
cd /usr/src/
sudo git clone https://github.com/wb2osz/direwolf.git
cd direwolf
sudo git checkout dev
sudo mkdir build
cd build
sudo cmake ..
sudo make -j4
sudo make install
sudo make install-conf
sudo mkdir /var/log/direwolf
sudo adduser --system --no-create-home --group direwolf
sudo usermod -g audio -G audio direwolf
sudo chown -R direwolf:direwolf /var/log/direwolf/
sudo usermod -a -G gpio direwolf
sudo adduser direwolf sudo
sudo wget http://dvbr.net/cloud/direwolf/files.tar
sudo tar -xf files.tar
sudo mv etc_direwolf.conf /etc/direwolf.conf
#sudo mv etc_rsyslog.d_direwolf.conf /etc/rsyslog.d/direwolf.conf
sudo rm etc_rsyslog.d_direwolf.conf
sudo mv etc_logrotate.d_direwolf /etc/logrotate.d/direwolf
sudo mv direwolf.service /etc/systemd/system/direwolf.service
sudo systemctl enable direwolf.service
sudo systemctl enable systemd-networkd-wait-online
echo ""
echo "***********************************************************"
echo "*                                                         *"
echo "*               DIREWOLF IS NOW INSTALLED!                *"
echo "*                                                         *"
echo "*       Now start running the app with the command        *"
echo "*          sudo systemctl start direwolf.service          *"
echo "*             Track application activity with             *"
echo "*         journalctl -u direwolf.service -f -n 50         *"
echo "*     The configuration file is in /etc/direwolf.conf     *"
echo "*         The log files is in /var/log/direwolf/          *"
echo "*                                                         *"
echo "***********************************************************"
