mirror of
https://github.com/MarkusMcNugen/docker-qBittorrentvpn
synced 2024-11-14 14:44:57 +00:00
Changes to work with Kubernetes and couple of fixes.
This commit is contained in:
parent
e76192d13f
commit
2456aed952
10
README.md
10
README.md
@ -21,7 +21,8 @@ To run the container use this command:
|
|||||||
|
|
||||||
```
|
```
|
||||||
$ docker run --privileged -d \
|
$ docker run --privileged -d \
|
||||||
-v /your/config/path/:/config \
|
-v /your/qBittorrent/path/:/config/qBittorrent \
|
||||||
|
-v /your/openvpn/client.conf:/config/client.ovpn \
|
||||||
-v /your/downloads/path/:/downloads \
|
-v /your/downloads/path/:/downloads \
|
||||||
-e "VPN_ENABLED=yes" \
|
-e "VPN_ENABLED=yes" \
|
||||||
-e "LAN_NETWORK=192.168.1.0/24" \
|
-e "LAN_NETWORK=192.168.1.0/24" \
|
||||||
@ -37,6 +38,7 @@ $ docker run --privileged -d \
|
|||||||
| Variable | Required | Function | Example |
|
| Variable | Required | Function | Example |
|
||||||
|----------|----------|----------|----------|
|
|----------|----------|----------|----------|
|
||||||
|`VPN_ENABLED`| Yes | Enable VPN? (yes/no) Default:yes|`VPN_ENABLED=yes`|
|
|`VPN_ENABLED`| Yes | Enable VPN? (yes/no) Default:yes|`VPN_ENABLED=yes`|
|
||||||
|
|`VPN_CONFIG`| No | Path to OpenVPN config file. Default: /config/client.ovpn| `VPN_CONFIG=/config/client.conf`
|
||||||
|`VPN_USERNAME`| No | If username and password provided, configures ovpn file automatically |`VPN_USERNAME=ad8f64c02a2de`|
|
|`VPN_USERNAME`| No | If username and password provided, configures ovpn file automatically |`VPN_USERNAME=ad8f64c02a2de`|
|
||||||
|`VPN_PASSWORD`| No | If username and password provided, configures ovpn file automatically |`VPN_PASSWORD=ac98df79ed7fb`|
|
|`VPN_PASSWORD`| No | If username and password provided, configures ovpn file automatically |`VPN_PASSWORD=ac98df79ed7fb`|
|
||||||
|`LAN_NETWORK`| Yes | Local Network with CIDR notation |`LAN_NETWORK=192.168.1.0/24`|
|
|`LAN_NETWORK`| Yes | Local Network with CIDR notation |`LAN_NETWORK=192.168.1.0/24`|
|
||||||
@ -50,7 +52,8 @@ $ docker run --privileged -d \
|
|||||||
## Volumes
|
## Volumes
|
||||||
| Volume | Required | Function | Example |
|
| Volume | Required | Function | Example |
|
||||||
|----------|----------|----------|----------|
|
|----------|----------|----------|----------|
|
||||||
| `config` | Yes | qBittorrent and OpenVPN config files | `/your/config/path/:/config`|
|
| `qBittorrent` | Yes | qBittorrent and OpenVPN config files | `/your/config/path/:/config/qBittorrent`|
|
||||||
|
| `client.ovpn` | No | OpenVPN config file if `VPN_ENABLED=yes` | `/your/openvpn/client.conf:/config/client.ovpn`|
|
||||||
| `downloads` | No | Default download path for torrents | `/your/downloads/path/:/downloads`|
|
| `downloads` | No | Default download path for torrents | `/your/downloads/path/:/downloads`|
|
||||||
|
|
||||||
## Ports
|
## Ports
|
||||||
@ -112,7 +115,8 @@ $ docker build -t qbittorrentvpn .
|
|||||||
## Run it:
|
## Run it:
|
||||||
```
|
```
|
||||||
$ docker run --privileged -d \
|
$ docker run --privileged -d \
|
||||||
-v /your/config/path/:/config \
|
-v /your/qBittorrent/path/:/config/qBittorrent \
|
||||||
|
-v /your/openvpn/client.conf:/config/client.ovpn \
|
||||||
-v /your/downloads/path/:/downloads \
|
-v /your/downloads/path/:/downloads \
|
||||||
-e "VPN_ENABLED=yes" \
|
-e "VPN_ENABLED=yes" \
|
||||||
-e "LAN_NETWORK=192.168.1.0/24" \
|
-e "LAN_NETWORK=192.168.1.0/24" \
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
# Forked from binhex's OpenVPN dockers
|
# Forked from binhex's OpenVPN dockers
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
ETC_OPENVPN=/etc/openvpn
|
||||||
|
OPENVPN_CONFIG="$ETC_OPENVPN/client.ovpn"
|
||||||
|
|
||||||
# check for presence of network interface docker0
|
# check for presence of network interface docker0
|
||||||
check_network=$(ifconfig | grep docker0 || true)
|
check_network=$(ifconfig | grep docker0 || true)
|
||||||
|
|
||||||
@ -19,51 +22,48 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $VPN_ENABLED == "yes" ]]; then
|
if [[ $VPN_ENABLED == "yes" ]]; then
|
||||||
# create directory to store openvpn config files
|
# Set default path to OpenVPN config file if not defined.
|
||||||
mkdir -p /config/openvpn
|
if [ -z "$VPN_CONFIG" ]; then
|
||||||
# set perms and owner for files in /config/openvpn directory
|
export VPN_CONFIG=/config/client.ovpn
|
||||||
|
fi
|
||||||
|
|
||||||
|
# exit if ovpn file not found
|
||||||
|
if [ ! -f "${VPN_CONFIG}" ]; then
|
||||||
|
echo "[crit] No OpenVPN config file located at $VPN_CONFIG. Please download from your VPN provider and then restart this container, exiting..." | ts '%Y-%m-%d %H:%M:%.S' && exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[info] OpenVPN config file is located at ${VPN_CONFIG}" | ts '%Y-%m-%d %H:%M:%.S'
|
||||||
|
|
||||||
|
# set perms and owner for files in $VPN_CONFIG directory
|
||||||
set +e
|
set +e
|
||||||
chown -R "${PUID}":"${PGID}" "/config/openvpn" &> /dev/null
|
chown -R "${PUID}":"${PGID}" "$VPN_CONFIG" &> /dev/null
|
||||||
exit_code_chown=$?
|
exit_code_chown=$?
|
||||||
chmod -R 775 "/config/openvpn" &> /dev/null
|
chmod -R 644 "$VPN_CONFIG" &> /dev/null
|
||||||
exit_code_chmod=$?
|
exit_code_chmod=$?
|
||||||
set -e
|
set -e
|
||||||
if (( ${exit_code_chown} != 0 || ${exit_code_chmod} != 0 )); then
|
if (( ${exit_code_chown} != 0 || ${exit_code_chmod} != 0 )); then
|
||||||
echo "[warn] Unable to chown/chmod /config/openvpn/, assuming SMB mountpoint" | ts '%Y-%m-%d %H:%M:%.S'
|
echo "[warn] Unable to chown/chmod $VPN_CONFIG, assuming SMB mountpoint" | ts '%Y-%m-%d %H:%M:%.S'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# wildcard search for openvpn config files (match on first result)
|
|
||||||
export VPN_CONFIG=$(find /config/openvpn -maxdepth 1 -name "*.ovpn" -print -quit)
|
|
||||||
|
|
||||||
# if ovpn file not found in /config/openvpn then exit
|
|
||||||
if [[ -z "${VPN_CONFIG}" ]]; then
|
|
||||||
echo "[crit] No OpenVPN config file located in /config/openvpn/ (ovpn extension), please download from your VPN provider and then restart this container, exiting..." | ts '%Y-%m-%d %H:%M:%.S' && exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "[info] OpenVPN config file (ovpn extension) is located at ${VPN_CONFIG}" | ts '%Y-%m-%d %H:%M:%.S'
|
|
||||||
|
|
||||||
# Read username and password env vars and put them in credentials.conf, then add ovpn config for credentials file
|
# Read username and password env vars and put them in credentials.conf, then add ovpn config for credentials file
|
||||||
if [[ ! -z "${VPN_USERNAME}" ]] && [[ ! -z "${VPN_PASSWORD}" ]]; then
|
if [[ ! -z "${VPN_USERNAME}" ]] && [[ ! -z "${VPN_PASSWORD}" ]]; then
|
||||||
if [[ ! -e /config/openvpn/credentials.conf ]]; then
|
OPENVPN_CREDENTIALS="$ETC_OPENVPN/credentials.conf"
|
||||||
touch /config/openvpn/credentials.conf
|
echo "${VPN_USERNAME}" > $OPENVPN_CREDENTIALS
|
||||||
fi
|
echo "${VPN_PASSWORD}" >> $OPENVPN_CREDENTIALS
|
||||||
|
|
||||||
echo "${VPN_USERNAME}" > /config/openvpn/credentials.conf
|
|
||||||
echo "${VPN_PASSWORD}" >> /config/openvpn/credentials.conf
|
|
||||||
|
|
||||||
# Replace line with one that points to credentials.conf
|
# Replace line with one that points to credentials.conf
|
||||||
auth_cred_exist=$(cat ${VPN_CONFIG} | grep -m 1 'auth-user-pass')
|
auth_cred_exist=$(grep -m 1 'auth-user-pass' $VPN_CONFIG || true)
|
||||||
if [[ ! -z "${auth_cred_exist}" ]]; then
|
if [[ ! -z "${auth_cred_exist}" ]]; then
|
||||||
# Get line number of auth-user-pass
|
# Get line number of auth-user-pass
|
||||||
LINE_NUM=$(grep -Fn -m 1 'auth-user-pass' ${VPN_CONFIG} | cut -d: -f 1)
|
LINE_NUM=$(grep -Fn -m 1 'auth-user-pass' ${VPN_CONFIG} | cut -d: -f 1)
|
||||||
sed -i "${LINE_NUM}s/.*/auth-user-pass credentials.conf\n/" ${VPN_CONFIG}
|
sed "${LINE_NUM}s/.*/auth-user-pass credentials.conf\n/" ${VPN_CONFIG} > $OPENVPN_CONFIG
|
||||||
else
|
else
|
||||||
sed -i "1s/.*/auth-user-pass credentials.conf\n/" ${VPN_CONFIG}
|
sed -e "\$aauth-user-pass credentials.conf\n" ${VPN_CONFIG} > $OPENVPN_CONFIG
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# convert CRLF (windows) to LF (unix) for ovpn
|
# convert CRLF (windows) to LF (unix) for ovpn
|
||||||
/usr/bin/dos2unix "${VPN_CONFIG}" 1> /dev/null
|
/usr/bin/dos2unix $OPENVPN_CONFIG 1> /dev/null
|
||||||
|
|
||||||
# parse values from ovpn file
|
# parse values from ovpn file
|
||||||
export vpn_remote_line=$(cat "${VPN_CONFIG}" | grep -P -o -m 1 '(?<=^remote\s)[^\n\r]+' | sed -e 's~^[ \t]*~~;s~[ \t]*$~~')
|
export vpn_remote_line=$(cat "${VPN_CONFIG}" | grep -P -o -m 1 '(?<=^remote\s)[^\n\r]+' | sed -e 's~^[ \t]*~~;s~[ \t]*$~~')
|
||||||
@ -161,8 +161,8 @@ fi
|
|||||||
|
|
||||||
if [[ $VPN_ENABLED == "yes" ]]; then
|
if [[ $VPN_ENABLED == "yes" ]]; then
|
||||||
echo "[info] Starting OpenVPN..." | ts '%Y-%m-%d %H:%M:%.S'
|
echo "[info] Starting OpenVPN..." | ts '%Y-%m-%d %H:%M:%.S'
|
||||||
cd /config/openvpn
|
cd $ETC_OPENVPN
|
||||||
exec openvpn --config ${VPN_CONFIG} &
|
exec openvpn --config $OPENVPN_CONFIG &
|
||||||
# give openvpn some time to connect
|
# give openvpn some time to connect
|
||||||
sleep 5
|
sleep 5
|
||||||
#exec /bin/bash /etc/openvpn/openvpn.init start &
|
#exec /bin/bash /etc/openvpn/openvpn.init start &
|
||||||
@ -170,3 +170,4 @@ if [[ $VPN_ENABLED == "yes" ]]; then
|
|||||||
else
|
else
|
||||||
exec /bin/bash /etc/qbittorrent/start.sh
|
exec /bin/bash /etc/qbittorrent/start.sh
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user