From d86c45d52aacfe794eed0a0a9ea6878add6c2c69 Mon Sep 17 00:00:00 2001 From: Jean-Francois Date: Wed, 28 Dec 2016 16:54:07 +0100 Subject: [PATCH] Add RPC Password Generates a RPC password and saves it as a setting. If no RPC password is present (previous versions), generates one and saves it as a setting as well. --- conf/settings.json | 2 +- scripts/install | 8 ++++++++ scripts/upgrade | 15 +++++++++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/conf/settings.json b/conf/settings.json index a5ce1dd..72b062b 100644 --- a/conf/settings.json +++ b/conf/settings.json @@ -45,7 +45,7 @@ "rpc-authentication-required": false, "rpc-bind-address": "127.0.0.1", "rpc-enabled": true, - "rpc-password": "{22ef1abe361f619946cf9ce68c442d27f73512d5lL3qJ6bY", + "rpc-password": "RPCPASSWORDTOCHANGE", "rpc-port": 9091, "rpc-url": "PATHTOCHANGE/transmission/", "rpc-username": "transmission", diff --git a/scripts/install b/scripts/install index 44d8c2d..0a19aa3 100644 --- a/scripts/install +++ b/scripts/install @@ -6,6 +6,9 @@ set -eu # Get app instance name app=$YNH_APP_INSTANCE_NAME +# Source app helpers +. /usr/share/yunohost/helpers + # Retrieve arguments domain=$YNH_APP_ARG_DOMAIN path=$YNH_APP_ARG_PATH @@ -41,7 +44,12 @@ sudo chown -R debian-transmission:debian-transmission /home/yunohost.transmissio sudo find /home/yunohost.transmission/ -type f | while read LINE; do sudo chmod 640 "$LINE" ; done sudo find /home/yunohost.transmission/ -type d | while read LINE; do sudo chmod 750 "$LINE" ; done +# Create RPC password +rpcpassword=$(ynh_string_random) +ynh_app_setting_set "$app" rpcpassword "$rpcpassword" + # Configure Transmission and reload +sed -i "s@RPCPASSWORDTOCHANGE@$rpcpassword@g" ../conf/settings.json sed -i "s@PATHTOCHANGE@$path@g" ../conf/settings.json sudo cp ../conf/settings.json /etc/transmission-daemon/settings.json sudo service transmission-daemon reload diff --git a/scripts/upgrade b/scripts/upgrade index 6f26b67..51131be 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -6,9 +6,13 @@ set -eu # Get app instance name app=$YNH_APP_INSTANCE_NAME +# Source app helpers +. /usr/share/yunohost/helpers + # Retrieve arguments -domain=$(sudo yunohost app setting "$app" domain) -path=$(sudo yunohost app setting "$app" path) +domain=$(ynh_app_setting_get "$app" domain) +path=$(ynh_app_setting_get "$app" path) +rpcpassword=$(ynh_app_setting_get "$app" rpcpassword) # Remove trailing "/" for next commands path=${path%/} @@ -26,7 +30,14 @@ sudo chown -R debian-transmission:debian-transmission /home/yunohost.transmissio sudo find /home/yunohost.transmission/ -type f | while read LINE; do sudo chmod 640 "$LINE" ; done sudo find /home/yunohost.transmission/ -type d | while read LINE; do sudo chmod 750 "$LINE" ; done +# Create RPC password if none exists +if [ -z "$rpcpassword" ]; then + rpcpassword=$(ynh_string_random) + ynh_app_setting_set "$app" rpcpassword "$rpcpassword" +fi + # Configure Transmission and reload +sed -i "s@RPCPASSWORDTOCHANGE@$rpcpassword@g" ../conf/settings.json sed -i "s@PATHTOCHANGE@$path@g" ../conf/settings.json sudo cp ../conf/settings.json /etc/transmission-daemon/settings.json sudo service transmission-daemon reload