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
# 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
#=================================================
# 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
# Retrieve arguments
domain=$(ynh_app_setting_get "$app" domain)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
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
backup_dir=$YNH_APP_BACKUP_DIR
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
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
sudo mkdir -p ./conf
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "conf/nginx.conf"
# Copy the php-fpm conf files
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="$final_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
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_add_nginx_config` will use the file conf/nginx.conf
# Create a dedicated nginx config
ynh_add_nginx_config

View file

@ -1,27 +1,81 @@
#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -u
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common ]; then
# 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 _common.sh
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
# Retrieve arguments
domain=$(ynh_app_setting_get "$app" domain)
domain=$(ynh_app_setting_get --app=$app --key=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_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
# 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
# Get file fonction if not been to the current directory
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
#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
#=================================================
# 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
# Retrieve arguments
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
is_public=$(ynh_app_setting_get $app is_public)
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)
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
# Check domain/path availability
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| ynh_die "Path not available: ${domain}${path}"
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..." --time --weight=1
# Check $final_path
final_path="/var/www/${app}"
if [ -d $final_path ]; then
ynh_die "There is already a directory: $final_path"
fi
ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
# Check configuration files
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
if [ -f $nginx_conf ]; then
ynh_die "The NGINX configuration already exists at '${nginx_conf}'.
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
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
phpfpm_ini="/etc/php5/fpm/conf.d/20-${app}.ini"
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
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
# 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
sudo cp -a "./sources" $final_path
ynh_restore_file --origin_path="$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
sudo cp -a ./conf/nginx.conf "${nginx_conf}"
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app
# Restore php-fpm configuration files
sudo cp -a ./conf/php-fpm.conf "${phpfpm_conf}"
sudo cp -a ./conf/php-fpm.ini "${phpfpm_ini}"
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Set ssowat config
if [[ $is_public -eq 0 ]]; then
ynh_app_setting_delete $app skipped_uris
fi
# Restore permissions on app files
chown -R root: $final_path
if [ $is_public -eq 1 ]
then
ynh_app_setting_set $app skipped_uris "/" # Make app public if necessary
fi
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
# Reload service
sudo systemctl reload php5-fpm
sudo systemctl reload nginx
sudo yunohost app ssowatconf
ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
#=================================================
# 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