1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/archivist_ynh.git synced 2024-09-03 18:15:55 +02:00
archivist_ynh/scripts/install

93 lines
3.2 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# INITIALIZE AND STORE SETTINGS
#=================================================
if [ "$encrypt" -eq 1 ] && [ -z "$encryption_pwd" ]; then
ynh_die --message="encryption_pwd can't be empty if you choose to enable encryption."
fi
# Not saved as settings by default
ynh_app_setting_set --app="$app" --key="encryption_pwd" --value="$encryption_pwd"
_set_frequencies
ynh_app_setting_set --app="$app" --key=overwrite_cron --value=1
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=3
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
chown -R "root:root" "$install_dir"
chown -R "root:root" "$data_dir"
#=================================================
# CONFIGURE ARCHIVIST
#=================================================
ynh_script_progression --message="Configuring Archivist..." --weight=2
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
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$config_file"
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
# Add Cron configuration file
ynh_add_config --template="archivist.cron" --destination="/etc/cron.d/$app"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last