-
-
Save dmp1ce/6bcb38d1843bac1a25e9 to your computer and use it in GitHub Desktop.
| #!/bin/bash | |
| # Kill transmission-daemon if it is running | |
| transmission_da_pid=$(pgrep transmission-da) | |
| if [ $transmission_da_pid ]; then | |
| killall transmission-daemon && echo "Closing existing tranmission-daemon processes ..." && sleep 8 | |
| fi | |
| # Get VPN IP to bind to | |
| bind_address=$(ip addr show tun0 | grep inet | awk '{print $2}') | |
| # If IP wasn't found then quit | |
| if [ -z $bind_address ]; then | |
| echo "VPN doesn't seem to be up. Will not start tranmission-daemon" | |
| exit | |
| fi | |
| # Start transmission-daemon | |
| transmission-daemon --rpc-bind-address=127.0.0.1 --bind-address-ipv4=$bind_address | |
| echo "transmission-daemon started and bound to address $bind_address" |
19wolf
commented
Dec 17, 2017
if you use ip -br addr show tun0 you can get rid of the grep inet part and change the awk to $3.
-br stands for -brief
A quick update as I stumbled upon this thread and used the suggested service unit successfully, but the ExecStart= line should be updated to remove the parameter assignation = as Transmission 3.00 now uses a space, and by using the suggestions by @ikwyl6 the line could be set to:
ExecStart=/bin/bash -c "/usr/bin/transmission-daemon -f --log-error --bind-address-ipv4 $(ip -br addr show tun0 | awk '{print $3}')"
Updated to 4.1.0 and for some reason, it now requires RestrictAddressFamilies=, to clear out the hardened defaults from the unit, because the ip utility requires AF_NETLINK sockets, or it will not be able to start.
So now I have in /etc/systemd/system/transmission.service.d/customexec.conf:
RestrictAddressFamilies=
ExecStart=
ExecStart=/bin/bash -c "/usr/bin/transmission-daemon -f --log-level=error --logfile /path/to/transmission.log --bind-address-ipv4 $(ip -br addr show tun0 | awk '{print $3}' | sed -e 's/\\/.*//')"