1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/minchat_ynh.git synced 2024-09-03 19:36:29 +02:00
This commit is contained in:
ericgaspar 2020-07-18 20:55:45 +02:00
parent 316e04eb0c
commit 021d770bd7
No known key found for this signature in database
GPG key ID: 574F281483054D44
4 changed files with 210 additions and 96 deletions

View file

@ -1,26 +1,63 @@
#!/bin/bash #!/bin/bash
# causes the shell to exit if any subcommand or pipeline returns a non-zero status #=================================================
set -eu # GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Source YNH helpers #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# 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
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get "$app" domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
# Backup directory location for the app from where the script is executed and #=================================================
# which will be compressed afterward # DECLARE DATA AND CONF FILES TO BACKUP
backup_dir=$YNH_APP_BACKUP_DIR #=================================================
ynh_print_info --message="Declaring files to be backed up..."
# Backup sources & data #=================================================
ynh_backup "/var/www/${app}" "sources" # BACKUP THE APP MAIN DIR
#=================================================
# Copy Nginx conf ynh_backup --src_path="$final_path"
sudo mkdir -p ./conf
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "conf/nginx.conf" #=================================================
# Copy the php-fpm conf files # BACKUP THE NGINX CONFIGURATION
ynh_backup "/etc/php5/fpm/pool.d/${app}.conf" "conf/php-fpm.conf" #=================================================
ynh_backup "/etc/php5/fpm/conf.d/20-${app}.ini" "conf/php-fpm.ini"
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE PHP-FPM CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -66,8 +66,6 @@ ynh_setup_source --dest_dir="$final_path"
#================================================= #=================================================
ynh_script_progression --message="Configuring nginx web server..." --time --weight=1 ynh_script_progression --message="Configuring nginx web server..." --time --weight=1
### `ynh_add_nginx_config` will use the file conf/nginx.conf
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config

View file

@ -1,27 +1,81 @@
#!/bin/bash #!/bin/bash
# Exit on command errors and treat unset variables as an error #=================================================
set -u # GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common ]; then source _common.sh
# Get file fonction if not been to the current directory
sudo cp ../settings/scripts/_common ./_common
sudo chmod a+rx _common
fi
# Source app helpers
source ./_common
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
# Get multi-instances specific variables #=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --time --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments domain=$(ynh_app_setting_get --app=$app --key=domain)
domain=$(ynh_app_setting_get "$app" domain) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
ynh_secure_remove /var/www/$app #=================================================
ynh_secure_remove /etc/nginx/conf.d/$domain.d/$app.conf # STANDARD REMOVE
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
# Remove the service from the list of services known by Yunohost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status $app >/dev/null
then
ynh_script_progression --message="Removing $app service..." --time --weight=1
yunohost service remove $app
fi
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --time --weight=1
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory..." --time --weight=1
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing nginx web server configuration..." --time --weight=1
# Remove the dedicated nginx config
ynh_remove_nginx_config
#=================================================
# REMOVE PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Removing php-fpm configuration..." --time --weight=1
# Remove the dedicated php-fpm config
ynh_remove_fpm_config ynh_remove_fpm_config
ynh_system_user_delete $app #=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_script_progression --message="Removing the dedicated system user..." --time --weight=1
sudo systemctl reload nginx # Delete a system user
ynh_system_user_delete --username=$app
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --time --last

View file

@ -1,81 +1,106 @@
#!/bin/bash #!/bin/bash
# causes the shell to exit if any subcommand or pipeline returns a non-zero status #=================================================
set -eu # GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common ]; then #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
# Get file fonction if not been to the current directory source ../settings/scripts/_common.sh
sudo cp ../settings/scripts/_common ./_common
sudo chmod a+rx _common
fi
# Loads the generic functions usually used in the script
source _common
# Source app helpers
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# 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
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --time --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments domain=$(ynh_app_setting_get --app=$app --key=domain)
domain=$(ynh_app_setting_get "$app" domain) path_url=$(ynh_app_setting_get --app=$app --key=path)
path=$(ynh_app_setting_get "$app" path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
is_public=$(ynh_app_setting_get $app is_public) phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
# Check domain/path availability #=================================================
sudo yunohost app checkurl "${domain}${path}" -a "$app" \ # CHECK IF THE APP CAN BE RESTORED
|| ynh_die "Path not available: ${domain}${path}" #=================================================
ynh_script_progression --message="Validating restoration parameters..." --time --weight=1
# Check $final_path ynh_webpath_available --domain=$domain --path_url=$path_url \
final_path="/var/www/${app}" || ynh_die --message="Path not available: ${domain}${path_url}"
if [ -d $final_path ]; then test ! -d $final_path \
ynh_die "There is already a directory: $final_path" || ynh_die --message="There is already a directory: $final_path "
fi
# Check configuration files #=================================================
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" # STANDARD RESTORATION STEPS
if [ -f $nginx_conf ]; then #=================================================
ynh_die "The NGINX configuration already exists at '${nginx_conf}'. # RESTORE THE NGINX CONFIGURATION
You should safely delete it before restoring this app." #=================================================
fi
# Check configuration files php-fpm
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
if [ -f $phpfpm_conf ]; then
ynh_die "The PHP FPM configuration already exists at '${phpfpm_conf}'.
You should safely delete it before restoring this app."
fi
phpfpm_ini="/etc/php5/fpm/conf.d/20-${app}.ini" ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
if [ -f $phpfpm_ini ]; then
ynh_die "The PHP FPM INI configuration already exists at '${phpfpm_ini}'.
You should safely delete it before restoring this app."
fi
# Create system user dedicace for this app #=================================================
ynh_system_user_create $app # RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --time --weight=1
# Restore sources & data ynh_restore_file --origin_path="$final_path"
sudo cp -a "./sources" $final_path
# Set permissions #=================================================
sudo chown -R $app: $final_path # RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --time --weight=1
# Restore configuration files # Create the dedicated user (if not existing)
sudo cp -a ./conf/nginx.conf "${nginx_conf}" ynh_system_user_create --username=$app
# Restore php-fpm configuration files #=================================================
sudo cp -a ./conf/php-fpm.conf "${phpfpm_conf}" # RESTORE USER RIGHTS
sudo cp -a ./conf/php-fpm.ini "${phpfpm_ini}" #=================================================
# Set ssowat config # Restore permissions on app files
if [[ $is_public -eq 0 ]]; then chown -R root: $final_path
ynh_app_setting_delete $app skipped_uris
fi
if [ $is_public -eq 1 ] #=================================================
then # RESTORE THE PHP-FPM CONFIGURATION
ynh_app_setting_set $app skipped_uris "/" # Make app public if necessary #=================================================
fi
# Reload service ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
sudo systemctl reload php5-fpm
sudo systemctl reload nginx #=================================================
sudo yunohost app ssowatconf # SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --time --weight=1
# Define and install dependencies
#ynh_install_app_dependencies $pkg_dependencies
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
ynh_script_progression --message="Reloading nginx web server and php-fpm..." --time --weight=1
ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --time --last