Updated scripts based on latest release of docker-transmission-openvpn, updated Dockerfile, fetches now vpn config externally
This commit is contained in:
@@ -10,7 +10,9 @@ log() {
|
||||
|
||||
# This script will be called with tun/tap device name as parameter 1, and local IP as parameter 4
|
||||
# See https://openvpn.net/index.php/open-source/documentation/manuals/65-openvpn-20x-manpage.html (--up cmd)
|
||||
|
||||
log "Up script executed with $*"
|
||||
|
||||
if [[ "$4" = "" ]]; then
|
||||
log "ERROR, unable to obtain tunnel address"
|
||||
log "killing $PPID"
|
||||
@@ -31,12 +33,46 @@ if [[ ! -e "/dev/random" ]]; then
|
||||
ln -s /dev/urandom /dev/random
|
||||
fi
|
||||
|
||||
. /etc/deluge/userSetup.sh
|
||||
|
||||
# if config file doesnt exist (wont exist until user changes a setting) then copy default config file
|
||||
if [[ ! -f /config/core.conf ]]; then
|
||||
log "[info] Deluge config file doesn't exist, copying default..."
|
||||
cp /etc/config/core.conf /config
|
||||
else
|
||||
log "[info] Deluge config file already exists, skipping copy"
|
||||
fi
|
||||
|
||||
# if config file doesnt exist then copy stock config file
|
||||
if [[ ! -f /config/web.conf ]]; then
|
||||
log "[info] Deluge webui config file doesn't exist, copying default..."
|
||||
cp /etc/config/web.conf /config
|
||||
else
|
||||
log "[info] Deluge webui config file already exists, skipping copy"
|
||||
fi
|
||||
|
||||
log "Using ip of interface $1: $4"
|
||||
export DELUGE_BIND_ADDRESS_IPV4=$4
|
||||
|
||||
if [ -e /config/core.conf ]; then
|
||||
log "Updating Deluge conf file: listen_interface=$DELUGE_BIND_ADDRESS_IPV4"
|
||||
log "Updating Deluge conf file"
|
||||
#Interface
|
||||
sed -i -e "s/\"listen_interface\": \".*\"/\"listen_interface\": \"$DELUGE_BIND_ADDRESS_IPV4\"/" /config/core.conf
|
||||
#Deamon port
|
||||
sed -i -e "s/\"daemon_port\": \".*\"/\"daemon_port\": \"$DELUGE_DEAMON_PORT\"/" /config/core.conf
|
||||
#location
|
||||
sed -i -e "s/\"download_location\": \".*\"/\"download_location\": \"${DELUGE_INCOMPLETE_DIR//\//\\/}\"/" /config/core.conf
|
||||
sed -i -e "s/\"autoadd_location\": \".*\"/\"autoadd_location\": \"${DELUGE_WATCH_DIR//\//\\/}\"/" /config/core.conf
|
||||
sed -i -e "s/\"move_completed_path\": \".*\"/\"move_completed_path\": \"${DELUGE_DOWNLOAD_DIR//\//\\/}\"/" /config/core.conf
|
||||
sed -i -e "s/\"torrentfiles_location\": \".*\"/\"torrentfiles_location\": \"${DELUGE_TORRENT_DIR//\//\\/}\"/" /config/core.conf
|
||||
fi
|
||||
|
||||
if [ -e /config/web.conf ]; then
|
||||
log "Updating Deluge web conf file"
|
||||
#Deamon port
|
||||
sed -i -e "s/\"default_daemon\": \".*\"/\"default_daemon\": \"127.0.0.1:$DELUGE_DEAMON_PORT\"/" /config/web.conf
|
||||
#Web port
|
||||
sed -i -e "s/\"port\": \".*\"/\"port\": \"$DELUGE_WEB_PORT\"/" /config/web.conf
|
||||
fi
|
||||
|
||||
if [[ "true" = "$DROP_DEFAULT_ROUTE" ]]; then
|
||||
@@ -44,31 +80,6 @@ if [[ "true" = "$DROP_DEFAULT_ROUTE" ]]; then
|
||||
ip r del default || exit 1
|
||||
fi
|
||||
|
||||
## If we use UFW or the LOCAL_NETWORK we need to grab network config info
|
||||
if [[ "${ENABLE_UFW,,}" == "true" ]] || [[ -n "${LOCAL_NETWORK-}" ]]; then
|
||||
eval $(/sbin/ip r l | awk '{if($5!="tun0"){print "GW="$3"\nINT="$5; exit}}')
|
||||
## IF we use UFW_ALLOW_GW_NET along with ENABLE_UFW we need to know what our netmask CIDR is
|
||||
if [[ "${ENABLE_UFW,,}" == "true" ]] && [[ "${UFW_ALLOW_GW_NET,,}" == "true" ]]; then
|
||||
eval $(ip r l dev ${INT} | awk '{if($3=="link"){print "GW_CIDR="$1; exit}}')
|
||||
fi
|
||||
fi
|
||||
|
||||
log "Got local network ${GW} and CIDR ${GW_CIDR} on interface ${INT}"
|
||||
|
||||
# if [[ "${ENABLE_UFW,,}" == "true" && "${UFW_ALLOW_GW_NET,,}" == "true" ]]; then
|
||||
# log "Allow from ${GW_CIDR}"
|
||||
# ufw allow from ${GW_CIDR}
|
||||
# fi
|
||||
|
||||
if [[ -n "${LOCAL_NETWORK-}" ]]; then
|
||||
if [[ -n "${GW-}" ]] && [[ -n "${INT-}" ]]; then
|
||||
for localNet in ${LOCAL_NETWORK//,/ }; do
|
||||
log "Adding route to local network ${localNet} via ${GW} dev ${INT}"
|
||||
/sbin/ip r a "${localNet}" via "${GW}" dev "${INT}"
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
# check if ufw is disabled (re-enable it)
|
||||
if [[ "${ENABLE_UFW,,}" == "true" ]]; then
|
||||
ufw status | grep -qw active
|
||||
@@ -79,8 +90,14 @@ if [[ "${ENABLE_UFW,,}" == "true" ]]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "true" = "$LOG_TO_STDOUT" ]]; then
|
||||
LOGFILE=/dev/stdout
|
||||
else
|
||||
LOGFILE=/config/deluged.log
|
||||
fi
|
||||
|
||||
log "Starting Deluge"
|
||||
exec su --preserve-environment abc -s /bin/bash -c "/usr/bin/deluged -d -c /config -L info -l /config/deluged.log" &
|
||||
exec su --preserve-environment ${RUN_AS} -s /bin/bash -c "/usr/bin/deluged -d -c /config -L info -l $LOGFILE" &
|
||||
|
||||
# wait for deluge daemon process to start (listen for port)
|
||||
while [[ $(netstat -lnt | awk '$6 == "LISTEN" && $4 ~ ".58846"') == "" ]]; do
|
||||
@@ -88,7 +105,7 @@ while [[ $(netstat -lnt | awk '$6 == "LISTEN" && $4 ~ ".58846"') == "" ]]; do
|
||||
done
|
||||
|
||||
log "Starting Deluge webui..."
|
||||
exec su --preserve-environment abc -s /bin/bash -c "/usr/bin/deluge-web -c /config -L info -l /config/web.log" &
|
||||
exec su --preserve-environment ${RUN_AS} -s /bin/bash -c "/usr/bin/deluge-web -c /config -L info -l $LOGFILE" &
|
||||
|
||||
# Configure port forwarding if applicable
|
||||
if [[ -x /etc/openvpn/${OPENVPN_PROVIDER,,}/update-port.sh && -z $DISABLE_PORT_UPDATER ]]; then
|
||||
@@ -104,4 +121,4 @@ if [[ -x /config/deluge-post-start.sh ]]; then
|
||||
log "/config/deluge-post-start.sh returned $?"
|
||||
fi
|
||||
|
||||
log "Deluge startup script complete."
|
||||
log "Deluge startup script complete."
|
||||
|
@@ -13,15 +13,32 @@ then
|
||||
log "/config/deluge-pre-stop.sh returned $?"
|
||||
fi
|
||||
|
||||
log "Sending kill signal to deluge-web"
|
||||
PID=$(pgrep deluge-web)
|
||||
kill "$PID"
|
||||
|
||||
log "Sending kill signal to deluge-daemon"
|
||||
PID=$(pidof /usr/bin/python3 /usr/bin/deluged)
|
||||
kill -9 $PID
|
||||
# Give deluge-daemon time to shut down
|
||||
for i in {1..10}; do
|
||||
ps -p $PID &> /dev/null || break
|
||||
sleep .2
|
||||
PID=$(pgrep deluged)
|
||||
kill "$PID"
|
||||
|
||||
# Give deluged some time to shut down
|
||||
DELUGE_TIMEOUT_SEC=${DELUGE_TIMEOUT_SEC:-5}
|
||||
for i in $(seq "$DELUGE_TIMEOUT_SEC")
|
||||
do
|
||||
sleep 1
|
||||
[[ -z "$(pgrep deluged)" ]] && break
|
||||
[[ $i == 1 ]] && echo "Waiting ${DELUGE_TIMEOUT_SEC}s for deluged to die"
|
||||
done
|
||||
|
||||
# Check whether deluged is still running
|
||||
if [[ -z "$(pgrep deluged)" ]]
|
||||
then
|
||||
echo "Successfuly closed deluged"
|
||||
else
|
||||
echo "Sending kill signal (SIGKILL) to deluged"
|
||||
kill -9 "$PID"
|
||||
fi
|
||||
|
||||
# If deluge-post-stop.sh exists, run it
|
||||
if [[ -x /config/deluge-post-stop.sh ]]
|
||||
then
|
||||
|
71
root/etc/deluge/userSetup.sh
Executable file
71
root/etc/deluge/userSetup.sh
Executable file
@@ -0,0 +1,71 @@
|
||||
#!/bin/bash
|
||||
|
||||
RUN_AS=root
|
||||
|
||||
if [ -n "$PUID" ] && [ ! "$(id -u root)" -eq "$PUID" ]; then
|
||||
RUN_AS=abc
|
||||
if [ ! "$(id -u ${RUN_AS})" -eq "$PUID" ]; then
|
||||
usermod -o -u "$PUID" ${RUN_AS}
|
||||
fi
|
||||
if [ -n "$PGID" ] && [ ! "$(id -g ${RUN_AS})" -eq "$PGID" ]; then
|
||||
groupmod -o -g "$PGID" ${RUN_AS}
|
||||
fi
|
||||
|
||||
if [[ "true" = "$LOG_TO_STDOUT" ]]; then
|
||||
chown ${RUN_AS}:${RUN_AS} /dev/stdout
|
||||
fi
|
||||
|
||||
# Make sure directories exist before chown and chmod
|
||||
mkdir -p /config \
|
||||
"${DELUGE_DOWNLOAD_DIR}" \
|
||||
"${DELUGE_INCOMPLETE_DIR}" \
|
||||
"${DELUGE_WATCH_DIR}" \
|
||||
"${DELUGE_TORRENT_DIR}"
|
||||
|
||||
echo "Enforcing ownership on deluge config directories"
|
||||
chown -R ${RUN_AS}:${RUN_AS} \
|
||||
/config
|
||||
|
||||
echo "Applying permissions to deluge config directories"
|
||||
chmod -R go=rX,u=rwX \
|
||||
/config
|
||||
|
||||
if [ "$GLOBAL_APPLY_PERMISSIONS" = true ]; then
|
||||
echo "Setting owner for deluge paths to ${PUID}:${PGID}"
|
||||
chown -R ${RUN_AS}:${RUN_AS} \
|
||||
"${DELUGE_DOWNLOAD_DIR}" \
|
||||
"${DELUGE_INCOMPLETE_DIR}" \
|
||||
"${DELUGE_WATCH_DIR}" \
|
||||
"${DELUGE_TORRENT_DIR}"
|
||||
|
||||
echo "Setting permissions for download and incomplete directories"
|
||||
DIR_PERMS=$(printf '%o\n' $((0777 & ~UMASK)))
|
||||
FILE_PERMS=$(printf '%o\n' $((0666 & ~UMASK)))
|
||||
echo "Mask: ${UMASK}"
|
||||
echo "Directories: ${DIR_PERMS}"
|
||||
echo "Files: ${FILE_PERMS}"
|
||||
|
||||
find "${DELUGE_DOWNLOAD_DIR}" "${DELUGE_INCOMPLETE_DIR}" -type d \
|
||||
-exec chmod $(printf '%o\n' $((0777 & ~UMASK))) {} +
|
||||
find "${DELUGE_DOWNLOAD_DIR}" "${DELUGE_INCOMPLETE_DIR}" -type f \
|
||||
-exec chmod $(printf '%o\n' $((0666 & ~UMASK))) {} +
|
||||
|
||||
echo "Setting permission for watch and torrent directories (775) and its files (664)"
|
||||
chmod -R o=rX,ug=rwX \
|
||||
"${DELUGE_WATCH_DIR}" "${DELUGE_TORRENT_DIR}"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "
|
||||
-------------------------------------
|
||||
Deluge will run as
|
||||
-------------------------------------
|
||||
User name: ${RUN_AS}
|
||||
User uid: $(id -u ${RUN_AS})
|
||||
User gid: $(id -g ${RUN_AS})
|
||||
-------------------------------------
|
||||
"
|
||||
|
||||
export PUID
|
||||
export PGID
|
||||
export RUN_AS
|
Reference in New Issue
Block a user