forked from SnoringDragon/gluetun-qbittorrent-port-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
33 lines (25 loc) · 939 Bytes
/
start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
COOKIES="/tmp/cookies.txt"
update_port () {
PORT=$(cat $PORT_FORWARDED)
rm -f $COOKIES
# Log in to qBittorrent and save the session cookie
login_response=$(curl -s -c $COOKIES --data "username=$QBITTORRENT_USER&password=$QBITTORRENT_PASS" "${HTTP_S}://${QBITTORRENT_SERVER}:${QBITTORRENT_PORT}/api/v2/auth/login")
if ! echo "$login_response" | grep -iq "Ok"; then
echo "Error logging into the qBittorrent Web UI"
return 1
fi
# Update the qBittorrent listening port
curl -s -b $COOKIES --data-urlencode "json={\"listen_port\":$PORT}" "${HTTP_S}://${QBITTORRENT_SERVER}:${QBITTORRENT_PORT}/api/v2/app/setPreferences" > /dev/null
rm -f $COOKIES
echo "Successfully updated qBittorrent to port $PORT"
}
while true; do
if [ -f $PORT_FORWARDED ]; then
update_port
else
echo "Couldn't find file $PORT_FORWARDED"
fi
# Wait for 30 seconds before checking again
sleep 30
done