qbittorrent auto port update

This commit is contained in:
2024-11-27 12:07:11 -05:00
parent e1dec568cf
commit ef92edba60

View File

@@ -6,16 +6,26 @@ data:
while true; do
date
# Run natpmpc for UDP and TCP, redirect output to a temporary file
natpmpc -a 1 0 udp 60 -g 10.2.0.1 && natpmpc -a 1 0 tcp 60 -g 10.2.0.1 > /tmp/natpmpc_output || {
echo -e "ERROR with natpmpc command \a"
break
}
# Extract the port numbers from the output and save them in variables
port=$(grep 'TCP' /tmp/natpmpc_output | grep -o 'Mapped public port [0-9]*' | awk '{print $4}')
currentPort=$(curl -XGET 'http://127.0.0.1:8080/api/v2/app/preferences' | jq '.listen_port')
echo "Opened port: $port"
echo "Current port: $currentPort"
if [ "$currentPort" != "$port" ]; then
echo "Current port is different. Changing from $currentPort to $port"
code=$(curl --write-out '%{http_code}' --silent --output /dev/null -XPOST -d "json={\"listen_port\":$port}" "http://127.0.0.1:8080/api/v2/app/setPreferences")
if [ "$code" != "200" ]; then
echo "ERROR: port change failed with status code $code"
else
echo "Port changed to $port successfully"
fi
fi
sleep 45
done
kind: ConfigMap