diff --git a/conf/nginx.conf b/conf/nginx.conf index 06a9322..35f8581 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/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..ec2af61 --- /dev/null +++ b/manifest.toml @@ -0,0 +1,72 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json + +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~ynh2" + +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" +cpe = "cpe:2.3:a:dolibarr:dolibarr" + +[integration] +yunohost = ">= 11.2" +architectures = "all" +multi_instance = true +ldap = true +sso = true +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 = "/dolibarr" + + [install.admin] + type = "user" + +[resources] + [resources.system_user] + + [resources.install_dir] + + [resources.data_dir] + + [resources.permissions] + main.url = "/" + + [resources.apt] + packages = [ + "php8.1-mysql", + "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..0aa665b 100755 --- a/scripts/backup +++ b/scripts/backup @@ -15,19 +15,19 @@ source /usr/share/yunohost/helpers #================================================= # Exit if an error occurs during the execution of the script -ynh_abort_if_errors +#REMOVEME? ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_print_info --message="Loading installation settings..." +#REMOVEME? ynh_print_info --message="Loading installation settings..." -app=$YNH_APP_INSTANCE_NAME +#REMOVEME? 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) +#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) +#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) +#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#REMOVEME? phpversion=$(ynh_app_setting_get --app="$app" --key=phpversion) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -38,7 +38,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..8cecbab 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -13,53 +13,53 @@ source /usr/share/yunohost/helpers # RETRIEVE ARGUMENTS #================================================= -old_domain=$YNH_APP_OLD_DOMAIN -old_path=$YNH_APP_OLD_PATH +#REMOVEME? old_domain=$YNH_APP_OLD_DOMAIN +#REMOVEME? old_path=$YNH_APP_OLD_PATH -new_domain=$YNH_APP_NEW_DOMAIN -new_path=$YNH_APP_NEW_PATH +#REMOVEME? new_domain=$YNH_APP_NEW_DOMAIN +#REMOVEME? new_path=$YNH_APP_NEW_PATH -app=$YNH_APP_INSTANCE_NAME +#REMOVEME? app=$YNH_APP_INSTANCE_NAME #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 +#REMOVEME? 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) +#REMOVEME? # Needed for helper "ynh_add_nginx_config" +#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1 +#REMOVEME? 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 () { +#REMOVEME? ynh_backup_before_upgrade +#REMOVEME? 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" +#REMOVEME? ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" # restore it if the upgrade fails - ynh_restore_upgradebackup +#REMOVEME? ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script -ynh_abort_if_errors +#REMOVEME? ynh_abort_if_errors #================================================= # CHECK WHICH PARTS SHOULD BE CHANGED #================================================= -change_domain=0 -if [ "$old_domain" != "$new_domain" ] +#REMOVEME? change_domain=0 +#REMOVEME? if [ "$old_domain" != "$new_domain" ] then - change_domain=1 + #REMOVEME? change_domain=1 fi -change_path=0 -if [ "$old_path" != "$new_path" ] +#REMOVEME? change_path=0 +#REMOVEME? if [ "$old_path" != "$new_path" ] then - change_path=1 + #REMOVEME? change_path=1 fi #================================================= @@ -69,28 +69,30 @@ fi #================================================= ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 -nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf +ynh_change_url_nginx_config -# Change the path in the nginx config file +#REMOVEME? nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf + +#REMOVEME? # 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 +#REMOVEME? # Make a backup of the original nginx config file if modified +#REMOVEME? ynh_backup_if_checksum_is_different --file="$nginx_conf_path" +#REMOVEME? # Set global variables for nginx helper +#REMOVEME? domain="$old_domain" +#REMOVEME? path="$new_path" +#REMOVEME? # Create a dedicated nginx config +#REMOVEME? ynh_add_nginx_config fi -# Change the domain for nginx +#REMOVEME? # 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 +#REMOVEME? ynh_delete_file_checksum --file="$nginx_conf_path" +#REMOVEME? 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" +#REMOVEME? ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" fi #================================================= @@ -99,16 +101,16 @@ 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" +ynh_replace_string --match_string="$old_domain$old_path" --replace_string="$new_domain$new_path" --target_file="$install_dir/htdocs/conf/conf.php" #================================================= # GENERIC FINALISATION #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 +#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1 -ynh_systemd_action --service_name=nginx --action=reload +#REMOVEME? #REMOVEME? ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index c68ac42..b92df48 100644 --- a/scripts/install +++ b/scripts/install @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,70 +8,15 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# MANAGE SCRIPT FAILURE +# INITIALIZE AND STORE SETTINGS #================================================= -# 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 - -#================================================= -# 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=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=version --value=$(ynh_app_upstream_version) #================================================= # 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_script_progression --message="Creating $app's MySQL database..." --weight=1 ynh_mysql_execute_as_root --sql="ALTER DATABASE $db_name charset=utf8" @@ -82,106 +25,70 @@ ynh_mysql_execute_as_root --sql="ALTER DATABASE $db_name charset=utf8" #================================================= ynh_script_progression --message="Setting up source files..." --weight=1 -# Load the last available version -source upgrade.d/upgrade.last.sh - -# Create an app.src for the last version of Dolibarr -cat > ../conf/app.src << EOF -SOURCE_URL=https://github.com/Dolibarr/dolibarr/archive/$next_version.tar.gz -SOURCE_SUM=$dolibarr_source_sha256 -SOURCE_SUM_PRG=sha256sum -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 --source_id="main" --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 +# PREPARE AND INSTALL APP #================================================= -ynh_script_progression --message="Configuring PHP-FPM" --weight=2 +ynh_script_progression --message="Adding $app's configuration file..." --weight=1 -fpm_footprint="medium" -fpm_usage="medium" +ynh_add_config --template="install.forced.php" --destination="$install_dir/htdocs/install/install.forced.php" -ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint -ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage +#================================================= +# SYSTEM CONFIGURATION +#================================================= +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 # 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 -#================================================= -# SPECIFIC SETUP -#================================================= -# PREPARE AND INSTALL APP -#================================================= -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" +# Use logrotate to manage application logfile(s) +ynh_use_logrotate --logfile="$install_dir/documents/dolibarr.log" #================================================= # 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 -mkdir -p /var/log/$app/ +mkdir -p "/var/log/$app/" ynh_script_progression --message="Finalizing installation..." --weight=1 ynh_script_progression --message="Generate fileconf" --weight=1 ynh_local_curl "/install/fileconf.php" \ - "testpost=ok" + "testpost=ok" ynh_exec_fully_quiet sleep 5 ynh_script_progression --message="installation - step 1" --weight=3 ynh_local_curl "/install/step1.php" \ - "testpost=ok" \ - "action=set" > /var/log/$app/install1.html + "testpost=ok" \ + "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_local_curl "/install/step2.php" \ - "testpost=ok" \ - "action=set" > /var/log/$app/install2.html + "testpost=ok" \ + "action=set" > /var/log/$app/install2.html ynh_exec_fully_quiet sleep 5 ynh_script_progression --message="installation - step 4" --weight=3 ynh_local_curl "/install/step4.php" \ - "testpost=ok" \ - "action=set" > /var/log/$app/install3.html + "testpost=ok" \ + "action=set" > /var/log/$app/install3.html ynh_exec_fully_quiet sleep 5 @@ -190,10 +97,10 @@ password=$(ynh_string_random 8) ynh_script_progression --message="installation - step 5" --weight=4 ynh_local_curl "/install/step5.php" \ - "testpost=ok" \ - "action=set" \ - "pass=$password" \ - "pass_verif=$password" > /var/log/$app/install4.html + "testpost=ok" \ + "action=set" \ + "pass=$password" \ + "pass_verif=$password" > /var/log/$app/install4.html ynh_exec_fully_quiet sleep 5 @@ -205,77 +112,47 @@ ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < .. # 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" +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" + ynh_print_info --message="LDAP user update ended with error" fi -# Remove the public access -ynh_permission_update --permission="main" --remove="visitors" - #================================================= # MODIFY A CONFIG FILE #================================================= 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 #================================================= # SECURE FILES AND DIRECTORIES #================================================= -ynh_script_progression --message="Configuring permissions..." --weight=1 +#REMOVEME? 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" -chmod 644 "$final_path/htdocs/conf/conf.php" -mkdir -p "$datadir" -chown -R $app: "$datadir" -chmod go-w $datadir - -#================================================= -# SETUP LOGROTATE -#================================================= -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 +chmod 644 "$install_dir/htdocs/conf/conf.php" +mkdir -p "$data_dir" +chown -R $app: "$data_dir" +chmod go-w $data_dir #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 07f811b..e245996 100644 --- a/scripts/remove +++ b/scripts/remove @@ -12,40 +12,40 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 +#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1 -app=$YNH_APP_INSTANCE_NAME +#REMOVEME? 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) +#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) +#REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port) +#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#REMOVEME? db_user=$db_name +#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) #================================================= # STANDARD REMOVE # REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing dependencies..." --weight=1 +#REMOVEME? ynh_script_progression --message="Removing dependencies..." --weight=1 # Remove metapackage and its dependencies -ynh_remove_app_dependencies +#REMOVEME? ynh_remove_app_dependencies #================================================= # REMOVE THE MYSQL DATABASE #================================================= -ynh_script_progression --message="Removing the MySQL database..." --weight=9 +#REMOVEME? 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 +#REMOVEME? 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 +#REMOVEME? ynh_script_progression --message="Removing app main directory..." --weight=1 # Remove the app directory securely -ynh_secure_remove --file="$final_path" +#REMOVEME? ynh_secure_remove --file="$install_dir" #================================================= # REMOVE NGINX CONFIGURATION @@ -94,10 +94,10 @@ ynh_secure_remove --file="/var/log/$app" #================================================= # REMOVE DEDICATED USER #================================================= -ynh_script_progression --message="Removing the dedicated system user..." --weight=1 +#REMOVEME? ynh_script_progression --message="Removing the dedicated system user..." --weight=1 # Delete a system user -ynh_system_user_delete --username=$app +#REMOVEME? ynh_system_user_delete --username=$app #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index 115f3d0..d617b86 100755 --- a/scripts/restore +++ b/scripts/restore @@ -15,60 +15,60 @@ source /usr/share/yunohost/helpers #================================================= # Exit if an error occurs during the execution of the script -ynh_abort_if_errors +#REMOVEME? ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= ynh_script_progression --message="Loading settings..." --weight=1 -app=$YNH_APP_INSTANCE_NAME +#REMOVEME? 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/ +#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) +#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path) +#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) +#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#REMOVEME? db_user=$db_name +#REMOVEME? data_dir=$install_dir/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) +#REMOVEME? fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) +#REMOVEME? fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage) +#REMOVEME? 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 +#REMOVEME? ynh_script_progression --message="Validating restoration parameters..." --weight=1 -test ! -d $final_path \ - || ynh_die --message="There is already a directory: $final_path " +#REMOVEME? test ! -d $install_dir \ + || ynh_die --message="There is already a directory: $install_dir " #================================================= # STANDARD RESTORATION STEPS #================================================= # RECREATE THE DEDICATED USER #================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --weight=3 +#REMOVEME? ynh_script_progression --message="Recreating the dedicated system user..." --weight=3 # Create the dedicated user (if not existing) -ynh_system_user_create --username=$app +#REMOVEME? 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 #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=1 +#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." --weight=1 # Define and install dependencies -ynh_install_app_dependencies $pkg_dependencies +#REMOVEME? ynh_install_app_dependencies $pkg_dependencies #================================================= # RESTORE THE PHP-FPM CONFIGURATION @@ -90,10 +90,10 @@ 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 +#REMOVEME? 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 +#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +#REMOVEME? 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 #================================================= @@ -106,17 +106,17 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= # SECURE FILES AND DIRECTORIES #================================================= -ynh_script_progression --message="Configuring permissions..." --weight=1 +#REMOVEME? 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..bf70b0f 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,23 +12,23 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=2 +#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=2 -app=$YNH_APP_INSTANCE_NAME +#REMOVEME? 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) +#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) +#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path) +#REMOVEME? admin=$(ynh_app_setting_get --app=$app --key=admin) +#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) +#REMOVEME? language=$(ynh_app_setting_get --app=$app --key=language) +#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#REMOVEME? current_version=$(ynh_app_setting_get --app=$app --key=version) update_version=$(ynh_app_upstream_version "../manifest.json") -datadir=$final_path/documents/ +#REMOVEME? data_dir=$install_dir/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) +#REMOVEME? fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) +#REMOVEME? fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage) +#REMOVEME? phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # CHECK VERSION @@ -39,16 +39,16 @@ 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 +#REMOVEME? 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 () { +#REMOVEME? ynh_backup_before_upgrade +#REMOVEME? ynh_clean_setup () { # restore it if the upgrade fails - ynh_restore_upgradebackup +#REMOVEME? ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script -ynh_abort_if_errors +#REMOVEME? ynh_abort_if_errors #================================================= # STANDARD UPGRADE STEPS @@ -60,13 +60,13 @@ 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 +#REMOVEME? 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 +# If install_dir doesn't exist, create it +if [ -z "$install_dir" ]; then +#REMOVEME? install_dir=/var/www/$app +#REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir fi # If fpm_footprint doesn't exist, create it @@ -82,15 +82,15 @@ if [ -z "$fpm_usage" ]; then fi # Cleaning legacy permissions -if ynh_legacy_permissions_exists; then - ynh_legacy_permissions_delete_all +#REMOVEME? if ynh_legacy_permissions_exists; then +#REMOVEME? 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" +#REMOVEME? if ! ynh_permission_exists --permission "public_space"; then +#REMOVEME? ynh_permission_create --permission "public_space" --url "/public/" --allowed "visitors" fi # Delete existing ini configuration file (backward compatibility) @@ -101,17 +101,17 @@ fi #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 +#REMOVEME? 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" +#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" #================================================= # UPGRADE DEPENDENCIES #================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=1 +#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=1 -ynh_install_app_dependencies $pkg_dependencies +#REMOVEME? ynh_install_app_dependencies $pkg_dependencies #================================================= # NGINX CONFIGURATION @@ -125,7 +125,7 @@ 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" +#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload --line_match="Reloaded" --log_path="systemd" # Create a dedicated nginx config ynh_add_nginx_config @@ -150,7 +150,7 @@ ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=2 # 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) +#REMOVEME? phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # SPECIFIC UPGRADE @@ -204,10 +204,10 @@ SOURCE_IN_SUBDIR=true EOF - 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 @@ -219,7 +219,7 @@ EOF # 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" +#REMOVEME? ynh_permission_update --permission="main" --add="visitors" fi @@ -237,9 +237,9 @@ EOF 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/ + pushd $install_dir/htdocs/install/ if php$phpversion upgrade.php $current_version $next_version > /var/log/$app/upgrade.html; then ynh_print_info --message="Step 1 upgrading ended successfully" @@ -266,7 +266,7 @@ EOF popd - ynh_permission_update --permission="main" --remove="visitors" +#REMOVEME? ynh_permission_update --permission="main" --remove="visitors" # Get the new current version number current_version=$next_version @@ -274,7 +274,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 +287,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 @@ -305,29 +305,29 @@ ynh_use_logrotate --non-append #================================================= # SECURE FILES AND DIRECTORIES #================================================= -ynh_script_progression --message="Configuring permissions..." --weight=1 +#REMOVEME? 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 +mkdir -p "$data_dir" +chown -R $app: "$data_dir" +chmod go-w $data_dir #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 +#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1 -ynh_systemd_action --service_name=nginx --action=reload +#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..35a337a --- /dev/null +++ b/tests.toml @@ -0,0 +1,11 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json + +test_format = 1.0 + +[default] + + # ------------ + # Tests to run + # ------------ + + test_upgrade_from.7e3914481ac4d6c40f3be3f35f155fac6f4387c6.name = "old version"