diff --git a/check_process b/check_process deleted file mode 100644 index 98cba45..0000000 --- a/check_process +++ /dev/null @@ -1,25 +0,0 @@ -;; Test complet - ; Manifest - domain="domain.tld" - path="/path" - admin="john" - ; Checks - pkg_linter=1 - setup_sub_dir=1 - setup_root=1 - setup_nourl=0 - setup_private=0 - setup_public=0 - upgrade=1 - upgrade=1 from_commit=7e3914481ac4d6c40f3be3f35f155fac6f4387c6 - backup_restore=1 - multi_instance=1 - port_already_use=0 - change_url=1 -;;; Options -Email= -Notification=none -;;; Upgrade options - ; commit=CommitHash - name=16.0.5 - manifest_arg=domain=DOMAIN&path=PATH&admin=USER& diff --git a/conf/install.forced.php b/conf/install.forced.php index b797e31..78aecd9 100644 --- a/conf/install.forced.php +++ b/conf/install.forced.php @@ -25,7 +25,7 @@ $force_install_noedit = 2; $force_install_message = 'Welcome to your Dolibarr install'; /** @var string Data root absolute path (documents folder) */ -$force_install_main_data_root = null; +$force_install_main_data_root = '__DATA_DIR__'; /** @var bool Force HTTPS */ $force_install_mainforcehttps = true; @@ -46,7 +46,7 @@ $force_install_port = 3306; $force_install_prefix = 'llx_'; /** @var bool Force database creation */ -$force_install_createdatabase = false; +$force_install_createdatabase = true; /** @var string Database username */ $force_install_databaselogin = '__DB_USER__'; diff --git a/conf/nginx.conf b/conf/nginx.conf index 06a9322..eae8d07 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -2,7 +2,7 @@ location __PATH__/ { # Path to source - alias __FINALPATH__/htdocs/ ; + alias __INSTALL_DIR__/htdocs/; index index.php; diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md deleted file mode 100644 index e69de29..0000000 diff --git a/hooks/post_user_create b/hooks/post_user_create index bd9cbd2..5a6ed86 100644 --- a/hooks/post_user_create +++ b/hooks/post_user_create @@ -1,6 +1,6 @@ #!/bin/bash app="$(basename $0 | cut -d- -f 2-)" # Extract the app name from the script name, which is supposed to be something like "50-app_id" -src_path=$(yunohost app setting $app final_path) +src_path=$(yunohost app setting $app install_dir) # member=__MEMBER__ # Sync users diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 28fcc73..0000000 --- a/manifest.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "name": "Dolibarr", - "id": "dolibarr", - "packaging_format": 1, - "description": { - "en": "Manage the various aspects of your business or association", - "fr": "Gérez les différents aspects de votre activité pro ou associative" - }, - "version": "18.0.3~ynh1", - "url": "https://www.dolibarr.org/", - "upstream": { - "license": "GPL-3.0-or-later", - "website": "https://www.dolibarr.org/", - "demo": "https://www.dolibarr.org/onlinedemo", - "admindoc": "https://www.dolibarr.org/documentation-home", - "userdoc": "https://www.dolibarr.org/#features", - "code": "https://github.com/Dolibarr/dolibarr", - "cpe": "cpe:2.3:a:dolibarr:dolibarr" - }, - "license": "GPL-3.0-or-later", - "maintainer": { - "name": "mastereur", - "url": "https://github.com/mastereur" - }, - "requirements": { - "yunohost": ">= 11.2" - }, - "multi_instance": true, - "services": [ - "nginx", - "php8.1-fpm", - "mysql" - ], - "arguments": { - "install": [ - { - "name": "domain", - "type": "domain" - }, - { - "name": "path", - "type": "path", - "example": "/dolibarr", - "default": "/dolibarr" - }, - { - "name": "admin", - "type": "user" - } - ] - } -} \ No newline at end of file diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..6c5bc33 --- /dev/null +++ b/manifest.toml @@ -0,0 +1,63 @@ +packaging_format = 2 + +id = "dolibarr" +name = "Dolibarr" +description.en = "Manage the various aspects of your business or association" +description.fr = "Gérez les différents aspects de votre activité pro ou associative" + +version = "18.0.3~ynh1" + +maintainers = ["mastereur"] + +[upstream] +license = "GPL-3.0-or-later" +website = "https://www.dolibarr.org/" +demo = "https://www.dolibarr.org/onlinedemo" +admindoc = "https://www.dolibarr.org/documentation-home" +userdoc = "https://www.dolibarr.org/#features" +code = "https://github.com/Dolibarr/dolibarr" + +[integration] +yunohost = ">= 11.2" +architectures = "all" +multi_instance = true + +ldap = true + +sso = false + +disk = "50M" +ram.build = "50M" +ram.runtime = "50M" + +[install] + [install.domain] + type = "domain" + + [install.path] + type = "path" + default = "/dolibarr" + + [install.init_main_permission] + type = "group" + default = "visitors" + + [install.admin] + type = "user" + +[resources] + + [resources.system_user] + + [resources.install_dir] + + [resources.data_dir] + + [resources.permissions] + main.url = "/" + + [resources.apt] + packages = "mariadb-server, php8.1-imagick, php8.1-gd, php8.1-mbstring, php8.1-soap, php8.1-curl, php8.1-intl, php8.1-opcache, php8.1-calendar, php8.1-zip, php8.1-xml, php8.1-fileinfo, php8.1-imap" + + [resources.database] + type = "mysql" diff --git a/scripts/_common.sh b/scripts/_common.sh index 562acb3..944a65e 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -3,24 +3,6 @@ #================================================= # COMMON VARIABLES #================================================= -YNH_PHP_VERSION="8.1" - -php_dependencies="php$YNH_PHP_VERSION-mysql \ - php$YNH_PHP_VERSION-imagick \ - php$YNH_PHP_VERSION-gd \ - php$YNH_PHP_VERSION-mbstring \ - php$YNH_PHP_VERSION-soap \ - php$YNH_PHP_VERSION-curl \ - php$YNH_PHP_VERSION-intl \ - php$YNH_PHP_VERSION-opcache \ - php$YNH_PHP_VERSION-calendar \ - php$YNH_PHP_VERSION-zip \ - php$YNH_PHP_VERSION-xml \ - php$YNH_PHP_VERSION-fileinfo \ - php$YNH_PHP_VERSION-imap" - -# dependencies used by the app (must be on a single line) -pkg_dependencies="$php_dependencies" #================================================= # PERSONAL HELPERS diff --git a/scripts/backup b/scripts/backup index 94a664e..3e51850 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 8927180..b50f43a 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -9,59 +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..." --weight=1 - -# Needed for helper "ynh_add_nginx_config" -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1 - -# 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 #================================================= @@ -69,29 +16,7 @@ fi #================================================= ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 -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 @@ -99,16 +24,7 @@ fi # UPDATE conf file #================================================= -ynh_replace_string --match_string="$old_domain$old_path" --replace_string="$new_domain$new_path" --target_file="$final_path/htdocs/conf/conf.php" - -#================================================= -# GENERIC FINALISATION -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -ynh_systemd_action --service_name=nginx --action=reload +ynh_replace_string --match_string="$old_domain$old_path" --replace_string="$new_domain$new_path" --target_file="$install_dir/htdocs/conf/conf.php" #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index c68ac42..f1b26ba 100644 --- a/scripts/install +++ b/scripts/install @@ -9,72 +9,29 @@ 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 -admin=$YNH_APP_ARG_ADMIN -phpversion=$YNH_PHP_VERSION - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS -#================================================= -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" - -# Register (book) web path -ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url +member=0 +fpm_footprint="medium" +fpm_usage="medium" #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_script_progression --message="Storing installation settings..." --weight=2 -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 +ynh_app_setting_set --app=$app --key=member --value=$member ynh_app_setting_set --app=$app --key=version --value=$(ynh_app_upstream_version "../manifest.json") - -#================================================= -# STANDARD MODIFICATIONS -#================================================= -# INSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Installing dependencies..." --weight=1 - -ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# 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" +ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint +ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage #================================================= # CREATE A MYSQL DATABASE #================================================= ynh_script_progression --message="Creating a MySQL database..." --weight=1 -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 - ynh_mysql_execute_as_root --sql="ALTER DATABASE $db_name charset=utf8" #================================================= @@ -94,36 +51,20 @@ SOURCE_FORMAT=tar.bz2 SOURCE_IN_SUBDIR=true EOF -ynh_app_setting_set --app=$app --key=final_path --value=$final_path - # Download, check integrity, uncompress and patch the source from app.src ynh_script_progression --message="Download source files..." --weight=70 -ynh_setup_source --dest_dir="$final_path" +ynh_setup_source --dest_dir="$install_dir" # Create necessary files -datadir=$final_path/documents -touch $final_path/htdocs/conf/conf.php +touch $install_dir/htdocs/conf/conf.php #================================================= # PHP-FPM CONFIGURATION #================================================= ynh_script_progression --message="Configuring PHP-FPM" --weight=2 -fpm_footprint="medium" -fpm_usage="medium" - -ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint -ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage - # Create a dedicated php-fpm config -ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint -# Used by ynh_add_nginx_config -phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Configuring NGINX web server..." --weight=1 +ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint # Create a dedicated nginx config ynh_add_nginx_config @@ -135,22 +76,14 @@ ynh_add_nginx_config #================================================= ynh_script_progression --message="Adding a configuration file..." --weight=1 -ynh_add_config --template="../conf/install.forced.php" --destination="$final_path/htdocs/install/install.forced.php" +ynh_add_config --template="install.forced.php" --destination="$install_dir/htdocs/install/install.forced.php" #================================================= # SETUP APPLICATION WITH CURL #================================================= # Set right permissions for curl install -chown -R $app: "$final_path" - -# Set the app as temporarily public for cURL call -if ! ynh_permission_has_user --permission "main" --user="visitors"; then - ynh_permission_update --permission="main" --add="visitors" -fi - -# Reload NGINX -ynh_systemd_action --service_name=nginx --action=reload +chown -R $app: "$install_dir" # Installation with curl @@ -170,8 +103,8 @@ ynh_local_curl "/install/step1.php" \ "action=set" > /var/log/$app/install1.html ynh_exec_fully_quiet sleep 5 - -ynh_script_progression --message="installation - step 2 (may take a while)..." --weight=72 + +ynh_script_progression --message="installation - step 2 (may take a while)..." --weight=20 ynh_local_curl "/install/step2.php" \ "testpost=ok" \ "action=set" > /var/log/$app/install2.html @@ -197,22 +130,19 @@ ynh_local_curl "/install/step5.php" \ ynh_exec_fully_quiet sleep 5 -ynh_script_progression --message="configuring LDAP" --weight=1 +# ynh_script_progression --message="configuring LDAP" --weight=1 -# Populate the LDAP parameters -ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < ../conf/sql/ldap.sql +# # Populate the LDAP parameters +# ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < ../conf/sql/ldap.sql -# Populate the database with YNH users. -ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < ../conf/sql/ldap_user.sql +# # Populate the database with YNH users. +# ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < ../conf/sql/ldap_user.sql -if php$phpversion $final_path/scripts/user/sync_users_ldap2dolibarr.php commitiferror --server=localhost -y; then - ynh_print_info --message="LDAP user update ok" -else - ynh_print_info --message="LDAP user update ended with error" -fi - -# Remove the public access -ynh_permission_update --permission="main" --remove="visitors" +# if php$phpversion $install_dir/scripts/user/sync_users_ldap2dolibarr.php commitiferror --server=localhost -y; then +# ynh_print_info --message="LDAP user update ok" +# else +# ynh_print_info --message="LDAP user update ended with error" +# fi #================================================= # MODIFY A CONFIG FILE @@ -220,14 +150,14 @@ ynh_permission_update --permission="main" --remove="visitors" ynh_script_progression --message="configuring config file" --weight=1 # Setup HTTP auth in conf -ynh_replace_string --match_string="dolibarr_main_authentication='dolibarr'" --replace_string="dolibarr_main_authentication='http'" --target_file="$final_path/htdocs/conf/conf.php" +ynh_replace_string --match_string="dolibarr_main_authentication='dolibarr'" --replace_string="dolibarr_main_authentication='http'" --target_file="$install_dir/htdocs/conf/conf.php" #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= # Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="$final_path/htdocs/conf/conf.php" +ynh_store_file_checksum --file="$install_dir/htdocs/conf/conf.php" #================================================= # GENERIC FINALIZATION @@ -237,20 +167,16 @@ ynh_store_file_checksum --file="$final_path/htdocs/conf/conf.php" ynh_script_progression --message="Configuring permissions..." --weight=1 # Set permissions on app files -if [ ! -f "$datadir/install.lock" ]; then - echo 'This is a lock file to prevent use of install pages (set with permission 440)' > "$datadir/install.lock" - chown $app:$app "$datadir/install.lock" - chmod 440 "$datadir/install.lock" -fi +# if [ ! -f "$data_dir/install.lock" ]; then +# echo 'This is a lock file to prevent use of install pages (set with permission 440)' > "$data_dir/install.lock" +# chown $app:$app "$data_dir/install.lock" +# chmod 440 "$data_dir/install.lock" +# fi -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" - -chmod 644 "$final_path/htdocs/conf/conf.php" -mkdir -p "$datadir" -chown -R $app: "$datadir" -chmod go-w $datadir +chmod 750 "$install_dir" +chmod 644 "$install_dir/htdocs/conf/conf.php" +chmod -R o-rwx "$install_dir" +chown -R $app:www-data "$install_dir" #================================================= # SETUP LOGROTATE @@ -258,24 +184,7 @@ chmod go-w $datadir ynh_script_progression --message="Configuring log rotation..." --weight=1 # Use logrotate to manage application logfile(s) -ynh_use_logrotate --logfile="$final_path/documents/dolibarr.log" - -#================================================= -# SETUP SSOWAT -#================================================= -ynh_script_progression --message="Configuring permissions..." --weight=1 - -# Create the public space permission if needed -if ! ynh_permission_exists --permission "public_space"; then - ynh_permission_create --permission "public_space" --url "/public/" --allowed "visitors" -fi - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -ynh_systemd_action --service_name=nginx --action=reload +ynh_use_logrotate --logfile="$install_dir/documents/dolibarr.log" #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 07f811b..7c463be 100644 --- a/scripts/remove +++ b/scripts/remove @@ -9,44 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -port=$(ynh_app_setting_get --app=$app --key=port) -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 DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." --weight=1 - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - -#================================================= -# REMOVE THE MYSQL DATABASE -#================================================= -ynh_script_progression --message="Removing the MySQL database..." --weight=9 - -# 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..." --weight=1 - -# Remove the app directory securely -ynh_secure_remove --file="$final_path" - #================================================= # REMOVE NGINX CONFIGURATION #================================================= @@ -55,50 +17,18 @@ ynh_script_progression --message="Removing NGINX web server configuration..." -- # Remove the dedicated nginx config ynh_remove_nginx_config -#================================================= -# REMOVE PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Removing PHP-FPM configuration..." --weight=1 - # Remove the dedicated php-fpm config ynh_remove_fpm_config -# Delete old static pool.d conf -old_php_version=7.0 -if [ -f /etc/php/$old_php_version/fpm/pool.d/$app.conf ]; then - ynh_secure_remove --file=/etc/php/$old_php_version/fpm/pool.d/$app.conf -fi - -#================================================= -# REMOVE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Removing logrotate configuration..." --weight=1 - # Remove the app-specific logrotate config ynh_remove_logrotate -#================================================= -# SPECIFIC REMOVE -#================================================= -# REMOVE APP FOLDERS -#================================================= - # Remove a directory securely ynh_secure_remove --file="/etc/$app" # Remove the log files ynh_secure_remove --file="/var/log/$app" -#================================================= -# GENERIC FINALIZATION -#================================================= -# REMOVE DEDICATED USER -#================================================= -ynh_script_progression --message="Removing the dedicated system user..." --weight=1 - -# Delete a system user -ynh_system_user_delete --username=$app - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index 115f3d0..f5feb25 100755 --- a/scripts/restore +++ b/scripts/restore @@ -10,65 +10,19 @@ 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 settings..." --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) -db_user=$db_name -datadir=$final_path/documents/ - -fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) -fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage) -phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) - -#================================================= -# CHECK IF THE APP CAN BE RESTORED -#================================================= -ynh_script_progression --message="Validating restoration parameters..." --weight=1 - -test ! -d $final_path \ - || ynh_die --message="There is already a directory: $final_path " - -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --weight=3 - -# Create the dedicated user (if not existing) -ynh_system_user_create --username=$app - #================================================= # RESTORE THE APP MAIN DIR #================================================= ynh_script_progression --message="Restoring the app main directory..." --weight=1 -ynh_restore_file --origin_path="$final_path" +ynh_restore_file --origin_path="$install_dir" #================================================= -# SPECIFIC RESTORATION +# RESTORE THE MYSQL DATABASE #================================================= -# REINSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=1 +ynh_script_progression --message="Restoring the MySQL database..." --weight=27 -# Define and install dependencies -ynh_install_app_dependencies $pkg_dependencies +ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql #================================================= # RESTORE THE PHP-FPM CONFIGURATION @@ -79,28 +33,10 @@ ynh_print_info --message="Reconfiguring PHP-FPM..." ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" # Recreate a dedicated php-fpm config -ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint - -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= +ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# RESTORE THE MYSQL DATABASE -#================================================= -ynh_script_progression --message="Restoring the MySQL database..." --weight=27 - -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..." --weight=1 - ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= @@ -109,14 +45,14 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app" ynh_script_progression --message="Configuring permissions..." --weight=1 # Set permissions on app files -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" -chmod 644 "$final_path/htdocs/conf/conf.php" -mkdir -p "$datadir" -chown -R $app: "$datadir" -chmod go-w $datadir +chmod 644 "$install_dir/htdocs/conf/conf.php" +mkdir -p "$data_dir" +chown -R $app: "$data_dir" +chmod go-w $data_dir #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index 666bacb..041369a 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,23 +12,9 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=2 -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) -language=$(ynh_app_setting_get --app=$app --key=language) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -current_version=$(ynh_app_setting_get --app=$app --key=version) update_version=$(ynh_app_upstream_version "../manifest.json") -datadir=$final_path/documents/ - -fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) -fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage) -phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) +current_version=$(ynh_app_setting_get --app=$app --key=version) #================================================= # CHECK VERSION @@ -36,20 +22,6 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) 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=11 - -# 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 #================================================= @@ -57,100 +29,28 @@ ynh_abort_if_errors #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 -# 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 fpm_footprint doesn't exist, create it -if [ -z "$fpm_footprint" ]; then - fpm_footprint=medium - ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint +if [ -z "${fpm_footprint:-}" ]; then + fpm_footprint=low + ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint fi # If fpm_usage doesn't exist, create it -if [ -z "$fpm_usage" ]; then - fpm_usage=medium - ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage +if [ -z "${fpm_usage:-}" ]; then + fpm_usage=low + ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage fi -# 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 a permission if needed -if ! ynh_permission_exists --permission "public_space"; then - ynh_permission_create --permission "public_space" --url "/public/" --allowed "visitors" -fi - -# Delete existing ini configuration file (backward compatibility) -if [ -f /etc/php/$YNH_PHP_VERSION/fpm/conf.d/20-$app.ini ]; then - ynh_secure_remove --file=/etc/php/$YNH_PHP_VERSION/fpm/conf.d/20-$app.ini -fi - -#================================================= -# CREATE DEDICATED USER -#================================================= -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 --home_dir="$final_path" - -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=1 - -ynh_install_app_dependencies $pkg_dependencies - #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 -ynh_backup_if_checksum_is_different --file="/etc/nginx/conf.d/$domain.d/$app.conf" - -# Delete current NGINX configuration to be able to check if .well-known is already served. -ynh_remove_nginx_config -ynh_app_setting_delete --app=$app --key="checksum__etc_nginx_conf.d_$domain.d_$app.conf" - -# Wait untils NGINX has fully reloaded -ynh_systemd_action --service_name=nginx --action=reload --line_match="Reloaded" --log_path="systemd" - # Create a dedicated nginx config ynh_add_nginx_config -#================================================= -# PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=2 - -# If php has changed, remove the old fpm config file -# if [ "$phpversion" != $YNH_PHP_VERSION ] -# then - # ynh_backup_if_checksum_is_different --file="/etc/php/$phpversion/fpm/pool.d/$app.conf" - # ynh_secure_remove --file="/etc/php/$phpversion/fpm/pool.d/$app.conf" - # if [ -f /etc/php/$phpversion/fpm/conf.d/20-$app.ini ]; then - # ynh_secure_remove --file="/etc/php/$phpversion/fpm/conf.d/20-$app.ini" - # fi - # ynh_systemd_action --service_name="php${phpversion}-fpm" --action=reload - - # phpversion="$YNH_PHP_VERSION" -# fi - # Recreate a dedicated PHP-FPM config ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint -phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # SPECIFIC UPGRADE @@ -203,11 +103,14 @@ SOURCE_FORMAT=tar.bz2 SOURCE_IN_SUBDIR=true EOF + + # Download, check integrity, uncompress and patch the source from app.src + ynh_setup_source --dest_dir="$install_dir" - chown -R $app: "$final_path" + chown -R $app: "$install_dir" # Remove the lock if it exists - lock=$final_path/documents/install.lock + lock=$install_dir/documents/install.lock if [ -f $lock ] then ynh_secure_remove $lock @@ -217,12 +120,6 @@ EOF # Upgrade with CURL - # Set the app as temporarily public for cURL call - if ! ynh_permission_has_user --permission "main" --user="visitors"; then - ynh_permission_update --permission="main" --add="visitors" - fi - - charset=$(mysql -ss -N -e "SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = '$db_name'") if [ "$charset" != "utf8" ] then @@ -235,9 +132,10 @@ EOF fi ynh_exec_fully_quiet sleep 5 + # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path" + ynh_setup_source --dest_dir="$install_dir" pushd $final_path/htdocs/install/ @@ -247,26 +145,23 @@ EOF ynh_die --message="Step 1 upgrading ended with error" fi - ynh_exec_fully_quiet sleep 5 + ynh_exec_fully_quiet sleep 5 - if php$phpversion upgrade2.php $current_version $next_version > /var/log/$app/upgrade2.html; then - ynh_print_info --message="Step 2 upgrading ended successfully" - else - ynh_die --message="Step 2 upgrading ended with error" - fi + if php$phpversion upgrade2.php $current_version $next_version > /var/log/$app/upgrade2.html; then + ynh_print_info --message="Step 2 upgrading ended successfully" + else + ynh_die --message="Step 2 upgrading ended with error" + fi - ynh_exec_fully_quiet sleep 5 - - if php$phpversion step5.php $current_version $next_version > /var/log/$app/upgrade3.html; then - ynh_print_info --message="Step 3 upgrading ended successfully" - else - ynh_die --message="Step 3 upgrading ended with error" - fi - + ynh_exec_fully_quiet sleep 5 + if php$phpversion step5.php $current_version $next_version > /var/log/$app/upgrade3.html; then + ynh_print_info --message="Step 3 upgrading ended successfully" + else + ynh_die --message="Step 3 upgrading ended with error" + fi popd - ynh_permission_update --permission="main" --remove="visitors" # Get the new current version number current_version=$next_version @@ -274,7 +169,7 @@ EOF done - if php$phpversion $final_path/scripts/user/sync_users_ldap2dolibarr.php commitiferror --server=localhost -y; then + if php$phpversion $install_dir/scripts/user/sync_users_ldap2dolibarr.php commitiferror --server=localhost -y; then ynh_print_info --message="LDAP user update ok" else ynh_print_info --message="LDAP user update ended with error" @@ -287,10 +182,10 @@ fi # STORE THE CONFIG FILE CHECKSUM #================================================= -ynh_backup_if_checksum_is_different --file="$final_path/htdocs/conf/conf.php" +ynh_backup_if_checksum_is_different --file="$install_dir/htdocs/conf/conf.php" # Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file="$final_path/htdocs/conf/conf.php" -chmod 644 "$final_path/htdocs/conf/conf.php" +ynh_store_file_checksum --file="$install_dir/htdocs/conf/conf.php" +chmod 644 "$install_dir/htdocs/conf/conf.php" #================================================= # SETUP LOGROTATE @@ -308,26 +203,19 @@ ynh_use_logrotate --non-append ynh_script_progression --message="Configuring permissions..." --weight=1 # Set permissions on app files -if [ ! -f "$datadir/install.lock" ]; then - echo 'This is a lock file to prevent use of install pages (set with permission 440)' > "$datadir/install.lock" - chown $app:$app "$datadir/install.lock" - chmod 440 "$datadir/install.lock" +if [ ! -f "$data_dir/install.lock" ]; then + echo 'This is a lock file to prevent use of install pages (set with permission 440)' > "$data_dir/install.lock" + chown $app:$app "$data_dir/install.lock" + chmod 440 "$data_dir/install.lock" 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" -mkdir -p "$datadir" -chown -R $app: "$datadir" -chmod go-w $datadir - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -ynh_systemd_action --service_name=nginx --action=reload +mkdir -p "$data_dir" +chown -R $app: "$data_dir" +chmod go-w $data_dir #================================================= # END OF SCRIPT diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..cbbeef1 --- /dev/null +++ b/tests.toml @@ -0,0 +1,3 @@ +test_format = 1.0 + +[default]