diff --git a/scripts/backup b/scripts/backup index 4568644..01bf979 100755 --- a/scripts/backup +++ b/scripts/backup @@ -42,6 +42,12 @@ ynh_print_info --message="Declaring files to be backed up..." ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# BACKUP LOGROTATE +#================================================= + +ynh_backup --src_path="/etc/logrotate.d/$app" + #================================================= # BACKUP SOGo CONFIGURATION #================================================= diff --git a/scripts/install b/scripts/install index b063666..806c816 100755 --- a/scripts/install +++ b/scripts/install @@ -92,8 +92,14 @@ ynh_add_config --template="sogo.conf" --destination="/etc/$app/sogo.conf" # To fix the issue https://sogo.nu/bugs/view.php?id=31 we need stunnel to be able to connect correctly to the smtp server config_stunnel -# Install crontab -config_cron +#================================================= +# SETUP A CRON +#================================================= +ynh_script_progression --message="Setuping a cron..." --weight=1 + +ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" +chown root: "/etc/cron.d/$app" +chmod 644 "/etc/cron.d/$app" #================================================= # NGINX CONFIGURATION @@ -137,7 +143,7 @@ ynh_permission_create --permission="sync_client" --allowed='visitors' --auth_hea #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 -yunohost service add $app --description="A short description of the app" --log="/var/log/$app/$app.log" +yunohost service add $app --description="Groupware for E-Mail, Contacts and Calender" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/restore b/scripts/restore index 7b308b0..e2f5cd8 100755 --- a/scripts/restore +++ b/scripts/restore @@ -3,68 +3,109 @@ #================================================= # GENERIC START #================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Import common cmd +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh - -# Source YunoHost helpers source /usr/share/yunohost/helpers -# Stop script if errors +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +ynh_clean_setup () { + #### Remove this function if there's nothing to clean before calling the remove script. + true +} +# Exit if an error occurs during the execution of the script ynh_abort_if_errors -ynh_script_progression --message="Loading settings..." +#================================================= +# LOAD SETTINGS +#================================================= +ynh_script_progression --message="Loading installation settings..." --weight=1 -domain=$(ynh_app_setting_get --app $app --key domain) -path_url=$(ynh_app_setting_get --app $app --key path) -final_path=$(ynh_app_setting_get --app $app --key final_path) -db_name=$(ynh_app_setting_get --app $app --key db_name) +app=$YNH_APP_INSTANCE_NAME +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name + +#================================================= # CHECK IF THE APP CAN BE RESTORED -ynh_webpath_available --domain $domain --path_url $path_url \ - || ynh_die --message "Path not available: ${domain}${path_url}" +#================================================= +ynh_script_progression --message="Validating restoration parameters..." --weight=1 + +test ! -d $final_path || ynh_die --message="There is already a directory: $final_path " #================================================= -# STANDARD RESTORATION STEPS +# REINSTALL DEPENDENCIES #================================================= +ynh_script_progression --message="Reinstalling dependencies..." --weight=1 # Define and install dependencies -ynh_script_progression --message="Reinstalling dependencies..." --weight=5 -install_dependance +ynh_install_app_dependencies $pkg_dependencies + # Restore all config and data ynh_script_progression --message="Restoring files..." --weight=10 + ynh_restore +#================================================= # RESTORE THE MYSQL DATABASE -ynh_script_progression --message="Restoring database..." --weight=3 -db_user=$db_name -db_pwd=$(ynh_app_setting_get --app $app --key mysqlpwd) -ynh_mysql_setup_db --db_name $db_name --db_user $db_user --db_pwd $db_pwd -ynh_mysql_connect_as --user $db_user --password $db_pwd --database $db_name < ./db.sql +#================================================= +ynh_script_progression --message="Restoring the MySQL database..." --weight=1 + +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd +ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql # Enable stunnel at startup ynh_replace_string --match_string "ENABLED=0" --replace_string "ENABLED=1" --target_file /etc/default/stunnel4 #================================================= -# GENERIC FINALIZATION -#================================================= - # SECURE FILES AND DIRECTORIES +#================================================= ynh_script_progression --message="Protecting directory..." + set_permission -# SETUP LOGROTATE -ynh_use_logrotate --logfile /var/log/$app/sogo.log --nonappend +#================================================= +# RESTORE THE LOGROTATE CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1 -# Register service -yunohost service add $app --log "/var/log/$app/sogo.log" +ynh_restore_file --origin_path="/etc/logrotate.d/$app" --nonappend + +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 + +yunohost service add $app --description="Groupware for E-Mail, Contacts and Calender" --log="/var/log/$app/$app.log" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=3 + +ynh_systemd_action --service_name=$app --action="restart" --log_path="systemd" +ynh_systemd_action --service_name=stunnel4 --action="restart" --log_path="systemd" + +#================================================= +# RELOAD NGINX AND PHP-FPM +#================================================= +ynh_script_progression --message="Reloading NGINX web server..." --weight=1 + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= -# Restart services -ynh_script_progression --message="Starting SOGo services..." --weight=3 -systemctl restart sogo -systemctl restart stunnel4 -systemctl reload nginx -systemctl restart cron ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index 10edd1c..fcf46cc 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -111,8 +111,15 @@ ynh_add_config --template="sogo.conf" --destination="/etc/$app/sogo.conf" # Configure stunnel config_stunnel -# Install crontab -config_cron +#================================================= +# SETUP A CRON +#================================================= +ynh_script_progression --message="Setuping a cron..." --weight=1 + +ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" +chown root: "/etc/cron.d/$app" +chmod 644 "/etc/cron.d/$app" + #Configure Nginx config_nginx