2017-11-01 20:57:58 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2020-04-08 19:59:52 +02:00
source _common.sh
source /usr/share/yunohost/helpers
2017-11-01 20:57:58 +01:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
encrypt=$YNH_APP_ARG_ENCRYPT
2021-11-30 15:02:27 +01:00
encryption_pwd=$YNH_APP_ARG_ENCRYPTION_PWD
2017-11-01 20:57:58 +01:00
core_backup=$YNH_APP_ARG_CORE_BACKUP
apps_backup=$YNH_APP_ARG_APPS_BACKUP
2017-12-23 23:56:21 +01:00
frequency="$YNH_APP_ARG_FREQUENCY"
2017-11-01 20:57:58 +01:00
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
2019-05-26 17:00:09 +02:00
ynh_script_progression --message="Validating installation parameters..."
2017-11-01 20:57:58 +01:00
final_path=/opt/yunohost/$app
2019-05-26 17:00:09 +02:00
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
2017-11-01 20:57:58 +01:00
if [ $encrypt -eq 1 ]; then
2022-07-16 19:44:33 +02:00
test -n "$encryption_pwd" || ynh_die --message="encryption_pwd can't be empty if you choose to enable encryption."
2017-11-01 20:57:58 +01:00
fi
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2019-05-26 17:00:09 +02:00
ynh_script_progression --message="Storing installation settings..." --weight=3
2017-11-01 20:57:58 +01:00
2019-05-26 17:00:09 +02:00
ynh_app_setting_set --app=$app --key=frequency --value="$frequency"
ynh_app_setting_set --app=$app --key=encrypt --value="$encrypt"
ynh_app_setting_set --app=$app --key=core_backup --value="$core_backup"
ynh_app_setting_set --app=$app --key=apps_backup --value="$apps_backup"
2019-01-30 19:21:03 +01:00
2019-05-26 17:00:09 +02:00
ynh_app_setting_set --app=$app --key=overwrite_cron --value=1
ynh_app_setting_set --app=$app --key=admin_mail_html --value=1
2017-11-01 20:57:58 +01:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2019-05-26 17:00:09 +02:00
ynh_script_progression --message="Installing dependencies..." --weight=15
2017-11-01 20:57:58 +01:00
# Valid the fucking debconf message
# To find this, install the package, install also debconf-utils
# Then use `debconf-get-selections | grep package`
echo "encfs encfs/security-information boolean true" | debconf-set-selections
2022-07-16 19:44:33 +02:00
ynh_install_app_dependencies $pkg_dependencies
2017-11-01 20:57:58 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2019-05-26 17:00:09 +02:00
ynh_script_progression --message="Setting up source files..." --weight=3
2017-11-01 20:57:58 +01:00
2019-05-26 17:00:09 +02:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
2017-11-01 20:57:58 +01:00
# Download, check integrity, uncompress and patch the source from app.src
2019-05-26 17:00:09 +02:00
ynh_setup_source --dest_dir="$final_path"
2017-11-01 20:57:58 +01:00
#=================================================
# SPECIFIC SETUP
#=================================================
# CREATE THE BACKUP DIRECTORY
#=================================================
2017-11-03 01:11:50 +01:00
backup_dir="/home/yunohost.app/${app}/backup"
enc_backup_dir="/home/yunohost.app/${app}/encrypted_backup"
2017-11-01 20:57:58 +01:00
mkdir -p "$backup_dir"
#=================================================
# CONFIGURE ARCHIVIST
#=================================================
2019-05-26 17:00:09 +02:00
ynh_script_progression --message="Configuring Archivist..." --weight=2
2017-11-01 20:57:58 +01:00
config_file="$final_path/Backup_list.conf"
cp "$final_path/Backup_list.conf.default" "$config_file"
2019-05-26 17:00:09 +02:00
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"
2017-11-01 20:57:58 +01:00
if [ $encrypt -eq 1 ]
then
2022-07-16 19:44:33 +02:00
encrypt=true
2017-11-01 20:57:58 +01:00
2022-07-16 19:44:33 +02:00
passkey="$final_path/passkey"
echo "$encryption_pwd" > "$passkey"
chmod 400 "$passkey"
2017-11-01 20:57:58 +01:00
else
2022-07-16 19:44:33 +02:00
encrypt=false
passkey=na
2017-11-01 20:57:58 +01:00
fi
2019-05-26 17:00:09 +02:00
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"
2017-11-01 20:57:58 +01:00
if [ $core_backup -eq 1 ]
then
2022-07-16 19:44:33 +02:00
core_backup=true
2017-11-01 20:57:58 +01:00
else
2022-07-16 19:44:33 +02:00
core_backup=false
2017-11-01 20:57:58 +01:00
fi
2019-05-26 17:00:09 +02:00
ynh_replace_string --match_string="^ynh_core_backup=.*" --replace_string="ynh_core_backup=$core_backup" --target_file="$config_file"
2017-11-01 20:57:58 +01:00
if [ $apps_backup -eq 1 ]
then
2022-07-16 19:44:33 +02:00
# 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 | grep 'id:' | sed 's/.*id: //')"
2017-11-01 20:57:58 +01:00
fi
2018-09-30 20:01:19 +02:00
# 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"
2018-09-30 20:01:19 +02:00
2017-11-01 20:57:58 +01:00
#=================================================
# SET THE CRON FILE
#=================================================
2019-05-26 17:00:09 +02:00
ynh_script_progression --message="Configuring the cron file..."
2017-11-01 20:57:58 +01:00
cp ../conf/cron /etc/cron.d/$app
2019-05-26 17:00:09 +02:00
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file=/etc/cron.d/$app
ynh_replace_string --match_string="__APP__" --replace_string=$app --target_file=/etc/cron.d/$app
2017-11-01 20:57:58 +01:00
if [ "$frequency" = "Daily" ]; then
2022-07-16 19:44:33 +02:00
cron_freq="0 2 * * *"
run_freq="every day"
2017-11-01 20:57:58 +01:00
elif [ "$frequency" = "Each 3 days" ]; then
2022-07-16 19:44:33 +02:00
cron_freq="0 2 */3 * *"
run_freq="each 3 days"
2017-11-01 20:57:58 +01:00
elif [ "$frequency" = "Weekly" ]; then
2022-07-16 19:44:33 +02:00
cron_freq="0 2 * * 0"
run_freq="once a week on sunday"
2017-11-01 20:57:58 +01:00
elif [ "$frequency" = "Biweekly" ]; then
2022-07-16 19:44:33 +02:00
cron_freq="0 2 * * 0/2"
run_freq="one sunday out of two"
2017-11-01 20:57:58 +01:00
else # Monthly
2022-07-16 19:44:33 +02:00
cron_freq="0 2 1 * *"
run_freq="once a month on the first sunday"
2017-11-01 20:57:58 +01:00
fi
2019-05-26 17:00:09 +02:00
ynh_replace_string --match_string="__FREQUENCY__" --replace_string="$cron_freq" --target_file=/etc/cron.d/$app
2017-11-01 20:57:58 +01:00
# Calculate and store the config file checksum into the app settings
2019-05-26 17:00:09 +02:00
ynh_store_file_checksum --file="/etc/cron.d/$app"
2017-11-01 20:57:58 +01:00
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions to app files
chown -R root: $final_path
2022-07-16 19:44:33 +02:00
#=================================================
# GENERIC FINALIZATION
2017-11-01 20:57:58 +01:00
#=================================================
# SETUP LOGROTATE
#=================================================
2019-05-26 17:00:09 +02:00
ynh_script_progression --message="Configuring log rotation..."
2017-11-01 20:57:58 +01:00
mkdir -p /var/log/$app
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
2019-01-13 17:27:09 +01:00
# PRINT INFORMATION
2017-11-01 20:57:58 +01:00
#=================================================
2019-05-26 17:00:09 +02:00
Informations="
To add recipients or to modify the files or apps to backup,
2017-11-03 01:11:50 +01:00
please have a look to the config file $config_file"
2019-05-26 17:00:09 +02:00
ynh_print_info --message="$Informations"
2017-12-16 23:05:44 +01:00
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
if [ "$encrypt" = "true" ]
then
2022-07-16 19:44:33 +02:00
encrypt_message="Your password for encryption is '$encryption_pwd'
2017-12-16 23:05:44 +01:00
"
2021-11-20 19:30:30 +01:00
2017-12-16 23:05:44 +01:00
else
2022-07-16 19:44:33 +02:00
encrypt_message=""
2017-12-16 23:05:44 +01:00
fi
2019-01-19 18:55:14 +01:00
# Get main domain and buid the url of the admin panel of the app.
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
2019-01-30 19:21:03 +01:00
echo "${encrypt_message}Archivist is going to run $run_freq.
2017-12-16 23:05:44 +01:00
If you want to change the frequency, have a look to the file /etc/cron.d/$app.
$Informations
2019-01-30 19:21:03 +01:00
Please read the __URL_TAG1__documentation__URL_TAG2__https://github.com/maniackcrudelis/archivist/blob/master/Configuration.md__URL_TAG3__ about the configuration of archivist for more information.
2019-01-19 18:55:14 +01:00
2019-01-30 19:21:03 +01:00
You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__.
You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__.
2017-12-16 23:05:44 +01:00
2019-01-30 19:21:03 +01:00
If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/archivist_ynh__URL_TAG3__." > mail_to_send
2019-01-30 16:07:38 +01:00
2019-05-26 17:00:09 +02:00
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=install
2019-01-30 19:21:03 +01:00
2019-01-30 16:07:38 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2019-05-26 17:00:09 +02:00
ynh_script_progression --message="Installation of $app completed" --last