From 14bbf2cf49e32afcdb07edc80105deae025c4461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Wed, 6 Dec 2023 11:25:05 +0100 Subject: [PATCH] Also store the password hash on upgrade --- scripts/_common.sh | 21 +++++++++++++++++++++ scripts/upgrade | 2 ++ 2 files changed, 23 insertions(+) diff --git a/scripts/_common.sh b/scripts/_common.sh index f563916..dfb9f1c 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -30,6 +30,27 @@ _wait_and_save_rcp_password_hash() { return 1 } + +_save_and_revert_rpc_password_hash_to_password() { + # This one is tricky : + # * transmission did password -> hash (we want to store hash) + # * user might have overrided other settings, we want to save them + # * we don't want false positives about user editing, so we revert the password change + # * in upgrade script, we will then re-write the saved password hash. + + password_hash=$(jq -r '.["rpc-password"]' "$SETTINGS_FILE") + if [[ "$rpcpassword" == "$password_hash" ]]; then + # Upgrade already did this, exiting + return + fi + + ynh_app_setting_set --app="$app" --key="rpcpassword" --value="$password_hash" + + # Revert the change to maybe prevent ynh_backup_if_checksum_is_different to trigger + sed -i "s|\"${password_hash}\"|\"${rpcpassword}\"|" "$SETTINGS_FILE" +} + + #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 17c5f47..4e94bb5 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -44,6 +44,8 @@ else path_less="$path" fi +_save_and_revert_rpc_password_hash_to_password + ynh_add_config --template="../conf/settings.json" --destination="$SETTINGS_FILE" chmod 400 "$SETTINGS_FILE"