2
0
Fork 0

Merge pull request #10 from soxfor/dev

This commit is contained in:
SOXFOR 2023-04-24 02:10:59 +01:00 committed by GitHub
commit 6073092c03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 147 additions and 28 deletions

View File

@ -19,7 +19,7 @@ FROM ubuntu:jammy
LABEL org.opencontainers.image.source="https://github.com/soxfor/qbittorrent-natmap"
LABEL org.opencontainers.image.base.name="ubuntu:jammy"
LABEL description="Map port via NAT-PMP and update qBittorrent configuration"
LABEL version="1.0.7"
LABEL version="1.1.0"
ARG DEBIAN_FRONTEND=noninteractive
@ -30,7 +30,8 @@ RUN apt-get install --no-install-suggests --no-install-recommends --yes --quiet
bc \
netcat-openbsd \
tzdata \
locales
locales \
iproute2
RUN rm -rf /var/lib/apt/lists/* /var/cache/apt/*
RUN apt-get clean

View File

@ -42,7 +42,8 @@ These actions are performed continuously (in a loop, every 5 minutes (default, c
* QBITTORRENT_PORT (Defaults to **8080**)
* QBITTORRENT_USER (Defaults to **admin**)
* QBITTORRENT_PASS (Defaults to **adminadmin**)
* VPN_GATEWAY (Defaults to empty, **needs to be set**)
* VPN_GATEWAY (Defaults to **empty**)
* If not set the script will try and find it
* The value for this variable will be the `VPN_IF_NAME` (default: tun0) gateway address, not the `VPN_ENDPOINT_IP` from the Gluetun/VPN Container when using Wireguard, [more info here](https://github.com/qdm12/gluetun/wiki/Custom-provider#wireguard-only).
* For ProtonVPN using Wireguard this would be set to **10.2.0.1**
* VPN_CT_NAME (Defaults to **gluetun**)

View File

@ -4,6 +4,41 @@ timestamp() {
date '+%Y-%m-%d %H:%M:%S'
}
get_vpn_if_gw() {
local vpn_if_hex_addr=''
local vpn_if_dec_addr=''
local vpn_if_addr=''
local try_ip=''
local vpn_if_gw=''
vpn_if_hex_addr=$(grep "${VPN_IF_NAME}" /proc/net/route | awk '$2 == "00000000" { print $3 }')
if [ -n "${vpn_if_hex_addr}" ]; then
#shellcheck disable=SC2046
vpn_if_dec_addr=$(printf "%d." $(echo "${vpn_if_hex_addr}" | sed 's/../0x& /g' | tr ' ' '\n' | tac) | sed 's/\.$/\n/')
fi
if [ -z "${vpn_if_dec_addr}" ]; then
vpn_if_addr=$(ip addr show dev "${VPN_IF_NAME}" | grep -oP '([0-9]{1,3}[\.]){3}[0-9]{1,3}')
for n in {1..254}; do
try_ip="$(echo "${vpn_if_addr}" | cut -d'.' -f1-3).${n}"
if [ "${try_ip}" != "${vpn_if_addr}" ]; then
if nc -4 -vw1 "${try_ip}" 1 &>/dev/null 2>&1; then
vpn_if_gw=${try_ip}
break
fi
fi
done
if [ -n "${vpn_if_gw}" ]; then
echo "${vpn_if_gw}"
else
return 1
fi
else
echo "${vpn_if_dec_addr}"
fi
}
getpublicip() {
# shellcheck disable=SC2086
natpmpc -g ${VPN_GATEWAY} | grep -oP '(?<=Public.IP.address.:.).*'
@ -107,7 +142,23 @@ get_portmap() {
return $res
}
check_vpn_ct_health() {
while true;
do
if ! docker inspect "${VPN_CT_NAME}" --format='{{json .State.Health.Status}}' | grep -q '"healthy"'; then
echo "$(timestamp) | Waiting for ${VPN_CT_NAME} healthy state.."
sleep 3
else
echo "$(timestamp) | VPN container ${VPN_CT_NAME} in healthy state!"
break
fi
done
}
pre_reqs() {
if [ -z "${VPN_GATEWAY}" ]; then
VPN_GATEWAY=$(get_vpn_if_gw || echo '')
fi
while read -r var; do
[ -z "${!var}" ] && { echo "$(timestamp) | ${var} is empty or not set."; exit 1; }
done << EOF
@ -148,6 +199,9 @@ configured_port=
active_port=
qbt_sid=
# Wait for a healthy state on the VPN container
check_vpn_ct_health
if pre_reqs; then load_vals; fi
# shellcheck disable=SC2086

View File

@ -1,33 +1,96 @@
---
services:
app:
gluetun:
# https://github.com/qdm12/gluetun
image: ghcr.io/qdm12/gluetun:latest
container_name: gluetun
# line above must be uncommented to allow external containers to connect. See https://github.com/qdm12/gluetun/wiki/Connect-a-container-to-gluetun#external-container-to-gluetun
restart: unless-stopped
cap_add:
- NET_ADMIN
devices:
- /dev/net/tun:/dev/net/tun
volumes:
- /<yourpath>:/gluetun
# If using ProtonVPN with OpenVPN, this path needs to be set to the downloaded .ovpn file
# - /<yourpath>/<ovpn_config>.udp.ovpn:/gluetun/custom.conf:ro
environment:
# See https://github.com/qdm12/gluetun/wiki
## ProtonVPN Wireguard
- VPN_SERVICE_PROVIDER=custom
- VPN_TYPE=wireguard
- VPN_ENDPOINT_IP=
- VPN_ENDPOINT_PORT=
- WIREGUARD_PUBLIC_KEY=
- WIREGUARD_PRIVATE_KEY=
- WIREGUARD_ADDRESSES=
## ProtonVPN OpenVPN
# - VPN_SERVICE_PROVIDER=custom
# - VPN_TYPE=openvpn
# - OPENVPN_CUSTOM_CONFIG=/gluetun/custom.conf
# See https://protonvpn.com/support/port-forwarding-manual-setup/
# - OPENVPN_USER=<username>+pmp
# - OPENVPN_PASSWORD=
# Timezone for accurate log times
- TZ=Etc/UTC
# Server list updater. See https://github.com/qdm12/gluetun/wiki/Updating-Servers#periodic-update
- UPDATER_PERIOD=
- UPDATER_VPN_SERVICE_PROVIDERS=
# If QBITTORRENT_SERVER address is not related to VPN_IF_NAME (default: tun0) you'll need to set the variable below
# - FIREWALL_OUTBOUND_SUBNETS=172.16.0.0/24
ports:
# - 8888:8888/tcp # HTTP proxy
# - 8388:8388/tcp # Shadowsocks
# - 8388:8388/udp # Shadowsocks
- 8080:8080/tcp # qBittorrent
# networks:
# gluetun-network:
# ipv4_address: 172.16.0.10
qbittorrent:
# https://docs.linuxserver.io/images/docker-qbittorrent
image: lscr.io/linuxserver/qbittorrent:latest
container_name: qbittorrent
restart: unless-stopped
volumes:
- /<yourpath>/config:/config
- /<yourpath>/downloads:/downloads
environment:
- TZ=Etc/UTC
network_mode: "service:gluetun"
depends_on:
gluetun:
condition: service_healthy
qbittorrent-natmap:
# https://github.com/soxfor/qbittorrent-natmap
image: ghcr.io/soxfor/qbittorrent-natmap:latest
container_name: qbittorrent-natmap
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /var/run/docker.sock:/var/run/docker.sock:ro
environment:
- TZ=Etc/UTC
- QBITTORRENT_SERVER=ip.a.dd.r
# - QBITTORRENT_PORT=
# Defaults to 8080
# - QBITTORRENT_USER=
# Defaults to admin
# - QBITTORRENT_PASS=
# Defaults to adminadmin
# - VPN_CT_NAME=
# Defaults to gluetun
- VPN_GATEWAY=ip.a.dd.r
# - VPN_IF_NAME=
# Defaults to tun0
# - CHECK_INTERVAL=
# Defaults to 300sec
# - NAT_LEASE_LIFETIME=
# Defaults to 300sec
- QBITTORRENT_SERVER=
# - QBITTORRENT_PORT=8080
# - QBITTORRENT_USER=admin
# - QBITTORRENT_PASS=adminadmin
# - VPN_GATEWAY=
# - VPN_CT_NAME=gluetun
# - VPN_IF_NAME=tun0
# - CHECK_INTERVAL=300
# - NAT_LEASE_LIFETIME=300
network_mode: "service:gluetun"
depends_on:
# VPN Container Name
- gluetun
# qBittorrent Container Name
- qbittorrent
network_mode: "container:gluetun" # Specify the VPN container name here
# or
# network_mode: "service:gluetun" # if defined on the same docker-compose file
qbittorrent:
condition: service_started
gluetun:
condition: service_healthy
#networks:
# gluetun-network:
# driver: bridge
# ipam:
# config:
# - subnet: 172.16.0.0/24
# gateway: 172.16.0.254