From 806bfaf4b4ba8a656ad24dd4cca7dc83eb49f87e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Wed, 6 Dec 2023 10:44:01 +0100 Subject: [PATCH] Transmission edits its settings file to save the hashed password, let's save it. --- scripts/_common.sh | 20 ++++++++++++++++++++ scripts/install | 8 +++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index ce07a20..f563916 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -10,6 +10,26 @@ SETTINGS_FILE="/etc/transmission-daemon/settings.json" # PERSONAL HELPERS #================================================= +_wait_and_save_rcp_password_hash() { + # Transmission first reads the plaintext password in the config, then + # computes a cryptographic hash and rewrites the config file. + + for ((i=0;i<10;i++)); do + pass=$(jq -r '.["rpc-password"]' "$SETTINGS_FILE") + if [[ "$pass" == "{"* ]]; then + # Save the hashed password + ynh_app_setting_set --app="$app" --key="rpcpassword" --value="$pass" + # Save the edited settings file + ynh_store_file_checksum --file="$SETTINGS_FILE" + return + fi + sleep 1 + done + + echo "Timeout! Transmission did not save a cryptographic hash of the password in 10 seconds!" + return 1 +} + #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/install b/scripts/install index 93f79ba..8e40ac7 100644 --- a/scripts/install +++ b/scripts/install @@ -14,7 +14,6 @@ source /usr/share/yunohost/helpers #================================================= rpcpassword=$(ynh_string_random) -ynh_app_setting_set --app=$app --key=rpcpassword --value="$rpcpassword" #================================================= # SPECIFIC SETUP @@ -107,6 +106,13 @@ ynh_script_progression --message="Starting a systemd service..." # Start a systemd service ynh_systemd_action --service_name=transmission-daemon --action="start" --log_path="systemd" +#================================================= +# RETRIEVE HASHED PASSWORD +#================================================= +ynh_script_progression --message="Saving the encrypted password..." + +_wait_and_save_rcp_password_hash + #================================================= # END OF SCRIPT #=================================================