Add module for DL server

This commit is contained in:
Alexandre CATTEAU 2022-06-06 15:15:13 +02:00
parent 7b5e087fa2
commit 72a1c2929c
6 changed files with 98 additions and 0 deletions

23
dl-server/install.sh Normal file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env bash
run_directory=$(dirname "$0")
source "$run_directory/variables.conf"
if [ -f $run_directory/.disabled ]; then
echo "Installation is disabled. Exiting..."
exit 0
fi
echo "Copying Systemd units to system directory..."
sudo cp $run_directory/transmission-daemon.service /etc/systemd/system/
sudo sed -i -e "s/PH_AUTHORIZED_ADDRESSES/$authorized_ips/g" /etc/systemd/system/transmission-daemon.service
sudo sed -i -e "s/PH_USER/$user/g" /etc/systemd/system/transmission-daemon.service
sudo sed -i -e "s/PH_PASSWORD/$password/g" /etc/systemd/system/transmission-daemon.service
sudo sed -i -e "s:PH_DL_LOCATION:$dl_location:g" /etc/systemd/system/transmission-daemon.service
sudo cp $run_directory/transmission-vpn.service /etc/systemd/system/
sudo sed -i -e "s:PH_DIRECTORY:$(pwd):g" /etc/systemd/system/transmission-vpn.service
sudo cp $run_directory/transmission-vpn.timer /etc/systemd/system/
echo "Finished install. Exiting..."
exit 0

View File

@ -0,0 +1,16 @@
[Unit]
Description=Transmission BitTorrent Daemon (KTO)
Wants=transmission-vpn.service
BindsTo=transmission-vpn.timer
After=network.target transmission-vpn.timer
[Service]
User=debian-transmission
Type=notify
ExecStart=/usr/bin/transmission-daemon -f --log-error -a PH_AUTHORIZED_ADDRESSES -C -t -u PH_USER -v PH_PASSWORD -w PH_DL_LOCATION
ExecStop=/bin/kill -s STOP $MAINPID
ExecReload=/bin/kill -s HUP $MAINPID
NoNewPrivileges=true
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,9 @@
[Unit]
Description=Make sure VPN is active for Transmission
OnFailure=transmission-daemon.service
[Service]
ExecStart=PH_DIRECTORY/transmission-vpn.sh
[Install]
WantedBy=default.target

View File

@ -0,0 +1,32 @@
#!/bin/bash
# The purpose of this script is to check if VPN connection is active
# This script will be called (via a service) in 2 situations:
# On a regular basis when transmission is running
# This will be achieved with a timer started and stopped with transmission service
# On transmission starting
# When the script exits with failure, associated service should try to start transmission service
# Thus this script will be executed again
# We can enter an infinite loop, but this will effectively prevent transmission from connecting
# If both services are stopped, this script will never be run by error
source "$run_directory/variables.conf"
# Parameters
myip_request="curl -s -4 https://ifconfig.co"
vpn_service="openvpn-client@vpn.service"
transmission_service="transmission-daemon.service"
# Main process
ip=$($myip_request)
if [[ $ip = $real_ip ]]; then
systemctl stop $transmission_service
systemctl stop $vpn_service
sleep 3
systemctl start $vpn_service
sleep 5
exit 1
elif [[ $ip =~ (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3} ]]; then
exit 0
else
exit 1
fi

View File

@ -0,0 +1,9 @@
[Unit]
Description=Regular check for VPN while Transmission is running
BindsTo=transmission-daemon.service
[Timer]
OnUnitInactiveSec=10m
[Install]
WantedBy=default.target

View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
# Copy this file as variables.conf, with the correct values
real_ip="" # for VPN check
authorized_ips="" # for transmission web interface
user="" # user for transmission web interface
password="" # password for transmission web interface
dl_location="" # location of Downloads directory