mirror of
https://github.com/YunoHost-Apps/archivist_ynh.git
synced 2024-09-03 18:15:55 +02:00
71 lines
2.5 KiB
Bash
Executable file
71 lines
2.5 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source scripts/_common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# SORT OUT THE CONFIG FILE TO HANDLE
|
|
#=================================================
|
|
|
|
file="$1"
|
|
|
|
if [ "$file" = "Backup_list.conf" ]; then
|
|
config_file="$install_dir/Backup_list.conf"
|
|
fi
|
|
|
|
#=================================================
|
|
# 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
|
|
if [ "$encrypt" -eq 1 ]; then
|
|
encrypt=true
|
|
passkey="$install_dir/passkey"
|
|
echo "$encryption_pwd" > "$passkey"
|
|
chmod 400 "$passkey"
|
|
else
|
|
encrypt=false
|
|
passkey=na
|
|
fi
|
|
|
|
if [ "$core_backup" -eq 1 ]; then
|
|
core_backup=true
|
|
else
|
|
core_backup=false
|
|
fi
|
|
|
|
config_file="$install_dir/Backup_list.conf"
|
|
cp "$install_dir/Backup_list.conf.default" "$config_file"
|
|
|
|
ynh_replace_string --target_file="$config_file" --match_string="^backup_dir=.*" --replace_string="backup_dir=$data_dir/backup"
|
|
ynh_replace_string --target_file="$config_file" --match_string="^enc_backup_dir=.*" --replace_string="enc_backup_dir=$data_dir/encrypted_backup"
|
|
|
|
ynh_replace_string --target_file="$config_file" --match_string="^encrypt=.*" --replace_string="encrypt=$encrypt"
|
|
ynh_replace_string --target_file="$config_file" --match_string="^cryptpass=.*" --replace_string="cryptpass=$passkey"
|
|
|
|
ynh_replace_string --target_file="$config_file" --match_string="^ynh_core_backup=.*" --replace_string="ynh_core_backup=$core_backup"
|
|
|
|
if [ $apps_backup -eq 1 ]; then
|
|
# Add all current applications to the backup
|
|
while read -r backup_app; do
|
|
ynh_replace_string --target_file="$config_file" --match_string="^ynh_app_backup=$" --replace_string="ynh_app_backup=$backup_app\n&"
|
|
done <<< "$(yunohost app list | 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
|