Standardize scripts, use bash and double brackets
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
/etc/transmission/stop.sh
|
/etc/transmission/stop.sh
|
||||||
[ ! -f /opt/tinyproxy/stop.sh ] || /opt/tinyproxy/stop.sh
|
[[ ! -f /opt/tinyproxy/stop.sh ]] || /opt/tinyproxy/stop.sh
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
/etc/transmission/start.sh "$@"
|
/etc/transmission/start.sh "$@"
|
||||||
[ ! -f /opt/tinyproxy/start.sh ] || /opt/tinyproxy/start.sh
|
[[ ! -f /opt/tinyproxy/start.sh ]] || /opt/tinyproxy/start.sh
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
#! /bin/sh
|
#! /bin/bash
|
||||||
|
|
||||||
export TRANSMISSION_DOWNLOAD_DIR={{ .Env.TRANSMISSION_DOWNLOAD_DIR }}
|
export TRANSMISSION_DOWNLOAD_DIR={{ .Env.TRANSMISSION_DOWNLOAD_DIR }}
|
||||||
export RSS_URL="{{ .Env.RSS_URL }}"
|
export RSS_URL="{{ .Env.RSS_URL }}"
|
@@ -1,9 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
# Ping uses both exit codes 1 and 2. Exit code 2 cannot be used for docker health checks,
|
# Ping uses both exit codes 1 and 2. Exit code 2 cannot be used for docker health checks,
|
||||||
# therefore we use this script to catch error code 2
|
# therefore we use this script to catch error code 2
|
||||||
HOST=$HEALTH_CHECK_HOST
|
HOST=${HEALTH_CHECK_HOST}
|
||||||
|
|
||||||
if [ -z "$HOST" ]
|
if [[ -z "$HOST" ]]
|
||||||
then
|
then
|
||||||
echo "Host not set! Set env 'HEATH_CHECK_HOST'. For now, using default google.com"
|
echo "Host not set! Set env 'HEATH_CHECK_HOST'. For now, using default google.com"
|
||||||
HOST="google.com"
|
HOST="google.com"
|
||||||
@@ -11,7 +11,7 @@ fi
|
|||||||
|
|
||||||
ping -c 1 $HOST
|
ping -c 1 $HOST
|
||||||
STATUS=$?
|
STATUS=$?
|
||||||
if [ $STATUS -ne 0 ]
|
if [[ ${STATUS} -ne 0 ]]
|
||||||
then
|
then
|
||||||
echo "Network is down"
|
echo "Network is down"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -19,4 +19,3 @@ fi
|
|||||||
|
|
||||||
echo "Network is up"
|
echo "Network is up"
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
if [ "${WEBPROXY_ENABLED}" = "true" ]; then
|
if [[ "${WEBPROXY_ENABLED}" = "true" ]]; then
|
||||||
|
|
||||||
/etc/init.d/tinyproxy stop
|
/etc/init.d/tinyproxy stop
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
#! /bin/sh
|
#! /bin/bash
|
||||||
export TRANSMISSION_HOME={{ .Env.TRANSMISSION_HOME }}
|
export TRANSMISSION_HOME={{ .Env.TRANSMISSION_HOME }}
|
||||||
export TRANSMISSION_ALT_SPEED_DOWN={{ .Env.TRANSMISSION_ALT_SPEED_DOWN }}
|
export TRANSMISSION_ALT_SPEED_DOWN={{ .Env.TRANSMISSION_ALT_SPEED_DOWN }}
|
||||||
export TRANSMISSION_ALT_SPEED_ENABLED={{ .Env.TRANSMISSION_ALT_SPEED_ENABLED }}
|
export TRANSMISSION_ALT_SPEED_ENABLED={{ .Env.TRANSMISSION_ALT_SPEED_ENABLED }}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
# Source our persisted env variables from container startup
|
# Source our persisted env variables from container startup
|
||||||
. /etc/transmission/environment-variables.sh
|
. /etc/transmission/environment-variables.sh
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
# This script will be called with tun/tap device name as parameter 1, and local IP as parameter 4
|
# 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)
|
# See https://openvpn.net/index.php/open-source/documentation/manuals/65-openvpn-20x-manpage.html (--up cmd)
|
||||||
echo "Up script executed with $*"
|
echo "Up script executed with $*"
|
||||||
if [ "$4" = "" ]; then
|
if [[ "$4" = "" ]]; then
|
||||||
echo "ERROR, unable to obtain tunnel address"
|
echo "ERROR, unable to obtain tunnel address"
|
||||||
echo "killing $PPID"
|
echo "killing $PPID"
|
||||||
kill -9 $PPID
|
kill -9 $PPID
|
||||||
@@ -14,7 +14,7 @@ if [ "$4" = "" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# If transmission-pre-start.sh exists, run it
|
# If transmission-pre-start.sh exists, run it
|
||||||
if [ -x /scripts/transmission-pre-start.sh ]
|
if [[ -x /scripts/transmission-pre-start.sh ]]
|
||||||
then
|
then
|
||||||
echo "Executing /scripts/transmission-pre-start.sh"
|
echo "Executing /scripts/transmission-pre-start.sh"
|
||||||
/scripts/transmission-pre-start.sh "$@"
|
/scripts/transmission-pre-start.sh "$@"
|
||||||
@@ -24,17 +24,17 @@ fi
|
|||||||
echo "Updating TRANSMISSION_BIND_ADDRESS_IPV4 to the ip of $1 : $4"
|
echo "Updating TRANSMISSION_BIND_ADDRESS_IPV4 to the ip of $1 : $4"
|
||||||
export TRANSMISSION_BIND_ADDRESS_IPV4=$4
|
export TRANSMISSION_BIND_ADDRESS_IPV4=$4
|
||||||
|
|
||||||
if [ "combustion" = "$TRANSMISSION_WEB_UI" ]; then
|
if [[ "combustion" = "$TRANSMISSION_WEB_UI" ]]; then
|
||||||
echo "Using Combustion UI, overriding TRANSMISSION_WEB_HOME"
|
echo "Using Combustion UI, overriding TRANSMISSION_WEB_HOME"
|
||||||
export TRANSMISSION_WEB_HOME=/opt/transmission-ui/combustion-release
|
export TRANSMISSION_WEB_HOME=/opt/transmission-ui/combustion-release
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "kettu" = "$TRANSMISSION_WEB_UI" ]; then
|
if [[ "kettu" = "$TRANSMISSION_WEB_UI" ]]; then
|
||||||
echo "Using Kettu UI, overriding TRANSMISSION_WEB_HOME"
|
echo "Using Kettu UI, overriding TRANSMISSION_WEB_HOME"
|
||||||
export TRANSMISSION_WEB_HOME=/opt/transmission-ui/kettu
|
export TRANSMISSION_WEB_HOME=/opt/transmission-ui/kettu
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "transmission-web-control" = "$TRANSMISSION_WEB_UI" ]; then
|
if [[ "transmission-web-control" = "$TRANSMISSION_WEB_UI" ]]; then
|
||||||
echo "Using Transmission Web Control UI, overriding TRANSMISSION_WEB_HOME"
|
echo "Using Transmission Web Control UI, overriding TRANSMISSION_WEB_HOME"
|
||||||
export TRANSMISSION_WEB_HOME=/opt/transmission-ui/transmission-web-control
|
export TRANSMISSION_WEB_HOME=/opt/transmission-ui/transmission-web-control
|
||||||
fi
|
fi
|
||||||
@@ -47,7 +47,7 @@ dockerize -template /etc/transmission/settings.tmpl:${TRANSMISSION_HOME}/setting
|
|||||||
echo "sed'ing True to true"
|
echo "sed'ing True to true"
|
||||||
sed -i 's/True/true/g' ${TRANSMISSION_HOME}/settings.json
|
sed -i 's/True/true/g' ${TRANSMISSION_HOME}/settings.json
|
||||||
|
|
||||||
if [ ! -e "/dev/random" ]; then
|
if [[ ! -e "/dev/random" ]]; then
|
||||||
# Avoid "Fatal: no entropy gathering module detected" error
|
# Avoid "Fatal: no entropy gathering module detected" error
|
||||||
echo "INFO: /dev/random not found - symlink to /dev/urandom"
|
echo "INFO: /dev/random not found - symlink to /dev/urandom"
|
||||||
ln -s /dev/urandom /dev/random
|
ln -s /dev/urandom /dev/random
|
||||||
@@ -55,7 +55,7 @@ fi
|
|||||||
|
|
||||||
. /etc/transmission/userSetup.sh
|
. /etc/transmission/userSetup.sh
|
||||||
|
|
||||||
if [ "true" = "$DROP_DEFAULT_ROUTE" ]; then
|
if [[ "true" = "$DROP_DEFAULT_ROUTE" ]]; then
|
||||||
echo "DROPPING DEFAULT ROUTE"
|
echo "DROPPING DEFAULT ROUTE"
|
||||||
ip r del default || exit 1
|
ip r del default || exit 1
|
||||||
fi
|
fi
|
||||||
@@ -63,11 +63,11 @@ fi
|
|||||||
echo "STARTING TRANSMISSION"
|
echo "STARTING TRANSMISSION"
|
||||||
exec su --preserve-environment ${RUN_AS} -s /bin/bash -c "/usr/bin/transmission-daemon -g ${TRANSMISSION_HOME} --logfile ${TRANSMISSION_HOME}/transmission.log" &
|
exec su --preserve-environment ${RUN_AS} -s /bin/bash -c "/usr/bin/transmission-daemon -g ${TRANSMISSION_HOME} --logfile ${TRANSMISSION_HOME}/transmission.log" &
|
||||||
|
|
||||||
if [ "$OPENVPN_PROVIDER" = "PIA" ]
|
if [[ "$OPENVPN_PROVIDER" = "PIA" ]]
|
||||||
then
|
then
|
||||||
echo "CONFIGURING PORT FORWARDING"
|
echo "CONFIGURING PORT FORWARDING"
|
||||||
exec /etc/transmission/updatePort.sh &
|
exec /etc/transmission/updatePort.sh &
|
||||||
elif [ "$OPENVPN_PROVIDER" = "PERFECTPRIVACY" ]
|
elif [[ "$OPENVPN_PROVIDER" = "PERFECTPRIVACY" ]]
|
||||||
then
|
then
|
||||||
echo "CONFIGURING PORT FORWARDING"
|
echo "CONFIGURING PORT FORWARDING"
|
||||||
exec /etc/transmission/updatePPPort.sh ${TRANSMISSION_BIND_ADDRESS_IPV4} &
|
exec /etc/transmission/updatePPPort.sh ${TRANSMISSION_BIND_ADDRESS_IPV4} &
|
||||||
@@ -76,7 +76,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# If transmission-post-start.sh exists, run it
|
# If transmission-post-start.sh exists, run it
|
||||||
if [ -x /scripts/transmission-post-start.sh ]
|
if [[ -x /scripts/transmission-post-start.sh ]]
|
||||||
then
|
then
|
||||||
echo "Executing /scripts/transmission-post-start.sh"
|
echo "Executing /scripts/transmission-post-start.sh"
|
||||||
/scripts/transmission-post-start.sh "$@"
|
/scripts/transmission-post-start.sh "$@"
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
#! /bin/sh
|
#! /bin/bash
|
||||||
|
|
||||||
# If transmission-pre-stop.sh exists, run it
|
# If transmission-pre-stop.sh exists, run it
|
||||||
if [ -x /scripts/transmission-pre-stop.sh ]
|
if [[ -x /scripts/transmission-pre-stop.sh ]]
|
||||||
then
|
then
|
||||||
echo "Executing /scripts/transmission-pre-stop.sh"
|
echo "Executing /scripts/transmission-pre-stop.sh"
|
||||||
/scripts/transmission-pre-stop.sh "$@"
|
/scripts/transmission-pre-stop.sh "$@"
|
||||||
@@ -11,7 +11,7 @@ fi
|
|||||||
kill $(pidof transmission-daemon)
|
kill $(pidof transmission-daemon)
|
||||||
|
|
||||||
# If transmission-post-stop.sh exists, run it
|
# If transmission-post-stop.sh exists, run it
|
||||||
if [ -x /scripts/transmission-post-stop.sh ]
|
if [[ -x /scripts/transmission-post-stop.sh ]]
|
||||||
then
|
then
|
||||||
echo "Executing /scripts/transmission-post-stop.sh"
|
echo "Executing /scripts/transmission-post-stop.sh"
|
||||||
/scripts/transmission-post-stop.sh "$@"
|
/scripts/transmission-post-stop.sh "$@"
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
#! /bin/sh
|
#! /bin/bash
|
||||||
|
|
||||||
echo "Wait for tunnel to be fully initialized and PIA is ready to give us a port"
|
echo "Wait for tunnel to be fully initialized and PIA is ready to give us a port"
|
||||||
sleep 15
|
sleep 15
|
||||||
@@ -9,8 +9,8 @@ sleep 15
|
|||||||
# Settings
|
# Settings
|
||||||
TRANSMISSION_PASSWD_FILE=/config/transmission-credentials.txt
|
TRANSMISSION_PASSWD_FILE=/config/transmission-credentials.txt
|
||||||
|
|
||||||
transmission_username=$(head -1 $TRANSMISSION_PASSWD_FILE)
|
transmission_username=$(head -1 ${TRANSMISSION_PASSWD_FILE})
|
||||||
transmission_passwd=$(tail -1 $TRANSMISSION_PASSWD_FILE)
|
transmission_passwd=$(tail -1 ${TRANSMISSION_PASSWD_FILE})
|
||||||
pia_client_id_file=/etc/transmission/pia_client_id
|
pia_client_id_file=/etc/transmission/pia_client_id
|
||||||
transmission_settings_file=${TRANSMISSION_HOME}/settings.json
|
transmission_settings_file=${TRANSMISSION_HOME}/settings.json
|
||||||
|
|
||||||
@@ -19,11 +19,11 @@ transmission_settings_file=${TRANSMISSION_HOME}/settings.json
|
|||||||
#
|
#
|
||||||
|
|
||||||
new_client_id() {
|
new_client_id() {
|
||||||
head -n 100 /dev/urandom | sha256sum | tr -d " -" | tee $pia_client_id_file
|
head -n 100 /dev/urandom | sha256sum | tr -d " -" | tee ${pia_client_id_file}
|
||||||
}
|
}
|
||||||
|
|
||||||
pia_client_id="$(cat $pia_client_id_file 2>/dev/null)"
|
pia_client_id="$(cat ${pia_client_id_file} 2>/dev/null)"
|
||||||
if [ -z "${pia_client_id}" ]; then
|
if [[ -z "${pia_client_id}" ]]; then
|
||||||
echo "Generating new client id for PIA"
|
echo "Generating new client id for PIA"
|
||||||
pia_client_id=$(new_client_id)
|
pia_client_id=$(new_client_id)
|
||||||
fi
|
fi
|
||||||
@@ -33,26 +33,26 @@ port_assignment_url="http://209.222.18.222:2000/?client_id=$pia_client_id"
|
|||||||
pia_response=$(curl -s -f "$port_assignment_url")
|
pia_response=$(curl -s -f "$port_assignment_url")
|
||||||
pia_curl_exit_code=$?
|
pia_curl_exit_code=$?
|
||||||
|
|
||||||
if [ -z "$pia_response" ]; then
|
if [[ -z "$pia_response" ]]; then
|
||||||
echo "Port forwarding is already activated on this connection, has expired, or you are not connected to a PIA region that supports port forwarding"
|
echo "Port forwarding is already activated on this connection, has expired, or you are not connected to a PIA region that supports port forwarding"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check for curl error (curl will fail on HTTP errors with -f flag)
|
# Check for curl error (curl will fail on HTTP errors with -f flag)
|
||||||
if [ $pia_curl_exit_code -ne 0 ]; then
|
if [[ ${pia_curl_exit_code} -ne 0 ]]; then
|
||||||
echo "curl encountered an error looking up new port: $pia_curl_exit_code"
|
echo "curl encountered an error looking up new port: $pia_curl_exit_code"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check for errors in PIA response
|
# Check for errors in PIA response
|
||||||
error=$(echo "$pia_response" | grep -oE "\"error\".*\"")
|
error=$(echo "$pia_response" | grep -oE "\"error\".*\"")
|
||||||
if [ ! -z "$error" ]; then
|
if [[ ! -z "$error" ]]; then
|
||||||
echo "PIA returned an error: $error"
|
echo "PIA returned an error: $error"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get new port, check if empty
|
# Get new port, check if empty
|
||||||
new_port=$(echo "$pia_response" | grep -oE "[0-9]+")
|
new_port=$(echo "$pia_response" | grep -oE "[0-9]+")
|
||||||
if [ -z "$new_port" ]; then
|
if [[ -z "$new_port" ]]; then
|
||||||
echo "Could not find new port from PIA"
|
echo "Could not find new port from PIA"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
@@ -65,7 +65,7 @@ echo "Got new port $new_port from PIA"
|
|||||||
# Check if transmission remote is set up with authentication
|
# Check if transmission remote is set up with authentication
|
||||||
auth_enabled=$(grep 'rpc-authentication-required\"' "$transmission_settings_file" \
|
auth_enabled=$(grep 'rpc-authentication-required\"' "$transmission_settings_file" \
|
||||||
| grep -oE 'true|false')
|
| grep -oE 'true|false')
|
||||||
if [ "true" = "$auth_enabled" ]
|
if [[ "true" = "$auth_enabled" ]]
|
||||||
then
|
then
|
||||||
echo "transmission auth required"
|
echo "transmission auth required"
|
||||||
myauth="--auth $transmission_username:$transmission_passwd"
|
myauth="--auth $transmission_username:$transmission_passwd"
|
||||||
@@ -76,8 +76,8 @@ fi
|
|||||||
|
|
||||||
# get current listening port
|
# get current listening port
|
||||||
transmission_peer_port=$(transmission-remote $myauth -si | grep Listenport | grep -oE '[0-9]+')
|
transmission_peer_port=$(transmission-remote $myauth -si | grep Listenport | grep -oE '[0-9]+')
|
||||||
if [ "$new_port" != "$transmission_peer_port" ]; then
|
if [[ "$new_port" != "$transmission_peer_port" ]]; then
|
||||||
if [ "true" = "$ENABLE_UFW" ]; then
|
if [[ "true" = "$ENABLE_UFW" ]]; then
|
||||||
echo "Update UFW rules before changing port in Transmission"
|
echo "Update UFW rules before changing port in Transmission"
|
||||||
|
|
||||||
echo "denying access to $transmission_peer_port"
|
echo "denying access to $transmission_peer_port"
|
||||||
@@ -87,11 +87,11 @@ if [ "$new_port" != "$transmission_peer_port" ]; then
|
|||||||
ufw allow "$new_port"
|
ufw allow "$new_port"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
transmission-remote $myauth -p "$new_port"
|
transmission-remote ${myauth} -p "$new_port"
|
||||||
|
|
||||||
echo "Checking port..."
|
echo "Checking port..."
|
||||||
sleep 10
|
sleep 10
|
||||||
transmission-remote $myauth -pt
|
transmission-remote ${myauth} -pt
|
||||||
else
|
else
|
||||||
echo "No action needed, port hasn't changed"
|
echo "No action needed, port hasn't changed"
|
||||||
fi
|
fi
|
||||||
|
Reference in New Issue
Block a user