From 0e4f1da9ce0c7b5284e1c750d311929920eb3212 Mon Sep 17 00:00:00 2001 From: Kristian Haugene Date: Sun, 16 Nov 2014 14:19:56 +0100 Subject: [PATCH] now passing configuration to container by mounting /config --- Dockerfile | 5 +++-- piaconfig/config.ovpn | 2 +- piaconfig/credentials.txt | 2 -- ...sionSettings.json => defaultSettings.json} | 0 transmission/run.sh | 10 +++++++++- transmission/updateTransmissionPort.sh | 20 ++++++++++++++----- 6 files changed, 28 insertions(+), 11 deletions(-) delete mode 100644 piaconfig/credentials.txt rename transmission/{transmissionSettings.json => defaultSettings.json} (100%) diff --git a/Dockerfile b/Dockerfile index ff895f7..d6e33ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,13 +35,14 @@ ADD transmission/runUpdates.sh /etc/service/portupdater/run RUN mkdir -p /etc/service/openvpn/ ADD runOpenVpn.sh /etc/service/openvpn/run +VOLUME /config + # Add configuration and scripts ADD piaconfig/config.ovpn /etc/openvpn/config.ovpn -ADD piaconfig/credentials.txt /etc/openvpn/credentials.txt ADD piaconfig/ca.crt /etc/openvpn/ca.crt ADD piaconfig/crl.pem /etc/openvpn/crl.pem ADD runOpenVpn.sh /etc/openvpn/start.sh -ADD transmission/transmissionSettings.json /etc/transmission-daemon/settings.json +ADD transmission/defaultSettings.json /etc/transmission-daemon/settings.json ADD transmission/updateTransmissionPort.sh /etc/transmission-daemon/updatePort.sh ADD transmission/periodicUpdates.sh /etc/transmission-daemon/periodicUpdates.sh diff --git a/piaconfig/config.ovpn b/piaconfig/config.ovpn index 84fdf05..0529277 100644 --- a/piaconfig/config.ovpn +++ b/piaconfig/config.ovpn @@ -9,7 +9,7 @@ persist-tun ca /etc/openvpn/ca.crt tls-client remote-cert-tls server -auth-user-pass /etc/openvpn/credentials.txt +auth-user-pass /config/pia-credentials.txt comp-lzo verb 1 reneg-sec 0 diff --git a/piaconfig/credentials.txt b/piaconfig/credentials.txt deleted file mode 100644 index f0560e8..0000000 --- a/piaconfig/credentials.txt +++ /dev/null @@ -1,2 +0,0 @@ -your-pia-username -your-pia-password diff --git a/transmission/transmissionSettings.json b/transmission/defaultSettings.json similarity index 100% rename from transmission/transmissionSettings.json rename to transmission/defaultSettings.json diff --git a/transmission/run.sh b/transmission/run.sh index 0231457..0853b83 100755 --- a/transmission/run.sh +++ b/transmission/run.sh @@ -1,2 +1,10 @@ #!/bin/sh -exec /usr/bin/transmission-daemon -f -g /etc/transmission-daemon/ + +if [ -f /config/transmission/settings.json ]; +then + echo "STARTING TRANSMISSION: Using custom config directory /config/transmission" + exec /usr/bin/transmission-daemon -f -g /config/transmission/ +else + echo "STARTING TRANSMISSION: No configuration provided, using defaults" + exec /usr/bin/transmission-daemon -f -g /etc/transmission-daemon/ +fi diff --git a/transmission/updateTransmissionPort.sh b/transmission/updateTransmissionPort.sh index 0fec580..bcaedf7 100755 --- a/transmission/updateTransmissionPort.sh +++ b/transmission/updateTransmissionPort.sh @@ -1,15 +1,25 @@ #/bin/bash # Settings -PIA_PASSWD_FILE=/etc/openvpn/credentials.txt +PIA_PASSWD_FILE=/config/pia-credentials.txt +TRANSMISSION_PASSWD_FILE=/config/transmission-credentials.txt -username=$(head -1 $PIA_PASSWD_FILE) -passwd=$(tail -1 $PIA_PASSWD_FILE) +pia_username=$(head -1 $PIA_PASSWD_FILE) +pia_passwd=$(tail -1 $PIA_PASSWD_FILE) +transmission_username=$(head -1 $TRANSMISSION_PASSWD_FILE) +transmission_passwd=$(tail -1 $TRANSMISSION_PASSWD_FILE) local_vpn_ip=$(ip addr show tun0 | grep inet | awk '{ print $2 }') pia_client_id_file=/etc/transmission-daemon/pia_client_id transmission_settings_file=/etc/transmission-daemon/settings.json port_assignment_url=https://www.privateinternetaccess.com/vpninfo/port_forward_assignment +if [ -f /config/transmission/settings.json ]; +then + transmission_settings_file=/config/transmission/settings.json +else + transmission_settings_file=/etc/transmission-daemon/settings.json +fi + # # First get a port from PIA # @@ -25,7 +35,7 @@ if [[ -z "$pia_client_id" ]]; then fi # Get the port -pia_response=$(curl -d "user=$username&pass=$passwd&client_id=$pia_client_id&local_ip=$local_vpn_ip" $port_assignment_url) +pia_response=$(curl -d "user=$pia_username&pass=$pia_passwd&client_id=$pia_client_id&local_ip=$local_vpn_ip" $port_assignment_url) new_port=$(echo $pia_response | grep -oE "[0-9]+") echo "Got new port $new_port from pia" @@ -39,7 +49,7 @@ auth_enabled=$(grep 'rpc-authentication-required\"' $transmission_settings_file if [[ "true" = "$auth_enabled" ]] then echo "transmission auth required" - myauth="--auth username:password" + myauth="--auth $transmission_username:$transmission_passwd" else echo "transmission auth not required" myauth=""