diff --git a/media/qbittorrent/natpmp-script.yaml b/media/qbittorrent/natpmp-script.yaml index 697fe55..7fa0f74 100644 --- a/media/qbittorrent/natpmp-script.yaml +++ b/media/qbittorrent/natpmp-script.yaml @@ -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