From 5245009c35424578ea3b77d9bded58d429c00cb5 Mon Sep 17 00:00:00 2001 From: Rodolphe Robles Date: Sat, 4 Apr 2020 03:34:57 +0200 Subject: [PATCH] add hooks to copy file config.dist.php in config.local.php with good options --- hooks/post_app_change_url | 20 +++++++++++++++ hooks/post_app_install | 22 ++++++++++++++++ hooks/post_app_upgrade | 20 +++++++++++++++ scripts/_common.sh | 7 ++++++ scripts/backup | 33 +++++++++++++----------- scripts/install | 41 ++++++++++++++++++++---------- scripts/remove | 20 ++++++++++++--- scripts/restore | 53 +++++++++++++++++++-------------------- 8 files changed, 158 insertions(+), 58 deletions(-) create mode 100644 hooks/post_app_change_url create mode 100644 hooks/post_app_install create mode 100644 hooks/post_app_upgrade diff --git a/hooks/post_app_change_url b/hooks/post_app_change_url new file mode 100644 index 0000000..4c406a8 --- /dev/null +++ b/hooks/post_app_change_url @@ -0,0 +1,20 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# Change options in config.local.php +#================================================= + +ynh_replace_string --match_string="const ROOT = __DIR__;" --replace_string="const ROOT = /var/www/garradin;" --target_file="$final_path/config.dist.php" +ynh_replace_string --match_string="const PREFER_HTTPS = false;" --replace_string="const PREFER_HTTPS = false;" --target_file="$final_path/config.dist.php" +ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '/garradin/';" --target_file="$final_path/config.dist.php" + +sudo cp -a $final_path/config.dist.php $final_path/local.dist.php \ No newline at end of file diff --git a/hooks/post_app_install b/hooks/post_app_install new file mode 100644 index 0000000..5fcbe84 --- /dev/null +++ b/hooks/post_app_install @@ -0,0 +1,22 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# Change options in file config.dist.php +# and copy in local.dist.php +#================================================= + +ynh_replace_string --match_string="const ROOT = __DIR__;" --replace_string="const ROOT = /var/www/garradin;" --target_file="$final_path/config.dist.php" +ynh_replace_string --match_string="const PREFER_HTTPS = false;" --replace_string="const PREFER_HTTPS = false;" --target_file="$final_path/config.dist.php" +ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '/garradin/';" --target_file="$final_path/config.dist.php" +ynh_replace_string --match_string="const SECRET_KEY = '3xUhIgGwuovRKOjVsVPQ5yUMfXUSIOX2GKzcebsz5OINrYC50r';" --replace_string="const SECRET_KEY = 'uqn8jvlmVZLn988lOZiHd1z97hD36V40AnE0LLqLY1801LG3caO';" --target_file="$final_path/config.dist.php" + +sudo cp -a $final_path/config.dist.php $final_path/local.dist.php \ No newline at end of file diff --git a/hooks/post_app_upgrade b/hooks/post_app_upgrade new file mode 100644 index 0000000..3235aa7 --- /dev/null +++ b/hooks/post_app_upgrade @@ -0,0 +1,20 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# Change options in config.local.php +#================================================= + +ynh_replace_string --match_string="const ROOT = __DIR__;" --replace_string="const ROOT = /var/www/garradin;" --target_file="$final_path/config.dist.php" +ynh_replace_string --match_string="const PREFER_HTTPS = false;" --replace_string="const PREFER_HTTPS = false;" --target_file="$final_path/config.dist.php" +ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '/garradin/';" --target_file="$final_path/config.dist.php" + +sudo cp -a $final_path/config.dist.php $final_path/local.dist.php diff --git a/scripts/_common.sh b/scripts/_common.sh index de37a9a..73fbed9 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,5 +1,12 @@ #!/bin/bash +#================================================= +# COMMON VARIABLES +#================================================= + +# dependencies used by the app +pkg_dependencies="php7.0-sqlite3" + # ============= FUTURE YUNOHOST HELPER ============= # Delete a file checksum from the app settings # diff --git a/scripts/backup b/scripts/backup index e8b2422..9329331 100644 --- a/scripts/backup +++ b/scripts/backup @@ -24,40 +24,45 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." --time --weight=1 app=$YNH_APP_INSTANCE_NAME -final_path=$(ynh_app_setting_get $app final_path) -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) #================================================= # STANDARD BACKUP STEPS #================================================= # BACKUP THE APP MAIN DIR #================================================= +ynh_script_progression --message="Backing up the main app directory..." --time --weight=1 -ynh_backup "$final_path" +ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= + --time --weight=1ynh_script_progression --message="Backing up nginx web server configuration..." --time --weight=1 -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP THE PHP-FPM CONFIGURATION #================================================= +ynh_script_progression --message="Backing up php-fpm configuration..." --time --weight=1 -ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf" -ynh_backup "/etc/php/7.0/fpm/conf.d/20-$app.ini" +ynh_backup --src_path="/etc/php/7.0/fpm/pool.d/$app.conf" +ynh_backup --src_path="/etc/php/7.0/fpm/conf.d/20-$app.ini" -# Backup directory location for the app from where the script is executed and -# which will be compressed afterward -backup_dir=$YNH_APP_BACKUP_DIR +# # Backup directory location for the app from where the script is executed and +# # which will be compressed afterward +# backup_dir=$YNH_APP_BACKUP_DIR -# Backup sources & data -ynh_backup "/var/www/$app" "sources" +# # Backup sources & data +# ynh_backup "/var/www/$app" "sources" -# Copy Nginx conf -sudo mkdir -p ./conf -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf" \ No newline at end of file +# # Copy Nginx conf +# sudo mkdir -p ./conf +# ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf" \ No newline at end of file diff --git a/scripts/install b/scripts/install index 1bbd556..f3c2ba4 100644 --- a/scripts/install +++ b/scripts/install @@ -29,6 +29,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 final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" @@ -39,41 +40,44 @@ path_url=$(ynh_normalize_url_path $path_url) # Check web path availability ynh_webpath_available $domain $path_url # Register (book) web path -ynh_webpath_register $app $domain $path_url +ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= +ynh_script_progression --message="Storing installation settings..." --time --weight=1 -ynh_app_setting_set $app path_url $path_url -ynh_app_setting_set $app domain $domain -ynh_app_setting_set $app is_public $is_public +ynh_app_setting_set --app=$app --key=domain --value=$domain +ynh_app_setting_set --app=$app --key=path --value=$path_url +ynh_app_setting_set --app=$app --key=is_public --value=$is_public #================================================= # Install dependency to convert tracks to a readable format for the browser #================================================= +ynh_script_progression --message="Installing dependencies..." --time --weight=1 if [ "$(lsb_release --codename --short)" != "jessie" ] then - ynh_install_app_dependencies php7.0-sqlite3 + ynh_install_app_dependencies $pkg_dependencies else - ynh_install_app_dependencies php5-sqlite + ynh_die --message="Votre version de Debian n'est pas compatible..." --time --weight=1 fi #================================================= # CREATE DEDICATED USER #================================================= - +ynh_script_progression --message="Configuring system user..." --time --weight=1 # Create a system user -ynh_system_user_create $app +ynh_system_user_create --username=$app #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Setting up source files..." --time --weight=1 -ynh_app_setting_set $app final_path $final_path +ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source "$final_path" +ynh_setup_source --dest_dir="$final_path" #================================================= # Files owned by user app @@ -85,13 +89,14 @@ sudo chmod 755 $final_path -R #================================================= # NGINX CONFIGURATION #================================================= - +ynh_script_progression --message="Configuring nginx web server..." --time --weight=1 # Create a dedicated nginx config ynh_add_nginx_config #================================================= # PHP-FPM CONFIGURATION #================================================= +ynh_script_progression --message="Configuring php-fpm..." --time --weight=1 # Create a dedicated php-fpm config ynh_add_fpm_config @@ -99,6 +104,9 @@ ynh_add_fpm_config #================================================= # SETUP SSOWAT #================================================= +ynh_script_progression --message="Configuring SSOwat..." --time --weight=1 + + if [ $is_public -eq 0 ] then # Remove the public access @@ -108,11 +116,18 @@ fi if [ $is_public -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set $app unprotected_uris "/" + ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" fi #================================================= # RELOAD NGINX #================================================= +ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 -systemctl reload nginx \ No newline at end of file +systemctl reload nginx + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Installation of $app completed" --time --last \ No newline at end of file diff --git a/scripts/remove b/scripts/remove index 079d4d3..aac63fd 100644 --- a/scripts/remove +++ b/scripts/remove @@ -12,15 +12,17 @@ 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 domain) -final_path=$(ynh_app_setting_get $app final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # REMOVE DEPENDENCIES #================================================= +ynh_script_progression --message="Removing dependencies..." --time --weight=1 # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -28,13 +30,15 @@ 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 "$final_path" +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 @@ -42,6 +46,7 @@ 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 @@ -51,6 +56,13 @@ ynh_remove_fpm_config #================================================= # REMOVE DEDICATED USER #================================================= +ynh_script_progression --message="Removing the dedicated system user..." --time --weight=1 # Delete a system user -ynh_system_user_delete $app \ No newline at end of file +ynh_system_user_delete --username=$app + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Removal of $app completed" --time --last \ No newline at end of file diff --git a/scripts/restore b/scripts/restore index 61e3b2a..d1e75b7 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,12 +6,8 @@ # IMPORT GENERIC HELPERS #================================================= -if [ ! -e _common.sh ]; then - # Get the _common.sh file if it's not in the current directory - cp ../settings/scripts/_common.sh ./_common.sh - chmod a+rx _common.sh -fi -source _common.sh +#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 #================================================= @@ -24,16 +20,18 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading settings..." --time --weight=1 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -final_path=$(ynh_app_setting_get $app final_path) +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 #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= +ynh_script_progression --message="Validating restoration parameters..." --time --weight=1 ynh_webpath_available $domain $path_url \ || ynh_die "Path not available: ${domain}${path_url}" @@ -57,9 +55,10 @@ ynh_restore_file "$final_path" #================================================= # 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 $app +ynh_system_user_create --username=$app #================================================= # RESTORE USER RIGHTS @@ -73,11 +72,10 @@ chown -R $app:$app $final_path #================================================= if [ "$(lsb_release --codename --short)" != "jessie" ] then - ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf" - ynh_restore_file "/etc/php/7.0/fpm/conf.d/20-$app.ini" + ynh_restore_file --origin_path="/etc/php/7.0/fpm/pool.d/$app.conf" + ynh_restore_file --origin_path="/etc/php/7.0/fpm/conf.d/20-$app.ini" else - ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf" - ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini" + ynh_die --message="Votre version de Debian n'est pas compatible..." fi #================================================= @@ -85,23 +83,24 @@ fi #================================================= # REINSTALL DEPENDENCIES #================================================= +ynh_script_progression --message="Reinstalling dependencies..." --time --weight=1 + +# Define and install dependencies +ynh_install_app_dependencies php7.0-sqlite3 -if [ "$(lsb_release --codename --short)" != "jessie" ] -then - ynh_install_app_dependencies php7.0-sqlite3 -else - ynh_install_app_dependencies php5-sqlite -fi #================================================= # GENERIC FINALIZATION #================================================= # RELOAD NGINX AND PHP-FPM #================================================= -if [ "$(lsb_release --codename --short)" != "jessie" ] -then - systemctl reload php7.0-fpm -else - systemctl reload php5-fpm -fi -systemctl reload nginx \ No newline at end of file +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=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Restoration completed for $app" --time --last \ No newline at end of file