mirror of
https://github.com/YunoHost-Apps/archivist_ynh.git
synced 2024-09-03 18:15:55 +02:00
82 lines
2.4 KiB
Bash
Executable file
82 lines
2.4 KiB
Bash
Executable file
#!/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 final_path)
|
|
encrypt=$(ynh_app_setting_get $app encrypt)
|
|
core_backup=$(ynh_app_setting_get $app core_backup)
|
|
apps_backup=$(ynh_app_setting_get $app 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
|
|
#=================================================
|
|
|
|
# Verify the checksum and backup the file if it's different
|
|
ynh_backup_if_checksum_is_different "$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 "^backup_dir=.*" "backup_dir=$backup_dir" "$config_file"
|
|
ynh_replace_string "^enc_backup_dir=.*" "enc_backup_dir=$enc_backup_dir" "$config_file"
|
|
|
|
if [ $encrypt -eq 1 ]
|
|
then
|
|
encrypt=true
|
|
passkey="$final_path/passkey"
|
|
else
|
|
encrypt=false
|
|
passkey=na
|
|
fi
|
|
ynh_replace_string "^encrypt=.*" "encrypt=$encrypt" "$config_file"
|
|
ynh_replace_string "^cryptpass=.*" "cryptpass=$passkey" "$config_file"
|
|
|
|
if [ $core_backup -eq 1 ]
|
|
then
|
|
core_backup=true
|
|
else
|
|
core_backup=false
|
|
fi
|
|
ynh_replace_string "^ynh_core_backup=.*" "ynh_core_backup=$core_backup" "$config_file"
|
|
|
|
if [ $apps_backup -eq 1 ]
|
|
then
|
|
# Add all current applications to the backup
|
|
while read backup_app
|
|
do
|
|
ynh_replace_string "^ynh_app_backup=$" "ynh_app_backup=$backup_app\n&" "$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 "$config_file"
|