mirror of
https://github.com/SinTan1729/random.git
synced 2025-04-19 09:10:00 -05:00
Compare commits
2 commits
d6bca201cc
...
ebf5d19cf8
Author | SHA1 | Date | |
---|---|---|---|
ebf5d19cf8 | |||
a6e16e7410 |
1 changed files with 11 additions and 11 deletions
22
qbt-set-forwarded-port.sh
Normal file → Executable file
22
qbt-set-forwarded-port.sh
Normal file → Executable file
|
@ -1,26 +1,25 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# Adapted from https://github.com/claabs/qbittorrent-port-forward-file/blob/master/main.sh
|
# Adapted from https://github.com/claabs/qbittorrent-port-forward-file/blob/master/main.sh
|
||||||
# Until VPN_PORT_FORWARDING_UP_COMMAND is available, this could be run via a cronjob
|
|
||||||
# Might need to change the container name in the docker exec line
|
|
||||||
|
|
||||||
set -e
|
# set -e
|
||||||
|
|
||||||
qbt_username="${QBT_USERNAME:-admin}"
|
qbt_username="${QBT_USERNAME:-sintan}"
|
||||||
qbt_password="${QBT_PASSWORD:-adminadmin}"
|
qbt_password="${QBT_PASSWORD:-17291998}"
|
||||||
qbt_addr="${QBT_ADDR:-http://localhost:8085}" # ex. http://10.0.1.48:8080
|
qbt_addr="${QBT_ADDR:-http://localhost:8085}" # ex. http://10.0.1.48:8080
|
||||||
gluetun_container="${GLUETUN_COMTAINER:-qbt-gluetun}"
|
|
||||||
|
|
||||||
port_number=$(docker exec "$gluetun_container" cat /tmp/gluetun/forwarded_port)
|
port_number="$1"
|
||||||
|
[ -z "$port_number" ] && port_number=$(cat /tmp/gluetun/forwarded_port)
|
||||||
|
|
||||||
if [ -z "$port_number" ]; then
|
if [ -z "$port_number" ]; then
|
||||||
echo "Could not figure out which port to set."
|
echo "Could not figure out which port to set."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
curl --fail --silent --show-error --cookie-jar /tmp/cookies.txt --cookie /tmp/cookies.txt --header "Referer: $qbt_addr" --data "username=$qbt_username" --data "password=$qbt_password" $qbt_addr/api/v2/auth/login 1> /dev/null
|
wget --save-cookies=/tmp/cookies.txt --keep-session-cookies --header="Referer: $qbt_addr" --header="Content-Type: application/x-www-form-urlencoded" \
|
||||||
|
--post-data="username=$qbt_username&password=$qbt_password" --output-document /dev/null --quiet "$qbt_addr/api/v2/auth/login"
|
||||||
|
|
||||||
listen_port=$(curl --fail --silent --show-error --cookie-jar /tmp/cookies.txt --cookie /tmp/cookies.txt $qbt_addr/api/v2/app/preferences | jq '.listen_port')
|
listen_port=$(wget --load-cookies=/tmp/cookies.txt --output-document - --quiet "$qbt_addr/api/v2/app/preferences" | grep -Eo '"listen_port":([0-9]+)' | awk -F: '{print $2}')
|
||||||
|
|
||||||
if [ ! "$listen_port" ]; then
|
if [ ! "$listen_port" ]; then
|
||||||
echo "Could not get current listen port, exiting..."
|
echo "Could not get current listen port, exiting..."
|
||||||
|
@ -28,13 +27,14 @@ if [ ! "$listen_port" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$port_number" = "$listen_port" ]; then
|
if [ "$port_number" = "$listen_port" ]; then
|
||||||
echo "Port already set, exiting..."
|
echo "Port already set to $port_number, exiting..."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Updating port to $port_number"
|
echo "Updating port to $port_number"
|
||||||
|
|
||||||
curl --fail --silent --show-error --cookie-jar /tmp/cookies.txt --cookie /tmp/cookies.txt --data-urlencode "json={\"listen_port\": $port_number}" $qbt_addr/api/v2/app/setPreferences
|
wget --load-cookies=/tmp/cookies.txt --header="Content-Type: application/x-www-form-urlencoded" --post-data='json={"listen_port": "'$port_number'"}' \
|
||||||
|
--output-document /dev/null --quiet "$qbt_addr/api/v2/app/setPreferences"
|
||||||
|
|
||||||
echo "Successfully updated port"
|
echo "Successfully updated port"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue