1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/framaforms_ynh.git synced 2024-09-03 18:36:12 +02:00

[fix] Backup and upgrade

This commit is contained in:
ljf 2019-06-19 18:03:19 +02:00
parent 72e9e99bdc
commit 125ce10915
11 changed files with 101 additions and 88 deletions

View file

@ -11,12 +11,12 @@
setup_sub_dir=1
setup_root=1
setup_nourl=0
setup_private=1
setup_public=1
upgrade=1
backup_restore=1
multi_instance=1
change_url=1
setup_private=0
setup_public=0
upgrade=0
backup_restore=0
multi_instance=0
change_url=0
;;; Levels
# If the level 5 (Package linter) is forced to 1. Please add justifications here.
Level 5=auto

View file

@ -5,7 +5,7 @@
"description": {
"en": "Framaforms helps you create online webforms and surveys"
},
"version": "1.0.0+190618-ynh1",
"version": "1.0.0+190618-ynh6",
"url": "https://framagit.org/framasoft/framaforms",
"license": "GPL-2.0-only",
"requirements": {
@ -55,6 +55,9 @@
"ask": {
"en": "Are visitors who do not have a YunoHost account on this server allowed to register and create forms ?"
},
"help": {
"en": "If no, only person with an account on your server will be able to create forms. In all cases, visitors will be able to reply to form"
},
"type": "boolean",
"default": true
}

BIN
scripts/.install.swp Normal file

Binary file not shown.

View file

@ -43,6 +43,3 @@ ynh_save_args () {
done
}
source ynh_add_extra_apt_repos__3
source ynh_install_php__3
source ynh_composer__2

View file

@ -7,7 +7,7 @@
#=================================================
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
#source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
@ -37,6 +37,9 @@ ynh_script_progression --message="Backing up the main app directory..." --time -
ynh_backup --src_path="$final_path"
ynh_script_progression --message="Backing up the answer files..." --time --weight=1
ynh_backup --src_path="/home/yunohost.app/$app/data" --is_big=1
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
@ -49,7 +52,7 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
ynh_script_progression --message="Backing up php-fpm configuration..." --time --weight=1
ynh_backup --src_path="/etc/php/7.0/fpm/pool.d/$app.conf"
ynh_backup --src_path="/etc/php/7.2/fpm/pool.d/$app.conf"
#=================================================
# BACKUP THE MYSQL DATABASE

View file

@ -6,7 +6,7 @@
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
#source _common.sh
source /usr/share/yunohost/helpers
#=================================================

View file

@ -8,6 +8,10 @@
source _common.sh
source /usr/share/yunohost/helpers
source ynh_add_extra_apt_repos__3
source ynh_install_php__3
source ynh_composer__2
source ynh_exec_as
#=================================================
# MANAGE SCRIPT FAILURE
@ -27,7 +31,7 @@ app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --time --weight=1
ynh_script_progression --message="Validating installation parameters..." --weight=1
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
@ -38,7 +42,7 @@ ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --time --weight=2
ynh_script_progression --message="Storing installation settings..." --weight=1
ynh_save_args domain path_url password is_public final_path
@ -48,14 +52,14 @@ ynh_save_args domain path_url password is_public final_path
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --time --weight=7
ynh_script_progression --message="Installing dependencies..." --weight=7
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# CREATE A PostgreSQL DATABASE
#=================================================
ynh_script_progression --message="Creating a PostgreSQL database..." --time --weight=2
ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2
ynh_psql_test_if_first_run
@ -67,7 +71,7 @@ ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --time --weight=12
ynh_script_progression --message="Setting up source files..." --weight=9
### `ynh_setup_source` is used to install an app from a zip or tar.gz file,
### downloaded from an upstream source, like a git repository.
@ -79,7 +83,7 @@ ynh_setup_source --dest_dir="$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring nginx web server..." --time --weight=2
ynh_script_progression --message="Configuring nginx web server..." --weight=1
### `ynh_add_nginx_config` will use the file conf/nginx.conf
@ -89,7 +93,7 @@ ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --time --weight=2
ynh_script_progression --message="Configuring system user..." --weight=3
# Create a system user
ynh_system_user_create --username=$app
@ -97,14 +101,14 @@ ynh_system_user_create --username=$app
#=================================================
# INSTALL PHP 7.2
#=================================================
ynh_script_progression --message="Installing PHP 7.2..." --time --weight=10
ynh_script_progression --message="Installing PHP 7.2..." --weight=35
ynh_install_php --phpversion="7.2" --package="$extra_pkg_dependencies"
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring php-fpm..." --time --weight=2
ynh_script_progression --message="Configuring php-fpm..." --weight=1
# Create a dedicated php-fpm config
ynh_add_fpm_config --phpversion="7.2"
@ -114,7 +118,7 @@ ynh_add_fpm_config --phpversion="7.2"
#=================================================
# CREATE DRUSH ALIAS
#=================================================
ynh_script_progression --message="Creating Drush alias..." --time --weight=2
ynh_script_progression --message="Creating Drush alias..." --weight=2
mkdir -p "$final_path/.drush"
@ -128,7 +132,7 @@ ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --
#=================================================
# INSTALL COMPOSER
#=================================================
ynh_script_progression --message="Installing Composer..." --time --weight=8
ynh_script_progression --message="Installing Composer..." --weight=31
mkdir -p "$final_path/.composer"
@ -139,7 +143,7 @@ ynh_install_composer --phpversion="7.2" --workdir="$final_path/.composer"
#=================================================
# Database initialization
#=================================================
ynh_script_progression --message="Initializing PostgreSQL database..." --time --weight=8
ynh_script_progression --message="Initializing PostgreSQL database..." --weight=8
ynh_replace_string "betaforms" "$db_user" "$final_path/framaforms.sql"
ynh_psql_execute_file_as_root "$final_path/framaforms.sql" "$db_name"
@ -147,20 +151,20 @@ ynh_psql_execute_file_as_root "$final_path/framaforms.sql" "$db_name"
#=================================================
# Initialize tmp and private directory
#=================================================
ynh_script_progression --message="Initializing tmp and private directory..." --time --weight=8
ynh_script_progression --message="Initializing tmp and private directory..." --weight=1
mkdir -p "$final_path/sites/default/files"
chmod 2775 "$final_path/sites/default/files"
mkdir -p "$final_path/sites/default/files/tmp"
mkdir -p "${final_path}_private"
chown -R $app: "${final_path}_private"
chmod 775 "${final_path}_private"
mkdir -p "/home/yunohost.app/$app/data"
chown -R $app: "/home/yunohost.app/$app/data"
chmod 775 "/home/yunohost.app/$app/data"
#=================================================
# Missing images
#=================================================
ynh_script_progression --message="Adding missing images..." --time --weight=2
ynh_script_progression --message="Adding missing images..." --weight=2
mkdir -p "$final_path/sites/default/files/imgforms"
@ -183,16 +187,18 @@ ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path"
#=================================================
# Change admin password and apply custom conf
#=================================================
ynh_script_progression --message="Changing admin password..." --time --weight=2
ynh_script_progression --message="Changing admin password..." --weight=19
chown -R $app: $final_path
drush="$final_path/.composer/vendor/bin/drush --quiet"
pushd $final_path
sudo -u $app $final_path/.composer/vendor/bin/drush upwd --password="$password" "admin"
sudo -u $app $final_path/.composer/vendor/bin/drush variable-set site_name "Framaforms"
sudo -u $app $final_path/.composer/vendor/bin/drush variable-set site_mail "no-reply@$domain"
#sudo -u $app $final_path/.composer/vendor/bin/drush @$app pm-download ldap
#sudo -u $app $final_path/.composer/vendor/bin/drush @$app pm-enable -y ldap_servers ldap_user ldap_authentication ldap_authorization ldap_authorization_drupal_role
#sudo -u $app $final_path/.composer/vendor/bin/drush @$app core-cron
ynh_exec_as $app $drush upwd --password="$password" "admin" --verbose --debug
ynh_exec_as $app $drush variable-set site_name "Framaforms" --verbose --debug
ynh_exec_as $app $drush variable-set site_mail "no-reply@$domain" --verbose --debug
ynh_exec_as $app $drush variable-set file_private_path "/home/yunohost.app/$app/data" --verbose --debug
#ynh_exec_as $app $drush @$app pm-download ldap
#ynh_exec_as $app $drush @$app pm-enable -y ldap_servers ldap_user ldap_authentication ldap_authorization ldap_authorization_drupal_role
#ynh_exec_as $app $drush @$app core-cron
popd
#=================================================
@ -220,7 +226,7 @@ chown -R $app: $final_path
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring SSOwat..." --time --weight=1
ynh_script_progression --message="Configuring SSOwat..." --weight=1
# Make app public if necessary
if [ $is_public -eq 1 ]
@ -232,7 +238,7 @@ fi
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
ynh_script_progression --message="Reloading nginx web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
@ -240,4 +246,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --time --last
ynh_script_progression --message="Installation of $app completed" --last

View file

@ -8,6 +8,7 @@
source _common.sh
source /usr/share/yunohost/helpers
source ynh_install_php__3
#=================================================
# LOAD SETTINGS
@ -26,7 +27,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#=================================================
# REMOVE THE PostgresSQL DATABASE
#=================================================
ynh_script_progression --message="Removing the database..." --time --weight=1
ynh_script_progression --message="Removing the database..." --weight=1
# Remove a database if it exists, along with the associated user
ynh_psql_remove_db --db_user=$db_user --db_name=$db_name
@ -34,7 +35,7 @@ ynh_psql_remove_db --db_user=$db_user --db_name=$db_name
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --time --weight=1
ynh_script_progression --message="Removing dependencies..." --weight=7
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
@ -42,7 +43,7 @@ ynh_remove_app_dependencies
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory..." --time --weight=1
ynh_script_progression --message="Removing app main directory..." --weight=1
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
@ -50,7 +51,7 @@ ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing nginx web server configuration..." --time --weight=1
ynh_script_progression --message="Removing nginx web server configuration..." --weight=1
# Remove the dedicated nginx config
ynh_remove_nginx_config
@ -58,25 +59,17 @@ ynh_remove_nginx_config
#=================================================
# REMOVE PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Removing php-fpm configuration..." --time --weight=1
ynh_script_progression --message="Removing php-fpm configuration..." --weight=1
# Remove the dedicated php-fpm config
ynh_remove_fpm_config
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE THE CRON FILE
#=================================================
ynh_script_progression --message="Removing the cron file..." --weight=1
# Remove a cron file
ynh_secure_remove --file="/etc/cron.d/$app"
#=================================================
# REMOVE PHP
#=================================================
ynh_script_progression --message="Removing php..." --weight=1
ynh_script_progression --message="Removing php..." --weight=14
ynh_remove_php
@ -85,7 +78,7 @@ ynh_remove_php
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_script_progression --message="Removing the dedicated system user..." --time --weight=1
ynh_script_progression --message="Removing the dedicated system user..." --weight=1
# Delete a system user
ynh_system_user_delete --username=$app
@ -94,4 +87,4 @@ ynh_system_user_delete --username=$app
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --time --last
ynh_script_progression --message="Removal of $app completed" --last

View file

@ -9,6 +9,10 @@
#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 ../settings/scripts/ynh_add_extra_apt_repos__3
source ../settings/scripts/ynh_install_php__3
source ../settings/scripts/ynh_composer__2
source ../settings/scripts/ynh_exec_as
#=================================================
# MANAGE SCRIPT FAILURE
@ -102,7 +106,7 @@ ynh_psql_execute_file_as_root ./db.sql "$db_name"
#=================================================
ynh_script_progression --message="Reloading nginx web server and php-fpm..." --time --weight=1
ynh_systemd_action --service_name=php7.0-fpm --action=reload
ynh_systemd_action --service_name=php7.2-fpm --action=reload
ynh_systemd_action --service_name=nginx --action=reload
#=================================================

View file

@ -8,11 +8,15 @@
source _common.sh
source /usr/share/yunohost/helpers
source ynh_add_extra_apt_repos__3
source ynh_install_php__3
source ynh_composer__2
source ynh_exec_as
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --time --weight=1
ynh_script_progression --message="Loading installation settings..." --weight=2
app=$YNH_APP_INSTANCE_NAME
@ -37,7 +41,7 @@ upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
@ -63,7 +67,7 @@ fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=21
# Backup the current version of the app
ynh_backup_before_upgrade
@ -74,18 +78,6 @@ ynh_clean_setup () {
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
# N.B. : this is for app installations before YunoHost 2.7
# where this value might be something like /foo/ or foo/
# instead of /foo ....
# If nobody installed your app before 2.7, then you may
# safely remove this line
path_url=$(ynh_normalize_url_path --path_url=$path_url)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
@ -94,7 +86,7 @@ path_url=$(ynh_normalize_url_path --path_url=$path_url)
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --time --weight=1
ynh_script_progression --message="Upgrading source files..." --weight=9
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
@ -103,7 +95,7 @@ fi
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading nginx web server configuration..." --time --weight=1
ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1
# Create a dedicated nginx config
ynh_add_nginx_config
@ -111,14 +103,14 @@ ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --time --weight=1
ynh_script_progression --message="Upgrading dependencies..." --weight=5
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app
@ -126,14 +118,14 @@ ynh_system_user_create --username=$app
#=================================================
# UPGRADE PHP
#=================================================
ynh_script_progression --message="Upgrading PHP..." --weight=1
ynh_script_progression --message="Upgrading PHP..." --weight=12
ynh_install_php --phpversion="7.2" --package="$extra_pkg_dependencies"
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading php-fpm configuration..." --time --weight=1
ynh_script_progression --message="Upgrading php-fpm configuration..." --weight=1
# Create a dedicated php-fpm config
ynh_add_fpm_config --phpversion="7.2"
@ -143,25 +135,25 @@ ynh_add_fpm_config --phpversion="7.2"
#=================================================
# UPGRADE COMPOSER
#=================================================
ynh_script_progression --message="Upgrading Composer..." --weight=1
ynh_script_progression --message="Upgrading Composer..." --weight=3
ynh_install_composer --phpversion="7.2" --workdir="$final_path/.composer"
#=================================================
# UPGRADE DRUPAL
#=================================================
ynh_script_progression --message="Upgrading Drupal..." --weight=1
ynh_script_progression --message="Upgrading Drupal..." --time --weight=30
ynh_backup_if_checksum_is_different --file="$final_path/$app/sites/default/settings.php"
drush="$final_path/.composer/vendor/bin/drush --quiet"
pushd $final_path
sudo -u $app $final_path/.composer/vendor/bin/drush @$app variable-set --exact maintenance_mode 1
sudo -u $app $final_path/.composer/vendor/bin/drush @$app cache-clear all
sudo -u $app $final_path/.composer/vendor/bin/drush @$app pm-update -y drupal
sudo -u $app $final_path/.composer/vendor/bin/drush @$app vset --exact maintenance_mode 0
sudo -u $app $final_path/.composer/vendor/bin/drush @$app cache-clear all
sudo -u $app $final_path/.composer/vendor/bin/drush @$app l10n-update-refresh
sudo -u $app $final_path/.composer/vendor/bin/drush @$app l10n-update
ynh_exec_as $app $drush
ynh_exec_as $app $drush variable-set --exact maintenance_mode 1
ynh_exec_as $app $drush cache-clear all
ynh_exec_as $app $drush pm-update -y drupal
ynh_exec_as $app $drush vset --exact maintenance_mode 0
ynh_exec_as $app $drush cache-clear all
popd
#=================================================
@ -180,7 +172,8 @@ ynh_store_file_checksum --file="$config_file"
#=================================================
# Set permissions on app files
chown -R root: $final_path
chown -R $app: $final_path
chown -R $app: "${final_path}_private"
#=================================================
# SETUP SSOWAT

14
scripts/ynh_exec_as Normal file
View file

@ -0,0 +1,14 @@
#!/bin/bash
# Execute a command as another user
# usage: exec_as USER COMMAND [ARG ...]
ynh_exec_as() {
local USER=$1
shift 1
if [[ $USER = $(whoami) ]]; then
eval "$@"
else
sudo -u "$USER" "$@"
fi
}