#!/bin/bash #================================================= # GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= source scripts/_common.sh source /usr/share/yunohost/helpers #================================================= # RETRIEVE ARGUMENTS #================================================= app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} 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) #================================================= # SORT OUT THE CONFIG FILE TO HANDLE #================================================= file="$1" if [ "$file" = "Backup_list.conf" ]; then config_file="$final_path/Backup_list.conf" fi #================================================= # SPECIFIC ACTION #================================================= # RESET THE CONFIG FILE #================================================= ynh_script_progression --message="Reseting the config file $file" # Verify the checksum and backup the file if it's different ynh_backup_if_checksum_is_different --file="$config_file" if [ "$file" = "Backup_list.conf" ] then # 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 fi # Calculate and store the config file checksum into the app settings ynh_store_file_checksum --file="$config_file" #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Execution completed" --last