1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/transmission_ynh.git synced 2024-09-04 01:46:12 +02:00
transmission_ynh/scripts/_common.sh

61 lines
2 KiB
Bash
Raw Permalink Normal View History

2017-06-13 23:37:51 +02:00
#!/bin/bash
2017-06-18 15:57:00 +02:00
#=================================================
2019-05-01 13:24:56 +02:00
# COMMON VARIABLES
2017-06-18 15:57:00 +02:00
#=================================================
SETTINGS_FILE="/etc/transmission-daemon/settings.json"
2019-05-01 13:24:56 +02:00
#=================================================
# 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
}
_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"
}
2019-05-01 13:24:56 +02:00
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
2017-06-13 23:37:51 +02:00
#=================================================
2019-05-01 13:24:56 +02:00
# FUTURE OFFICIAL HELPERS
2017-06-13 23:37:51 +02:00
#=================================================