From 9ba5395970bc827fc23378059d80f2581089fa92 Mon Sep 17 00:00:00 2001 From: tituspijean Date: Tue, 15 Aug 2023 17:52:30 +0200 Subject: [PATCH] Packaging v2 --- check_process | 22 -------- conf/app.src | 7 --- conf/nginx.conf | 2 +- conf/php-fpm.conf | 2 +- manifest.json | 55 ------------------- manifest.toml | 68 ++++++++++++++++++++++++ scripts/_common.sh | 2 - scripts/backup | 21 +------- scripts/change_url | 91 +------------------------------ scripts/install | 125 ++++++------------------------------------- scripts/remove | 40 -------------- scripts/restore | 51 +++--------------- scripts/upgrade | 130 +++++++-------------------------------------- tests.toml | 5 ++ 14 files changed, 119 insertions(+), 502 deletions(-) delete mode 100644 check_process delete mode 100644 conf/app.src delete mode 100644 manifest.json create mode 100644 manifest.toml create mode 100644 tests.toml diff --git a/check_process b/check_process deleted file mode 100644 index 8e1aba9..0000000 --- a/check_process +++ /dev/null @@ -1,22 +0,0 @@ -;; Test complet - ; Manifest - domain="domain.tld" - path="/path" - is_public=1 - admin="john" - ; Checks - pkg_linter=1 - setup_sub_dir=1 - setup_root=1 - setup_nourl=0 - setup_private=1 - setup_public=1 - upgrade=1 - upgrade=1 from_commit=f356f5b8f496f626aba3ec0f9d9c40c4cb54e7f6 - backup_restore=1 - multi_instance=1 - port_already_use=0 - change_url=1 -;;; Options -Email= -Notification=none diff --git a/conf/app.src b/conf/app.src deleted file mode 100644 index b78a417..0000000 --- a/conf/app.src +++ /dev/null @@ -1,7 +0,0 @@ -SOURCE_URL=http://download.dotclear.org/latest/dotclear-2.27.1.zip -SOURCE_SUM=5f80ffca818424b7ff7da79d4d00edfd8785e98dafd0562b0f964a5808728d63 -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=zip -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= -SOURCE_EXTRACT=true diff --git a/conf/nginx.conf b/conf/nginx.conf index b26a6dc..c5d0284 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -2,7 +2,7 @@ location __PATH__/ { # Path to source - alias __FINALPATH__/ ; + alias __INSTALL_DIR__/ ; index index.php; diff --git a/conf/php-fpm.conf b/conf/php-fpm.conf index ab1a471..13a53b0 100644 --- a/conf/php-fpm.conf +++ b/conf/php-fpm.conf @@ -358,7 +358,7 @@ request_terminate_timeout = 1d ; Chdir to this directory at the start. ; Note: relative path can be used. ; Default Value: current directory or / when chroot -chdir = __FINALPATH__ +chdir = __INSTALL_DIR__ ; Redirect worker stdout and stderr into main error log. If not set, stdout and ; stderr will be redirected to /dev/null according to FastCGI specs. diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 7809a4a..0000000 --- a/manifest.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "name": "DotClear 2", - "id": "dotclear2", - "packaging_format": 1, - "description": { - "en": "Blog publishing application", - "fr": "Moteur de blog" - }, - "version": "2.27.1~ynh1", - "license": "GPL-2.0-or-later", - "url": "https://dotclear.org/", - "upstream": { - "license": "GPL-2.0-or-later", - "website": "https://dotclear.org", - "demo": "https://www.softaculous.com/demos/Dotclear", - "admindoc": "https://dotclear.org/documentation/2.0", - "code": "https://git.dotclear.org/dev/dotclear" - }, - "maintainer": { - "name": "kay0u", - "email": "pierre@kayou.io" - }, - "requirements": { - "yunohost": ">= 11.0.0" - }, - "multi_instance": true, - "services": [ - "nginx", - "php7.3-fpm", - "mysql" - ], - "arguments": { - "install": [ - { - "name": "domain", - "type": "domain" - }, - { - "name": "path", - "type": "path", - "example": "/dotclear2", - "default": "/dotclear2" - }, - { - "name": "is_public", - "type": "boolean", - "default": true - }, - { - "name": "admin", - "type": "user" - } - ] - } -} diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..6b7b920 --- /dev/null +++ b/manifest.toml @@ -0,0 +1,68 @@ +packaging_format = 2 + +id = "dotclear2" +name = "DotClear 2" +description.en = "Blog publishing application" +description.fr = "Moteur de blog" + +version = "2.27.1~ynh1" + +maintainers = ["kay0u"] + +[upstream] +license = "GPL-2.0-or-later" +website = "https://dotclear.org" +demo = "https://www.softaculous.com/demos/Dotclear" +admindoc = "https://dotclear.org/documentation/2.0" +code = "https://git.dotclear.org/dev/dotclear" +cpe = "cpe:2.3:a:dotclear:dotclear" +fund = "https://dotclear.org/donate" + +[integration] +yunohost = ">= 11.0.0" +architectures = "all" +multi_instance = true +ldap = true +sso = false +disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ... +ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... +ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... + +[install] + [install.domain] + type = "domain" + + [install.path] + type = "path" + default = "/dotclear2" + + [install.init_main_permission] + type = "group" + default = "visitors" + + [install.admin] + type = "user" + +[resources] + [resources.sources.latest] + prefetch = false + url = "http://download.dotclear.org/latest/dotclear-2.27.1.zip" + sha256 = "15d5d139dffd5e53f7c2301e01f085edcdbed7a89d9e829864a81b7b99cba5e8" + + [resources.sources.attic] + prefetch = false + url = "http://download.dotclear.org/attic/dotclear-2.27.1.zip" + sha256 = "15d5d139dffd5e53f7c2301e01f085edcdbed7a89d9e829864a81b7b99cba5e8" + + [resources.system_user] + + [resources.install_dir] + + [resources.permissions] + main.url = "/" + + [resources.database] + type = "mysql" + + [resources.apt] + packages = ["php8.2", "php8.2-fpm"] diff --git a/scripts/_common.sh b/scripts/_common.sh index 092a127..944a65e 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,8 +4,6 @@ # COMMON VARIABLES #================================================= -phpversion=8.2 - #================================================= # PERSONAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index 2fa3523..04eed75 100755 --- a/scripts/backup +++ b/scripts/backup @@ -10,25 +10,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# 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 - -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) - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= @@ -38,7 +19,7 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$final_path" +ynh_backup --src_path="$install_dir" #================================================= # BACKUP THE NGINX CONFIGURATION diff --git a/scripts/change_url b/scripts/change_url index cd8e436..40f93a7 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -9,62 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -old_domain=$YNH_APP_OLD_DOMAIN -old_path=$YNH_APP_OLD_PATH - -new_domain=$YNH_APP_NEW_DOMAIN -new_path=$YNH_APP_NEW_PATH - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -# Needed for helper "ynh_add_nginx_config" -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - -# Add settings here as needed by your application -db_name=$(ynh_app_setting_get --app=$app --key=db_name) - -#================================================= -# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. - ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" - - # Restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# CHECK WHICH PARTS SHOULD BE CHANGED -#================================================= - -change_domain=0 -if [ "$old_domain" != "$new_domain" ] -then - change_domain=1 -fi - -change_path=0 -if [ "$old_path" != "$new_path" ] -then - change_path=1 -fi - #================================================= # STANDARD MODIFICATIONS #================================================= @@ -72,29 +16,7 @@ fi #================================================= ynh_script_progression --message="Updating NGINX web server configuration..." --weight=2 -nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf - -# Change the path in the NGINX config file -if [ $change_path -eq 1 ] -then - # Make a backup of the original NGINX config file if modified - ynh_backup_if_checksum_is_different --file="$nginx_conf_path" - # Set global variables for NGINX helper - domain="$old_domain" - path_url="$new_path" - # Create a dedicated NGINX config - ynh_add_nginx_config -fi - -# Change the domain for NGINX -if [ $change_domain -eq 1 ] -then - # Delete file checksum for the old conf file location - ynh_delete_file_checksum --file="$nginx_conf_path" - mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf - # Store file checksum for the new config file location - ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" -fi +ynh_change_url_nginx_config #================================================= # SPECIFIC MODIFICATIONS @@ -116,7 +38,7 @@ ynh_mysql_execute_as_root --sql="UPDATE dc_setting SET setting_value='$new_theme #================================================= ynh_script_progression --message="Updating configuration file..." -php_config=$final_path/inc/config.php +php_config=$install_dir/inc/config.php ynh_backup_if_checksum_is_different --file="$php_config" @@ -129,15 +51,6 @@ ynh_store_file_checksum --file="$php_config" chmod 400 "$php_config" chown $app:$app "$php_config" -#================================================= -# GENERIC FINALISATION -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." - -ynh_systemd_action --service_name=nginx --action=reload - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/install b/scripts/install index 6f6bf78..b9a5f84 100755 --- a/scripts/install +++ b/scripts/install @@ -9,86 +9,26 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# RETRIEVE ARGUMENTS FROM THE MANIFEST -#================================================= - -domain=$YNH_APP_ARG_DOMAIN -path_url=$YNH_APP_ARG_PATH -is_public=$YNH_APP_ARG_IS_PUBLIC -admin=$YNH_APP_ARG_ADMIN - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS -#================================================= -ynh_script_progression --message="Validating installation parameters..." - -final_path=/var/www/$app -test ! -e "$final_path" || ynh_die --message="This path already contains a folder" - -# Register (book) web path -ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url - -#================================================= -# STORE SETTINGS FROM MANIFEST -#================================================= -ynh_script_progression --message="Storing installation settings..." - -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=admin --value=$admin - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." --weight=2 - -# Create a system user -ynh_system_user_create --username=$app --home_dir="$final_path" - -#================================================= -# CREATE A MYSQL DATABASE -#================================================= -ynh_script_progression --message="Creating a MySQL database..." --weight=2 - -db_name=$(ynh_sanitize_dbid --db_name=$app) -db_user=$db_name -ynh_app_setting_set --app=$app --key=db_name --value=$db_name -ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name -db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=4 -ynh_app_setting_set --app=$app --key=final_path --value=$final_path - # In case of a new version, the url change from http://download.dotclear.org/latest/dotclear-X.X.X.tar.gz to http://download.dotclear.org/attic/dotclear-X.X.X.tar.gz -src_url=$(grep 'SOURCE_URL=' "../conf/app.src" | cut -d= -f2-) +src_url=$(cat $YNH_APP_BASEDIR/manifest.toml | toml_to_json | jq ".resources.sources[latest].url") if ! curl --output /dev/null --silent --head --fail "$src_url"; then - ynh_replace_string --match_string="latest" --replace_string="attic" --target_file="../conf/app.src" + ynh_setup_source --dest_dir="$install_dir" --source_id="attic" +else + ynh_setup_source --dest_dir="$install_dir" --source_id="latest" fi -# Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source --dest_dir="$final_path" - -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" +chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R $app:www-data "$install_dir" # https://dotclear.org/documentation/2.0/admin/install -mkdir -p "$final_path/"{cache,public} -setfacl -m d:u:www-data:rwx "$final_path/"{cache,public} +mkdir -p "$install_dir/"{cache,public} +setfacl -m d:u:www-data:rwx "$install_dir/"{cache,public} #================================================= # NGINX CONFIGURATION @@ -104,7 +44,7 @@ ynh_add_nginx_config ynh_script_progression --message="Configuring PHP-FPM..." --weight=2 # Create a dedicated PHP-FPM config -ynh_add_fpm_config --phpversion=$phpversion +ynh_add_fpm_config #================================================= # SPECIFIC SETUP @@ -113,14 +53,14 @@ ynh_add_fpm_config --phpversion=$phpversion #================================================= ynh_script_progression --message="Adding a configuration file..." -php_config=$final_path/inc/config.php +php_config=$install_dir/inc/config.php master_key=$(ynh_string_random --length=30) ynh_app_setting_set --app=$app --key=master_key --value=$master_key cp $php_config.in $php_config -admin_url="${path_url%/}/admin/" +admin_url="${path%/}/admin/" email=$(ynh_user_get_info --username=$admin --key=mail) @@ -145,6 +85,7 @@ blog_media_admin="false" blog_media="false" blog_pages="false" blog_blogroll="false" + ynh_app_setting_set --app=$app --key=blog_admin --value=$blog_admin ynh_app_setting_set --app=$app --key=blog_contentadmin --value=$blog_contentadmin ynh_app_setting_set --app=$app --key=blog_usage --value=$blog_usage @@ -156,7 +97,7 @@ ynh_app_setting_set --app=$app --key=blog_media --value=$blog_media ynh_app_setting_set --app=$app --key=blog_pages --value=$blog_pages ynh_app_setting_set --app=$app --key=blog_blogroll --value=$blog_blogroll -ynh_add_config --template="../conf/class.auth.ldap.php" --destination="$final_path/inc/class.auth.ldap.php" +ynh_add_config --template="../conf/class.auth.ldap.php" --destination="$install_dir/inc/class.auth.ldap.php" cat << EOF >> $php_config @@ -172,16 +113,6 @@ chown $app:$app "$php_config" #================================================= # SETUP APPLICATION WITH CURL #================================================= -ynh_script_progression --message="Setuping application with CURL..." - -# Set the app as temporarily public for curl call -ynh_script_progression --message="Configuring SSOwat..." -# Making the app public for curl -ynh_permission_update --permission="main" --add="visitors" - -# Reload Nginx -ynh_systemd_action --service_name=nginx --action=reload - ynh_script_progression --message="Finalizing installation..." --weight=14 firstname=$(ynh_user_get_info --username=$admin --key=firstname) @@ -195,9 +126,6 @@ installUrl="/admin/install/index.php" ynh_local_curl $installUrl "u_email=$email" "u_firstname=$firstname" "u_name=$lastname" "u_login=$admin" "u_pwd=$password" "u_pwd2=$password" -# Remove the public access -ynh_permission_update --permission="main" --remove="visitors" - #================================================= # GENERIC FINALIZATION #================================================= @@ -206,30 +134,7 @@ ynh_permission_update --permission="main" --remove="visitors" ynh_script_progression --message="Configuring Fail2Ban..." # Create a dedicated Fail2Ban config -ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Invalid credentials in $final_path/inc/class.auth.ldap.php .* client: , .*https://$domain${path_url%/}/admin/auth.php" - -#================================================= -# SETUP SSOWAT -#================================================= -ynh_script_progression --message="Configuring permissions..." - -# Make app public if necessary -if [ $is_public -eq 1 ] -then - # Everyone can access the app. - # The "main" permission is automatically created before the install script. - ynh_permission_update --permission="main" --add="visitors" -fi - -# Only the admin can access the admin panel of the app (if the app has an admin panel) -ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." - -ynh_systemd_action --service_name=nginx --action=reload +ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Invalid credentials in $install_dir/inc/class.auth.ldap.php .* client: , .*https://$domain${path%/}/admin/auth.php" #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index f2a4bf0..768ea30 100755 --- a/scripts/remove +++ b/scripts/remove @@ -9,36 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_user=$db_name -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - -#================================================= -# STANDARD REMOVE -#================================================= -# REMOVE THE MYSQL DATABASE -#================================================= -ynh_script_progression --message="Removing the MySQL database..." - -# Remove a database if it exists, along with the associated user -ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name - -#================================================= -# REMOVE APP MAIN DIR -#================================================= -ynh_script_progression --message="Removing app main directory..." - -# Remove the app directory securely -ynh_secure_remove --file="$final_path" - #================================================= # REMOVE NGINX CONFIGURATION #================================================= @@ -63,16 +33,6 @@ ynh_script_progression --message="Removing Fail2Ban configuration..." # Remove the dedicated Fail2Ban config ynh_remove_fail2ban_config -#================================================= -# GENERIC FINALIZATION -#================================================= -# REMOVE DEDICATED USER -#================================================= -ynh_script_progression --message="Removing the dedicated system user..." - -# Delete a system user -ynh_system_user_delete --username=$app - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index 619a437..ee62cc6 100755 --- a/scripts/restore +++ b/scripts/restore @@ -10,35 +10,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -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) -db_user=$db_name -phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) - -#================================================= -# CHECK IF THE APP CAN BE RESTORED -#================================================= -ynh_script_progression --message="Validating restoration parameters..." - -test ! -d $final_path \ - || ynh_die --message="There is already a directory: $final_path " - #================================================= # STANDARD RESTORATION STEPS #================================================= @@ -48,28 +19,20 @@ ynh_script_progression --message="Restoring the NGINX configuration..." 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..." --weight=2 - -# 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..." -ynh_restore_file --origin_path="$final_path" +ynh_restore_file --origin_path="$install_dir" -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" +chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R $app:www-data "$install_dir" # https://dotclear.org/documentation/2.0/admin/install -mkdir -p "$final_path/"{cache,public} -setfacl -m d:u:www-data:rwx "$final_path/"{cache,public} +mkdir -p "$install_dir/"{cache,public} +setfacl -m d:u:www-data:rwx "$install_dir/"{cache,public} #================================================= # RESTORE THE PHP-FPM CONFIGURATION @@ -94,8 +57,6 @@ ynh_systemd_action --action=restart --service_name=fail2ban #================================================= ynh_script_progression --message="Restoring the MySQL database..." --weight=3 -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 #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 440903d..6486b5d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,34 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_app_setting_get --app=$app --key=path) -admin=$(ynh_app_setting_get --app=$app --key=admin) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_user=$db_name -db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) -password=$(ynh_app_setting_get --app=$app --key=password) -master_key=$(ynh_app_setting_get --app=$app --key=master_key) - -blog_admin=$(ynh_app_setting_get --app=$app --key=blog_admin) -blog_contentadmin=$(ynh_app_setting_get --app=$app --key=blog_contentadmin) -blog_usage=$(ynh_app_setting_get --app=$app --key=blog_usage) -blog_publish=$(ynh_app_setting_get --app=$app --key=blog_publish) -blog_delete=$(ynh_app_setting_get --app=$app --key=blog_delete) -blog_categories=$(ynh_app_setting_get --app=$app --key=blog_categories) -blog_media_admin=$(ynh_app_setting_get --app=$app --key=blog_media_admin) -blog_media=$(ynh_app_setting_get --app=$app --key=blog_media) -blog_pages=$(ynh_app_setting_get --app=$app --key=blog_pages) -blog_blogroll=$(ynh_app_setting_get --app=$app --key=blog_blogroll) - #================================================= # CHECK VERSION #================================================= @@ -44,20 +16,6 @@ ynh_script_progression --message="Checking 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)..." --weight=4 - -# 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 - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -65,38 +23,6 @@ ynh_abort_if_errors #================================================= ynh_script_progression --message="Ensuring downward compatibility..." -# 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 [ -n "$(ynh_app_setting_get --app=$app --key=is_public)" ]; then - ynh_app_setting_delete --app=$app --key=protected_uris - - # Removing skipped/unprotected_uris under certain conditions, remove the visitors group added during the migration process of 3.7 - # Remove unprotected_uris. If the app was public, add visitors again to the main permission - if ynh_permission_has_user --permission=main --user=visitors - then - ynh_app_setting_delete --app=$app --key=unprotected_uris - ynh_permission_update --permission "main" --add "visitors" - else - ynh_app_setting_delete --app=$app --key=unprotected_uris - fi - ynh_app_setting_delete --app=$app --key=is_public -fi - -if ! ynh_permission_exists --permission="admin"; then - # Create the required permissions - ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin -fi - if [ -z "$blog_admin" ] || [ -z "$blog_contentadmin" ] || [ -z "$blog_usage" ] || @@ -117,51 +43,43 @@ if [ -z "$blog_admin" ] || blog_media="false" blog_pages="false" blog_blogroll="false" - ynh_app_setting_set --app=$app --key=blog_admin --value=$blog_admin - ynh_app_setting_set --app=$app --key=blog_contentadmin --value=$blog_contentadmin + ynh_app_setting_set --app=$app --key=blog_admin --value=$blog_admin + ynh_app_setting_set --app=$app --key=blog_contentadmin --value=$blog_contentadmin ynh_app_setting_set --app=$app --key=blog_usage --value=$blog_usage ynh_app_setting_set --app=$app --key=blog_publish --value=$blog_publish ynh_app_setting_set --app=$app --key=blog_delete --value=$blog_delete ynh_app_setting_set --app=$app --key=blog_categories --value=$blog_categories - ynh_app_setting_set --app=$app --key=blog_media_admin --value=$blog_media_admin + ynh_app_setting_set --app=$app --key=blog_media_admin --value=$blog_media_admin ynh_app_setting_set --app=$app --key=blog_media --value=$blog_media ynh_app_setting_set --app=$app --key=blog_pages --value=$blog_pages ynh_app_setting_set --app=$app --key=blog_blogroll --value=$blog_blogroll fi -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." - -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir=$final_path - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= if [ "$upgrade_type" == "UPGRADE_APP" ] then - # Download, check integrity, uncompress and patch the source from app.src - # In case of a new version, the url change from http://download.dotclear.org/latest/dotclear-X.X.X.tar.gz to http://download.dotclear.org/attic/dotclear-X.X.X.tar.gz - src_url=$(grep 'SOURCE_URL=' "../conf/app.src" | cut -d= -f2-) - if ! curl --output /dev/null --silent --head --fail "$src_url"; then - ynh_replace_string "latest" "attic" ../conf/app.src - fi ynh_script_progression --message="Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path" + # In case of a new version, the url change from http://download.dotclear.org/latest/dotclear-X.X.X.tar.gz to http://download.dotclear.org/attic/dotclear-X.X.X.tar.gz + src_url=$(cat $YNH_APP_BASEDIR/manifest.toml | toml_to_json | jq ".resources.sources[latest].url") + if ! curl --output /dev/null --silent --head --fail "$src_url"; then + ynh_setup_source --dest_dir="$install_dir" --source_id="attic" + else + ynh_setup_source --dest_dir="$install_dir" --source_id="latest" + fi fi -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" +chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R $app:www-data "$install_dir" # https://dotclear.org/documentation/2.0/admin/install -mkdir -p "$final_path/"{cache,public} -setfacl -m d:u:www-data:rwx "$final_path/"{cache,public} +mkdir -p "$install_dir/"{cache,public} +setfacl -m d:u:www-data:rwx "$install_dir/"{cache,public} #================================================= # NGINX CONFIGURATION @@ -177,7 +95,7 @@ ynh_add_nginx_config ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=2 # Create a dedicated PHP-FPM config -ynh_add_fpm_config --phpversion=$phpversion +ynh_add_fpm_config #================================================= # SPECIFIC UPGRADE @@ -186,13 +104,13 @@ ynh_add_fpm_config --phpversion=$phpversion #================================================= ynh_script_progression --message="Updating a configuration file..." -php_config=$final_path/inc/config.php +php_config=$install_dir/inc/config.php ynh_backup_if_checksum_is_different --file=$php_config cp $php_config.in $php_config -admin_url="${path_url%/}/admin/" +admin_url="${path%/}/admin/" email=$(ynh_user_get_info --username=$admin --key=mail) @@ -207,7 +125,7 @@ ynh_replace_string --match_string="'DC_ADMIN_URL', ''" --replace_string="'DC_ADM ynh_replace_string --match_string="'DC_ADMIN_MAILFROM', ''" --replace_string="'DC_ADMIN_MAILFROM', '$email'" --target_file=$php_config # Adding LDAP login -ynh_add_config --template="../conf/class.auth.ldap.php" --destination="$final_path/inc/class.auth.ldap.php" +ynh_add_config --template="../conf/class.auth.ldap.php" --destination="$install_dir/inc/class.auth.ldap.php" cat << EOF >> $php_config @@ -237,15 +155,7 @@ ynh_local_curl $adminUrl ynh_script_progression --message="Reconfiguring Fail2Ban..." # Create a dedicated Fail2Ban config -ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Invalid credentials in $final_path/inc/class.auth.ldap.php .* client: , .*https://$domain${path_url%/}/admin/auth.php" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server and PHP-FRM..." - -ynh_systemd_action --service_name=nginx --action=reload -ynh_systemd_action --service_name=php$YNH_PHP_VERSION-fpm --action=reload +ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Invalid credentials in $install_dir/inc/class.auth.ldap.php .* client: , .*https://$domain${path%/}/admin/auth.php" #================================================= # END OF SCRIPT diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..1520b9b --- /dev/null +++ b/tests.toml @@ -0,0 +1,5 @@ +test_format = 1.0 + +[default] + + test_upgrade_from.f356f5b8f496f626aba3ec0f9d9c40c4cb54e7f6.name = "2.15.2~ynh1"