1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/phpipam_ynh.git synced 2024-09-03 19:56:39 +02:00
This commit is contained in:
ericgaspar 2021-07-06 11:23:03 +02:00
parent 08138ad602
commit 7fe835efbb
5 changed files with 302 additions and 91 deletions

View file

@ -24,7 +24,7 @@
"requirements": { "requirements": {
"yunohost": ">= 4.2.4" "yunohost": ">= 4.2.4"
}, },
"multi_instance": false, "multi_instance": true,
"services": [ "services": [
"nginx", "nginx",
"php7.3-fpm", "php7.3-fpm",

View file

@ -6,7 +6,7 @@
YNH_PHP_VERSION="7.3" YNH_PHP_VERSION="7.3"
extra_php_dependencies="php${YNH_PHP_VERSION}-mysql php${YNH_PHP_VERSION}-json php${YNH_PHP_VERSION}-curl php${YNH_PHP_VERSION}-gd php${YNH_PHP_VERSION}-opcache php${YNH_PHP_VERSION}-fileinfo php${YNH_PHP_VERSION}-intl php${YNH_PHP_VERSION}-cli php${YNH_PHP_VERSION}-mbstring php${YNH_PHP_VERSION}-xml" extra_php_dependencies="php${YNH_PHP_VERSION}-gmp php${YNH_PHP_VERSION}-mysql php${YNH_PHP_VERSION}-ldap php${YNH_PHP_VERSION}-json php${YNH_PHP_VERSION}-gd php${YNH_PHP_VERSION}-opcache php${YNH_PHP_VERSION}-fileinfo php${YNH_PHP_VERSION}-intl php${YNH_PHP_VERSION}-cli php${YNH_PHP_VERSION}-mbstring php${YNH_PHP_VERSION}-xml"
#================================================= #=================================================
# PERSONAL HELPERS # PERSONAL HELPERS

View file

@ -1,33 +1,81 @@
#!/bin/bash #!/bin/bash
# Exit on command errors and treat unset variables as an error #=================================================
set -eu # GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# See comments in install script # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
app=$YNH_APP_INSTANCE_NAME source ../settings/scripts/_common.sh
# Source YunoHost helpers
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
# Backup sources & data #=================================================
# Note: the last argument is where to save this path, see the restore script. # MANAGE SCRIPT FAILURE
ynh_backup "/var/www/${app}" "sources" #=================================================
### MySQL (remove if not used) ### ynh_clean_setup () {
# If a MySQL database is used: ### Remove this function if there's nothing to clean before calling the remove script.
# Dump the database true
dbname=$app }
dbuser=$app # Exit if an error occurs during the execution of the script
dbpass=$(ynh_app_setting_get "$app" mysqlpwd) ynh_abort_if_errors
mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./dump.sql
### MySQL end ###
# Copy NGINX configuration #=================================================
domain=$(ynh_app_setting_get "$app" domain) # LOAD SETTINGS
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf" #=================================================
ynh_print_info --message="Loading installation settings..."
### PHP (remove if not used) ### app=$YNH_APP_INSTANCE_NAME
# If a dedicated php-fpm process is used:
# # Copy PHP-FPM pool configuration final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# ynh_backup "/etc/php5/fpm/pool.d/${app}.conf" "php-fpm.conf" domain=$(ynh_app_setting_get --app=$app --key=domain)
### PHP end ### db_name=$(ynh_app_setting_get --app=$app --key=db_name)
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
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"
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_backup --src_path="/etc/logrotate.d/$app"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
ynh_print_info --message="Backing up the MySQL database..."
### (However, things like MySQL dumps *do* take some time to run, though the
### copy of the generated dump to the archive still happens later)
ynh_mysql_dump_db --database="$db_name" > db.sql
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -1,52 +1,113 @@
#!/bin/bash #!/bin/bash
# Note: each files and directories you've saved using the ynh_backup helper #=================================================
# will be located in the current directory, regarding the last argument. # GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Exit on command errors and treat unset variables as an error # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
set -eu source ../settings/scripts/_common.sh
# See comments in install script
app=$YNH_APP_INSTANCE_NAME
# Source YunoHost helpers
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
# Retrieve old app settings #=================================================
domain=$(ynh_app_setting_get "$app" domain) # MANAGE SCRIPT FAILURE
path_url=$(ynh_app_setting_get "$app" path_url) #=================================================
# Check domain/path availability ynh_clean_setup () {
sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \ #### Remove this function if there's nothing to clean before calling the remove script.
|| ynh_die "Path not available: ${domain}${path_url}" true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# Restore sources & data #=================================================
src_path="/var/www/${app}" # LOAD SETTINGS
sudo cp -a ./sources "$src_path" #=================================================
ynh_script_progression --message="Loading installation settings..." --time --weight=1
# Restore permissions to app files app=$YNH_APP_INSTANCE_NAME
# you may need to make some file and/or directory writeable by www-data (nginx user)
sudo chown -R root: "$src_path"
### MySQL (remove if not used) ### domain=$(ynh_app_setting_get --app=$app --key=domain)
# If a MySQL database is used: path_url=$(ynh_app_setting_get --app=$app --key=path)
# Create and restore the database final_path=$(ynh_app_setting_get --app=$app --key=final_path)
dbname=$app db_name=$(ynh_app_setting_get --app=$app --key=db_name)
dbuser=$app db_user=$db_name
dbpass=$(ynh_app_setting_get "$app" mysqlpwd) phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql
### MySQL end ###
# Restore NGINX configuration #=================================================
sudo cp -a ./nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf" # CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..." --time --weight=1
### PHP (remove if not used) ### ynh_webpath_available --domain=$domain --path_url=$path_url \
# If a dedicated php-fpm process is used: || ynh_die --message="Path not available: ${domain}${path_url}"
# # Copy PHP-FPM pool configuration and reload the service test ! -d $final_path \
# sudo cp -a ./php-fpm.conf "/etc/php5/fpm/pool.d/${app}.conf" || ynh_die --message="There is already a directory: $final_path "
# sudo service php5-fpm reload
### PHP end ###
# Restart webserver #=================================================
sudo service nginx reload # STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX configuration..." --time --weight=1
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --time --weight=1
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --time --weight=1
ynh_restore_file --origin_path="$final_path"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the PHP-FPM configuration..." --time --weight=1
ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the MySQL database..." --time --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
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the logrotate configuration..." --time --weight=1
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
# 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

View file

@ -1,46 +1,148 @@
#!/bin/bash #!/bin/bash
# Exit on command errors and treat unset variables as an error #=================================================
set -eu # GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# See comments in install script source _common.sh
app=$YNH_APP_INSTANCE_NAME
final_path=/var/www/$app
# Source YunoHost helpers
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --time --weight=1
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)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1
#
# N.B. : the followings setting migrations snippets are provided as *EXAMPLES*
# of what you may want to do in some cases (e.g. a setting was not defined on
# some legacy installs and you therefore want to initiaze stuff during upgrade)
#
# If db_name doesn't exist, create it
#if [ -z "$db_name" ]; then
# db_name=$(ynh_sanitize_dbid --db_name=$app)
# ynh_app_setting_set --app=$app --key=db_name --value=$db_name
#fi
# If final_path doesn't exist, create it
#if [ -z "$final_path" ]; then
# final_path=/var/www/$app
# ynh_app_setting_set --app=$app --key=final_path --value=$final_path
#fi
### If nobody installed your app before 4.1,
### then you may safely remove these lines
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_app_setting_set $app final_path $final_path if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --time --weight=1
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path" ynh_setup_source --dest_dir="$final_path"
fi
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --time --weight=1
# Create a dedicated nginx config # Create a dedicated NGINX config
#ynh_add_nginx_config ynh_add_nginx_config
#================================================= #=================================================
# UPGRADE CONFIG # PHP-FPM CONFIGURATION
#================================================= #=================================================
#cp -a ../conf/loolwsd.xml /etc/loolwsd ynh_script_progression --message="Upgrading PHP-FPM configuration..." --time --weight=1
#ynh_replace_string "__NEXTCLOUDDOMAIN__" "$nextcloud_domain" "/etc/loolwsd/loolwsd.xml"
#ynh_replace_string "__PASSWORD__" "$password" "/etc/loolwsd/loolwsd.xml"
#systemctl restart loolwsd
# Create a dedicated PHP-FPM config
ynh_add_fpm_config
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..." --time --weight=1
# If app is public, add url to SSOWat conf as skipped_uris ynh_add_config --template="../conf/config.dist.php" --destination="$final_path/config.php"
#if [[ $is_public -eq 1 ]]; then
# See install script
# ynh_app_setting_set "$app" unprotected_uris "/"
#fi
# Reload Nginx service chmod 400 "$final_path/config.php"
systemctl reload nginx chown $app:$app "$final_path/config.php"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --time --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --time --last