persist env variables on startup. conform to /bin/sh

This commit is contained in:
Kristian Haugene 2015-05-24 20:40:25 +02:00
parent 0d918b22f9
commit 8a3a0b30e9
6 changed files with 86 additions and 4 deletions

View File

@ -27,6 +27,7 @@ ADD transmission/periodicUpdates.sh /etc/transmission-daemon/periodicUpdates.sh
ADD transmission/start.sh /etc/transmission-daemon/start.sh
ADD transmission/runUpdates.sh /etc/transmission-daemon/startPortUpdates.sh
ADD transmission/down.sh /etc/transmission-daemon/stop.sh
ADD transmission/environment-variables.tmpl /etc/transmission-daemon/environment-variables.tmpl
ADD start.sh /etc/openvpn/start.sh
ENV PIA_USERNAME=**None** \
@ -38,6 +39,7 @@ ENV PIA_USERNAME=**None** \
"TRANSMISSION_ALT_SPEED_TIME_ENABLED=false" \
"TRANSMISSION_ALT_SPEED_TIME_END=1020" \
"TRANSMISSION_ALT_SPEED_UP=50" \
"TRANSMISSION_BIND_ADDRESS_IPV4=0.0.0.0" \
"TRANSMISSION_BIND_ADDRESS_IPV6=::" \
"TRANSMISSION_BLOCKLIST_ENABLED=false" \
"TRANSMISSION_BLOCKLIST_URL=http://www.example.com/blocklist" \

View File

@ -38,4 +38,7 @@ fi
echo $TRANSMISSION_RPC_USERNAME > /config/transmission-credentials.txt
echo $TRANSMISSION_RPC_PASSWORD >> /config/transmission-credentials.txt
# Persist transmission settings for use by transmission-daemon
dockerize -template /etc/transmission-daemon/environment-variables.tmpl:/etc/transmission-daemon/environment-variables.sh /bin/true
exec openvpn --config "$OPEN_VPN_CONFIG"

View File

@ -6,7 +6,7 @@
"alt-speed-time-enabled": {{ .Env.TRANSMISSION_ALT_SPEED_TIME_ENABLED }},
"alt-speed-time-end": {{ .Env.TRANSMISSION_ALT_SPEED_TIME_END }},
"alt-speed-up": {{ .Env.TRANSMISSION_ALT_SPEED_UP }},
"bind-address-ipv4": "!!BINDIPV4!!",
"bind-address-ipv4": "{{ .Env.TRANSMISSION_BIND_ADDRESS_IPV4 }}",
"bind-address-ipv6": "{{ .Env.TRANSMISSION_BIND_ADDRESS_IPV6 }}",
"blocklist-enabled": {{ .Env.TRANSMISSION_BLOCKLIST_ENABLED }},
"blocklist-url": "{{ .Env.TRANSMISSION_BLOCKLIST_URL }}",

View File

@ -0,0 +1,74 @@
#! /bin/sh
export TRANSMISSION_ALT_SPEED_DOWN={{ .Env.TRANSMISSION_ALT_SPEED_DOWN }}
export TRANSMISSION_ALT_SPEED_ENABLED={{ .Env.TRANSMISSION_ALT_SPEED_ENABLED }}
export TRANSMISSION_ALT_SPEED_TIME_BEGIN={{ .Env.TRANSMISSION_ALT_SPEED_TIME_BEGIN }}
export TRANSMISSION_ALT_SPEED_TIME_DAY={{ .Env.TRANSMISSION_ALT_SPEED_TIME_DAY }}
export TRANSMISSION_ALT_SPEED_TIME_ENABLED={{ .Env.TRANSMISSION_ALT_SPEED_TIME_ENABLED }}
export TRANSMISSION_ALT_SPEED_TIME_END={{ .Env.TRANSMISSION_ALT_SPEED_TIME_END }}
export TRANSMISSION_ALT_SPEED_UP={{ .Env.TRANSMISSION_ALT_SPEED_UP }}
export TRANSMISSION_BIND_ADDRESS_IPV4={{ .Env.TRANSMISSION_BIND_ADDRESS_IPV4 }}
export TRANSMISSION_BIND_ADDRESS_IPV6={{ .Env.TRANSMISSION_BIND_ADDRESS_IPV6 }}
export TRANSMISSION_BLOCKLIST_ENABLED={{ .Env.TRANSMISSION_BLOCKLIST_ENABLED }}
export TRANSMISSION_BLOCKLIST_URL={{ .Env.TRANSMISSION_BLOCKLIST_URL }}
export TRANSMISSION_CACHE_SIZE_MB={{ .Env.TRANSMISSION_CACHE_SIZE_MB }}
export TRANSMISSION_DHT_ENABLED={{ .Env.TRANSMISSION_DHT_ENABLED }}
export TRANSMISSION_DOWNLOAD_DIR={{ .Env.TRANSMISSION_DOWNLOAD_DIR }}
export TRANSMISSION_DOWNLOAD_LIMIT={{ .Env.TRANSMISSION_DOWNLOAD_LIMIT }}
export TRANSMISSION_DOWNLOAD_LIMIT_ENABLED={{ .Env.TRANSMISSION_DOWNLOAD_LIMIT_ENABLED }}
export TRANSMISSION_DOWNLOAD_QUEUE_ENABLED={{ .Env.TRANSMISSION_DOWNLOAD_QUEUE_ENABLED }}
export TRANSMISSION_DOWNLOAD_QUEUE_SIZE={{ .Env.TRANSMISSION_DOWNLOAD_QUEUE_SIZE }}
export TRANSMISSION_ENCRYPTION={{ .Env.TRANSMISSION_ENCRYPTION }}
export TRANSMISSION_IDLE_SEEDING_LIMIT={{ .Env.TRANSMISSION_IDLE_SEEDING_LIMIT }}
export TRANSMISSION_IDLE_SEEDING_LIMIT_ENABLED={{ .Env.TRANSMISSION_IDLE_SEEDING_LIMIT_ENABLED }}
export TRANSMISSION_INCOMPLETE_DIR={{ .Env.TRANSMISSION_INCOMPLETE_DIR }}
export TRANSMISSION_INCOMPLETE_DIR_ENABLED={{ .Env.TRANSMISSION_INCOMPLETE_DIR_ENABLED }}
export TRANSMISSION_LPD_ENABLED={{ .Env.TRANSMISSION_LPD_ENABLED }}
export TRANSMISSION_MAX_PEERS_GLOBAL={{ .Env.TRANSMISSION_MAX_PEERS_GLOBAL }}
export TRANSMISSION_MESSAGE_LEVEL={{ .Env.TRANSMISSION_MESSAGE_LEVEL }}
export TRANSMISSION_PEER_CONGESTION_ALGORITHM={{ .Env.TRANSMISSION_PEER_CONGESTION_ALGORITHM }}
export TRANSMISSION_PEER_ID_TTL_HOURS={{ .Env.TRANSMISSION_PEER_ID_TTL_HOURS }}
export TRANSMISSION_PEER_LIMIT_GLOBAL={{ .Env.TRANSMISSION_PEER_LIMIT_GLOBAL }}
export TRANSMISSION_PEER_LIMIT_PER_TORRENT={{ .Env.TRANSMISSION_PEER_LIMIT_PER_TORRENT }}
export TRANSMISSION_PEER_PORT={{ .Env.TRANSMISSION_PEER_PORT }}
export TRANSMISSION_PEER_PORT_RANDOM_HIGH={{ .Env.TRANSMISSION_PEER_PORT_RANDOM_HIGH }}
export TRANSMISSION_PEER_PORT_RANDOM_LOW={{ .Env.TRANSMISSION_PEER_PORT_RANDOM_LOW }}
export TRANSMISSION_PEER_PORT_RANDOM_ON_START={{ .Env.TRANSMISSION_PEER_PORT_RANDOM_ON_START }}
export TRANSMISSION_PEER_SOCKET_TOS={{ .Env.TRANSMISSION_PEER_SOCKET_TOS }}
export TRANSMISSION_PEX_ENABLED={{ .Env.TRANSMISSION_PEX_ENABLED }}
export TRANSMISSION_PORT_FORWARDING_ENABLED={{ .Env.TRANSMISSION_PORT_FORWARDING_ENABLED }}
export TRANSMISSION_PREALLOCATION={{ .Env.TRANSMISSION_PREALLOCATION }}
export TRANSMISSION_PREFETCH_ENABLED={{ .Env.TRANSMISSION_PREFETCH_ENABLED }}
export TRANSMISSION_QUEUE_STALLED_ENABLED={{ .Env.TRANSMISSION_QUEUE_STALLED_ENABLED }}
export TRANSMISSION_QUEUE_STALLED_MINUTES={{ .Env.TRANSMISSION_QUEUE_STALLED_MINUTES }}
export TRANSMISSION_RATIO_LIMIT={{ .Env.TRANSMISSION_RATIO_LIMIT }}
export TRANSMISSION_RATIO_LIMIT_ENABLED={{ .Env.TRANSMISSION_RATIO_LIMIT_ENABLED }}
export TRANSMISSION_RENAME_PARTIAL_FILES={{ .Env.TRANSMISSION_RENAME_PARTIAL_FILES }}
export TRANSMISSION_RPC_AUTHENTICATION_REQUIRED={{ .Env.TRANSMISSION_RPC_AUTHENTICATION_REQUIRED }}
export TRANSMISSION_RPC_BIND_ADDRESS={{ .Env.TRANSMISSION_RPC_BIND_ADDRESS }}
export TRANSMISSION_RPC_ENABLED={{ .Env.TRANSMISSION_RPC_ENABLED }}
export TRANSMISSION_RPC_PASSWORD={{ .Env.TRANSMISSION_RPC_PASSWORD }}
export TRANSMISSION_RPC_PORT={{ .Env.TRANSMISSION_RPC_PORT }}
export TRANSMISSION_RPC_URL={{ .Env.TRANSMISSION_RPC_URL }}
export TRANSMISSION_RPC_USERNAME={{ .Env.TRANSMISSION_RPC_USERNAME }}
export TRANSMISSION_RPC_WHITELIST={{ .Env.TRANSMISSION_RPC_WHITELIST }}
export TRANSMISSION_RPC_WHITELIST_ENABLED={{ .Env.TRANSMISSION_RPC_WHITELIST_ENABLED }}
export TRANSMISSION_SCRAPE_PAUSED_TORRENTS_ENABLED={{ .Env.TRANSMISSION_SCRAPE_PAUSED_TORRENTS_ENABLED }}
export TRANSMISSION_SCRIPT_TORRENT_DONE_ENABLED={{ .Env.TRANSMISSION_SCRIPT_TORRENT_DONE_ENABLED }}
export TRANSMISSION_SCRIPT_TORRENT_DONE_FILENAME={{ .Env.TRANSMISSION_SCRIPT_TORRENT_DONE_FILENAME }}
export TRANSMISSION_SEED_QUEUE_ENABLED={{ .Env.TRANSMISSION_SEED_QUEUE_ENABLED }}
export TRANSMISSION_SEED_QUEUE_SIZE={{ .Env.TRANSMISSION_SEED_QUEUE_SIZE }}
export TRANSMISSION_SPEED_LIMIT_DOWN={{ .Env.TRANSMISSION_SPEED_LIMIT_DOWN }}
export TRANSMISSION_SPEED_LIMIT_DOWN_ENABLED={{ .Env.TRANSMISSION_SPEED_LIMIT_DOWN_ENABLED }}
export TRANSMISSION_SPEED_LIMIT_UP={{ .Env.TRANSMISSION_SPEED_LIMIT_UP }}
export TRANSMISSION_SPEED_LIMIT_UP_ENABLED={{ .Env.TRANSMISSION_SPEED_LIMIT_UP_ENABLED }}
export TRANSMISSION_START_ADDED_TORRENTS={{ .Env.TRANSMISSION_START_ADDED_TORRENTS }}
export TRANSMISSION_TRASH_ORIGINAL_TORRENT_FILES={{ .Env.TRANSMISSION_TRASH_ORIGINAL_TORRENT_FILES }}
export TRANSMISSION_UMASK={{ .Env.TRANSMISSION_UMASK }}
export TRANSMISSION_UPLOAD_LIMIT={{ .Env.TRANSMISSION_UPLOAD_LIMIT }}
export TRANSMISSION_UPLOAD_LIMIT_ENABLED={{ .Env.TRANSMISSION_UPLOAD_LIMIT_ENABLED }}
export TRANSMISSION_UPLOAD_SLOTS_PER_TORRENT={{ .Env.TRANSMISSION_UPLOAD_SLOTS_PER_TORRENT }}
export TRANSMISSION_UTP_ENABLED={{ .Env.TRANSMISSION_UTP_ENABLED }}
export TRANSMISSION_WATCH_DIR={{ .Env.TRANSMISSION_WATCH_DIR }}
export TRANSMISSION_WATCH_DIR_ENABLED={{ .Env.TRANSMISSION_WATCH_DIR_ENABLED }}

View File

@ -1,5 +1,8 @@
#!/bin/sh
# Source our persisted env variables from container startup
. /etc/transmission-daemon/environment-variables.sh
tun0ip=$(ifconfig tun0 | sed -n '2 p' | awk '{print $2}' | cut -d: -f2)
echo "Updating TRANSMISSION_BIND_ADDRESS_IPV4 to tun0 ip: ${tun0ip}"
export TRANSMISSION_BIND_ADDRESS_IPV4=${tun0ip}

View File

@ -22,7 +22,7 @@ new_client_id() {
}
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"
pia_client_id=$(new_client_id)
fi
@ -39,7 +39,7 @@ echo "Got new port $new_port from pia"
# Check if transmission remote is set up with authentication
auth_enabled=$(grep 'rpc-authentication-required\"' $transmission_settings_file | grep -oE 'true|false')
if [[ "true" = "$auth_enabled" ]]
if [ "true" = "$auth_enabled" ]
then
echo "transmission auth required"
myauth="--auth $transmission_username:$transmission_passwd"
@ -50,7 +50,7 @@ fi
# get current listening port
transmission_peer_port=$(transmission-remote $myauth -si | grep Listenport | grep -oE '[0-9]+')
if [[ "$new_port" != "$transmission_peer_port" ]]
if [ "$new_port" != "$transmission_peer_port" ]
then
transmission-remote $myauth -p "$new_port"
echo "Checking port..."