1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/lutim_ynh.git synced 2024-09-03 19:36:24 +02:00
lutim_ynh/scripts/actions/reset_default_app

159 lines
5.9 KiB
Text
Raw Normal View History

2020-04-25 13:14:03 +02:00
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Load common variables for all scripts.
source scripts/_variables
source scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
# Clean installation remaining that are not handle by the remove script.
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
port=$(ynh_app_setting_get --app=$app --key=port)
always_encrypt=$(ynh_app_setting_get --app=$app --key=always_encrypt)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
secret=$(ynh_app_setting_get --app=$app --key=secret)
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_app_setting_set --app=$app --key=overwrite_settings --value=1
ynh_app_setting_set --app=$app --key=overwrite_nginx --value=1
ynh_app_setting_set --app=$app --key=overwrite_systemd --value=1
ynh_app_setting_set --app=$app --key=admin_mail_html --value=1
#=================================================
# SPECIFIC ACTION
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
ynh_script_progression --message="Activating maintenance mode..."
ynh_maintenance_mode_ON
#=================================================
# STOP LUTIM
#=================================================
ynh_systemd_action --action=stop
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Resetting source files..." --weight=2
# Download, check integrity, uncompress and patch the source from app.src
(cd scripts; YNH_CWD=$PWD ynh_setup_source --dest_dir="$final_path")
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Resetting nginx web server configuration..." --weight=4
# Create a dedicated nginx config
yunohost app action run $app reset_default_nginx
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app
#=================================================
# RECONFIGURE APP
#=================================================
ynh_script_progression --message="Reconfiguring Lutim..." --weight=2
# Configure Lutim
# Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
ynh_backup_if_checksum_is_different --file="$final_path/lutim.conf"
(cd scripts; cp ../conf/lutim.conf.template "$final_path/lutim.conf")
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__ENCRYPT__" --replace_string="$always_encrypt" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__SECRET__" --replace_string="$secret" --target_file="$final_path/lutim.conf"
# Set the number of process for Lutim to twice the number of CPU core.
ynh_replace_string --match_string="__WORKERS__" --replace_string="$(( $(nproc) * 2 ))" --target_file="$final_path/lutim.conf"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum --file="$final_path/lutim.conf"
#=================================================
# SETUP CRON
#=================================================
(cd scripts; cp ../conf/cron_lutim /etc/cron.d/$app)
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
#=================================================
# SECURING FILES AND DIRECTORIES
#=================================================
# Set permissions on app files
chown -R $app: $final_path
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Resetting systemd configuration..."
yunohost app action run $app reset_default_systemd
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Resetting logrotate configuration..."
ynh_use_logrotate --non-append
chown $app -R /var/log/$app
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# DEACTIVE MAINTENANCE MODE
#=================================================
ynh_script_progression --message="Disabling maintenance mode..."
ynh_maintenance_mode_OFF
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Execution completed" --last