diff --git a/seqs/downloader.sh b/seqs/downloader.sh new file mode 100755 index 0000000..706dc1c --- /dev/null +++ b/seqs/downloader.sh @@ -0,0 +1,234 @@ +#!/bin/bash + +toolName=mytool +DLDUSER=dluser + +# Get script working directory +# (when called from a different directory) +WDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >>/dev/null 2>&1 && pwd)" +APTOPT= +CONFIG=0 +SCRIPT_NAME=$(basename -- $0) +SCRIPT_NAME=${SCRIPT_NAME%%.*} +CONFIG_FILE_NAME="${SCRIPT_NAME}.cfg" +CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example" + +#step_config() { + #echo "Called once before executing steps." + ## e.g. to source a config file manually: + #. "$CONFIG_FILE" + ## or to use sequencer api with global config file: + #initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE" + ## or to use sequencer api with profile config file support: + #initSeqConfig -p "$SCRIPT_NAME" "$CONFIG_FILE_TEMPLATE" + #if [ $? -eq 0 ] ; then + # CONFIG=1 + #else + # # End if no configuration file exists + # [ $DRY -eq 0 ] && return -1 + #fi + #[ $QUIET -ne 0 ] && APTOPT="-y" + #return 0 +#} + +step_1_info() { echo "Install mono"; } +step_1_alias() { ALIAS="install"; } +step_1() { + exe apt install apt-transport-https dirmngr gnupg ca-certificates + exe apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF + + exep "echo \"deb https://download.mono-project.com/repo/debian stable-buster main\" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list" + + exe apt update + # This will apparently be managed by the installation of sonarr later + # (https://sonarr.tv/#downloads-v3-linux Chapter 1) + #exe apt install mono-complete +} + +step_2_info() { echo "Install mediainfo"; } +step_2() { + exe wget https://mediaarea.net/repo/deb/repo-mediaarea_1.0-16_all.deb -O /tmp/repo-mediaarea_all.deb + + exe dpkg -i /tmp/repo-mediaarea_all.deb + + exe apt-get update + exe apt install mediainfo +} + +step_3_info() { echo "Add system user"; } +step_3() { + exe adduser --system $DLDUSER --group --home /opt/downloaders +} + +step_4_info() { echo "Install sonarr" + echoinfo "Default port: 8989" +} +step_4() { + exe apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 2009837CBFFD68F45BC180471F4F90DE2A9B4BF8 + exep "echo \"deb https://apt.sonarr.tv/debian buster main\" | sudo tee /etc/apt/sources.list.d/sonarr.list" + exe apt update + exe apt install sonarr + # Start of sonar must be managed by VPN service + exe service sonarr stop + exe systemctl disable sonarr +} + +step_5_info() { + echo "Install radarr for arm64" + echoinfo "Default port: 7878" +} +step_5() { + # nightly https://radarr.servarr.com/v1/update/nightly/updatefile?os=linux&runtime=netcore&arch=arm64 + exe curl -sL "https://radarr.servarr.com/v1/update/master/updatefile?os=linux&runtime=netcore&arch=arm64" \ + -o /tmp/Radarr.tgz + + exe tar xvzf /tmp/Radarr.tgz -C /opt/downloaders/ + exe mv /opt/downloaders/Radarr /opt/downloaders/radarr + exe chown -R ${DLDUSER}:${DLDUSER} /opt/downloaders/radarr +} + +step_6_info() { echo "Create radarr service"; } +step_6() { + exe mkdir -p "$radarrConf" + exe chown -R $DLDUSER: "$radarrConf" + + addConf -s "$radarrService" "$radarrServiceLoc" + exe systemctl daemon-reload +} +radarrConf="/opt/downloaders.conf/radarr" +radarrServiceLoc="/etc/systemd/system/radarr.service" +radarrService="[Unit] +Description=Radarr Daemon +After=syslog.target network.target +Requires=nzbget.service +StartLimitIntervalSec=0 + +[Service] +User=$DLDUSER +Group=$DLDUSER + +Type=simple + +ExecStart=/opt/downloaders/radarr/Radarr -nobrowser -data=$radarrConf +TimeoutStopSec=20 +KillMode=process +Restart=on-failure +RestartSec=5 + +[Install] +WantedBy=multi-user.target +Alias=radarr.service" + +step_7_info() { + echo "Install jackett for arm64" + echoinfo "Default port: 9117" +} +step_7() { + local jTar="/tmp/Jackett.tgz" + local jUrl="https://github.com/Jackett/Jackett/releases/latest/download/Jackett.Binaries.LinuxARM64.tar.gz" + + [ ! -e "$jTar" ] && exe curl -sL "$jUrl" -o "$jTar" + + exe tar xvzf "$jTar" -C /opt/downloaders + exe mv /opt/downloaders/Jackett /opt/downloaders/jackett + exe chown -R ${DLDUSER}:${DLDUSER} /opt/downloaders/jackett +} + +step_8_info() { echo "Create jackett service"; } +step_8() { + addConf -s "$jackettService" "$jackettServiceLoc" + exe systemctl daemon-reload +} +jackettServiceLoc="/etc/systemd/system/jackett.service" +jackettService="[Unit] +Description=Jackett Daemon +After=syslog.target network.target +Requires=transmission.service +StartLimitIntervalSec=0 + +[Service] +User=$DLDUSER +Group=$DLDUSER + +Type=simple +SyslogIdentifier=jackett +Restart=on-failure +RestartSec=5 +WorkingDirectory=/opt/downloaders/jackett +ExecStart=/bin/sh /opt/downloaders/jackett/jackett_launcher.sh +TimeoutStopSec=30 + +[Install] +WantedBy=multi-user.target +Alias=jackett.service" + +step_9_info() { + echo "Install NZBGet for arm64" + echoinfo "Default port: 6789" +} +step_9() { + exe wget -q https://nzbget.net/download/nzbget-latest-bin-linux.run -O /tmp/nzbget-latest-bin-linux.run + + # you can skip --arch aarch64 to auto-detect the architecture + exe sh /tmp/nzbget-latest-bin-linux.run --destdir /opt/downloaders/nzbget --arch aarch64 + + exe chown -R ${DLDUSER}:${DLDUSER} /opt/downloaders/nzbget +} + +step_10_info() { echo "Create NZBGet service"; } +step_10() { + local nzbConfOri="/opt/downloaders/nzbget/nzbget.conf" + local nzbConf="/opt/downloaders.conf/nzbget/nzbget.conf" + exe mkdir -p "$(dirname "$nzbConf")" + exe chown -R $DLDUSER: "$(dirname "$nzbConf")"/.. + + addConf -s "$nzbService" "$nzbServiceLoc" + exe systemctl daemon-reload + + exe cp -n "$nzbConfOri" "$nzbConf" +} +nzbServiceLoc="/etc/systemd/system/nzbget.service" +nzbService="[Unit] +Description=NZBGet Daemon +After=syslog.target network.target +#Requires=mnt-disk.mount +StartLimitIntervalSec=0 + +[Service] +# Change the user and group variables here. +User=$DLDUSER +Group=$DLDUSER + +Type=forking + +# Pass any command line arguments etc. +ExecStart=/opt/downloaders/nzbget/nzbget -D -c /opt/downloaders.conf/nzbget/nzbget.conf +ExecStop=/opt/downloaders/nzbget/nzbget -Q -c /opt/downloaders.conf/nzbget/nzbget.conf +ExecReload=/opt/downloaders/nzbget/nzbget -O -c /opt/downloaders.conf/nzbget/nzbget.conf +TimeoutStopSec=20 +KillMode=process +Restart=on-failure +RestartSec=5 + +# Sandboxing ... (see https://www.freedesktop.org/software/systemd/man/systemd.exec.html for more info) +ReadWritePaths=/opt/downloaders/nzbget /opt/downloaders.conf/nzbget /mnt +ProtectSystem=strict +PrivateDevices=true +ProtectHome=true + +[Install] +WantedBy=multi-user.target +Alias=nzbget.service +RequiredBy=sonarr.service radarr.service" + +step_11_info() { echo "Create ufw rules for default ports"; } +step_11_alias() { ALIAS="ufw"; } +step_11() { + exe ufw allow in on eth0 to any port 6789 proto tcp comment "NZBGet" + exe ufw allow in on eth0 to any port 8989 proto tcp comment "sonarr" + exe ufw allow in on eth0 to any port 7878 proto tcp comment "radarr" + exe ufw allow in on eth0 to any port 9117 proto tcp comment "jackett" +} + +VERSION_SEQREV=12 +. /usr/local/bin/sequencer.sh