2018-09-30 20:01:19 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source scripts/_common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2020-04-08 20:00:29 +02:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2018-09-30 20:01:19 +02:00
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS
|
|
|
|
#=================================================
|
|
|
|
|
2020-05-02 01:11:24 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2020-04-08 20:00:29 +02:00
|
|
|
|
2019-05-26 17:00:09 +02:00
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
|
|
encrypt=$(ynh_app_setting_get --app=$app --key=encrypt)
|
|
|
|
core_backup=$(ynh_app_setting_get --app=$app --key=core_backup)
|
|
|
|
apps_backup=$(ynh_app_setting_get --app=$app --key=apps_backup)
|
2018-09-30 20:01:19 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SORT OUT THE CONFIG FILE TO HANDLE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
file="$1"
|
|
|
|
|
|
|
|
if [ "$file" = "Backup_list.conf" ]; then
|
2020-05-02 00:51:00 +02:00
|
|
|
config_file="$final_path/Backup_list.conf"
|
2018-09-30 20:01:19 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC ACTION
|
|
|
|
#=================================================
|
|
|
|
# RESET THE CONFIG FILE
|
|
|
|
#=================================================
|
2019-05-26 17:00:09 +02:00
|
|
|
ynh_script_progression --message="Reseting the config file $file"
|
2018-09-30 20:01:19 +02:00
|
|
|
|
|
|
|
# Verify the checksum and backup the file if it's different
|
2019-05-26 17:00:09 +02:00
|
|
|
ynh_backup_if_checksum_is_different --file="$config_file"
|
2018-09-30 20:01:19 +02:00
|
|
|
|
|
|
|
if [ "$file" = "Backup_list.conf" ]
|
|
|
|
then
|
2020-05-02 00:51:00 +02:00
|
|
|
# Get the default file and overwrite the current config
|
|
|
|
cp "$final_path/Backup_list.conf.default" "$config_file"
|
|
|
|
|
|
|
|
# Recreate the default config
|
|
|
|
backup_dir="/home/yunohost.app/${app}/backup"
|
|
|
|
enc_backup_dir="/home/yunohost.app/${app}/encrypted_backup"
|
|
|
|
ynh_replace_string --match_string="^backup_dir=.*" --replace_string="backup_dir=$backup_dir" --target_file="$config_file"
|
|
|
|
ynh_replace_string --match_string="^enc_backup_dir=.*" --replace_string="enc_backup_dir=$enc_backup_dir" --target_file="$config_file"
|
|
|
|
|
|
|
|
if [ $encrypt -eq 1 ]
|
|
|
|
then
|
|
|
|
encrypt=true
|
|
|
|
passkey="$final_path/passkey"
|
|
|
|
else
|
|
|
|
encrypt=false
|
|
|
|
passkey=na
|
|
|
|
fi
|
|
|
|
ynh_replace_string --match_string="^encrypt=.*" --replace_string="encrypt=$encrypt" --target_file="$config_file"
|
|
|
|
ynh_replace_string --match_string="^cryptpass=.*" --replace_string="cryptpass=$passkey" --target_file="$config_file"
|
|
|
|
|
|
|
|
if [ $core_backup -eq 1 ]
|
|
|
|
then
|
|
|
|
core_backup=true
|
|
|
|
else
|
|
|
|
core_backup=false
|
|
|
|
fi
|
|
|
|
ynh_replace_string --match_string="^ynh_core_backup=.*" --replace_string="ynh_core_backup=$core_backup" --target_file="$config_file"
|
|
|
|
|
|
|
|
if [ $apps_backup -eq 1 ]
|
|
|
|
then
|
|
|
|
# Add all current applications to the backup
|
|
|
|
while read backup_app
|
|
|
|
do
|
|
|
|
ynh_replace_string --match_string="^ynh_app_backup=$" --replace_string="ynh_app_backup=$backup_app\n&" --target_file="$config_file"
|
|
|
|
done <<< "$(yunohost app list -i | grep id: | sed 's/.*id: //')"
|
|
|
|
fi
|
2018-09-30 20:01:19 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Calculate and store the config file checksum into the app settings
|
2019-05-26 17:00:09 +02:00
|
|
|
ynh_store_file_checksum --file="$config_file"
|
2019-01-30 16:07:38 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Execution completed" --last
|