From fad51b9051c24798a0da0f1ded5640cd4ae29c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Thu, 17 Dec 2020 15:28:55 +0100 Subject: [PATCH 1/2] Testing (#24) * Add extra_php-fpm.conf * Increase memory_limit to 256M * Add Morpheus icons --- check_process | 2 +- conf/config.ini.php | 5 +- conf/cron | 2 +- conf/extra_php-fpm.conf | 5 ++ conf/icons.src | 6 ++ conf/nginx.conf | 4 +- issue_template.md | 2 +- manifest.json | 6 +- scripts/_common.sh | 16 ++++++ scripts/change_url | 119 ++++++++++++++++++++++++++++++++++++++++ scripts/install | 52 ++++++------------ scripts/upgrade | 60 +++++++++++++++++--- 12 files changed, 228 insertions(+), 51 deletions(-) create mode 100644 conf/extra_php-fpm.conf create mode 100644 conf/icons.src create mode 100644 scripts/change_url diff --git a/check_process b/check_process index 487c4da..4292fa2 100644 --- a/check_process +++ b/check_process @@ -20,7 +20,7 @@ backup_restore=1 multi_instance=1 port_already_use=0 - change_url=0 + change_url=1 ;;; Options Email=anmol@datamol.org Notification=yes diff --git a/conf/config.ini.php b/conf/config.ini.php index beda577..0d3b9c6 100644 --- a/conf/config.ini.php +++ b/conf/config.ini.php @@ -2,7 +2,8 @@ ; file automatically generated or modified by Matomo; you can manually override the default values in global.ini.php by redefining them in this file. [database] host = "127.0.0.1" -username = "__DB__" +username = "__DB_NAME__" password = "__DB_PASSWORD__" -dbname = "__DB__" +dbname = "__DB_NAME__" tables_prefix = "matomo_" + diff --git a/conf/cron b/conf/cron index 8e8ce50..02900b9 100644 --- a/conf/cron +++ b/conf/cron @@ -1,2 +1,2 @@ MAILTO="admin" -5 * * * * __USER__ /usr/bin/php YNH_WWW_PATH/console core:archive --url=https://__DOMAIN__/__PATH__ > /dev/null +5 * * * * __APP__ /usr/bin/php__PHPVERSION__ __FINALPATH__/console core:archive --url=https://__DOMAIN____PATH__ > /dev/null diff --git a/conf/extra_php-fpm.conf b/conf/extra_php-fpm.conf new file mode 100644 index 0000000..a5425fc --- /dev/null +++ b/conf/extra_php-fpm.conf @@ -0,0 +1,5 @@ +; Additional php.ini defines, specific to this pool of workers. + +php_admin_value[upload_max_filesize] = 100M +php_admin_value[memory_limit] = 256M +php_admin_value[post_max_size] = 50M diff --git a/conf/icons.src b/conf/icons.src new file mode 100644 index 0000000..6ffad8e --- /dev/null +++ b/conf/icons.src @@ -0,0 +1,6 @@ +SOURCE_URL=https://github.com/matomo-org/matomo-icons/archive/e96ef33bf490794829831cbb795fd4ea67259699.tar.gz +SOURCE_SUM=9a6457d8f138216f911621db7a5af5fbce7214e62d6f184730f216986e498b53 +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=tar.gz +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= diff --git a/conf/nginx.conf b/conf/nginx.conf index 556b622..b41ead3 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -11,8 +11,8 @@ location __PATH__/ { index index.php; - # Common parameter to increase upload size limit in conjunction with dedicated php-fpm file - #client_max_body_size 50M; + # Common parameter to increase upload size limit in conjunction with dedicated PHP-FPM file + client_max_body_size 100M; try_files $uri $uri/ index.php; location ~ [^/]\.php(/|$) { diff --git a/issue_template.md b/issue_template.md index 0f954a7..1cad34d 100644 --- a/issue_template.md +++ b/issue_template.md @@ -20,7 +20,7 @@ about: Create a report to help us debug, it would be nice to fill the template a - Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...* - YunoHost version: x.x.x - I have access to my server: *Through SSH | through the webadmin | direct access via keyboard / screen | ...* -- Are you in a special context or did you perform some particular tweaking on your YunoHost instance ?: *no / yes* +- Are you in a special context or did you perform some particular tweaking on your YunoHost instance?: *no / yes* - If yes, please explain: - Using, or trying to install package version/branch: - If upgrading, current package version: *can be found in the admin, or with `yunohost app info $app_id`* diff --git a/manifest.json b/manifest.json index 35712cc..7f5a27d 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Open source analytics platform for measuring Web statistics", "fr": "Plateforme d'analyse open source de mesure de statistiques Web" }, - "version": "4.0.5~ynh1", + "version": "4.0.5~ynh2", "url": "https://matomo.org", "license": "GPL-3.0-or-later", "maintainer": { @@ -50,6 +50,10 @@ "en": "Is it a public application?", "fr": "Est-ce une application publique ?" }, + "help": { + "en": "If enabled, Matomo will be accessible by people who do not have an account. This can be changed later via the webadmin.", + "fr": "Si cette case est cochée, Matomo sera accessible aux personnes n’ayant pas de compte. Vous pourrez changer ceci plus tard via la webadmin." + }, "default": true } ] diff --git a/scripts/_common.sh b/scripts/_common.sh index e932edf..c685199 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -76,3 +76,19 @@ $(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')" # Send the email to the recipients echo "$mail_message" | $mail_bin -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients" } + + + +# Execute a command as another user +# usage: ynh_exec_as USER COMMAND [ARG ...] +ynh_exec_as() { + local USER=$1 + shift 1 + + if [[ $USER = $(whoami) ]]; then + eval "$@" + else + sudo -u "$USER" "$@" + fi +} + diff --git a/scripts/change_url b/scripts/change_url new file mode 100644 index 0000000..253d54f --- /dev/null +++ b/scripts/change_url @@ -0,0 +1,119 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +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) +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) + +#================================================= +# 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 + +#================================================= +# MODIFY URL IN NGINX CONF +#================================================= +ynh_script_progression --message="Updating NGINX web server configuration..." --weight=3 + +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 + +#================================================= +# SETUP A CRON +#================================================= +ynh_script_progression --message="Setuping a cron..." + +cp ../conf/cron /etc/cron.d/$app + +ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="/etc/cron.d/$app" +ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/etc/cron.d/$app" +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$new_domain" --target_file="/etc/cron.d/$app" +ynh_replace_string --match_string="__PATH__" --replace_string="$new_path" --target_file="/etc/cron.d/$app" +ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$phpversion" --target_file="/etc/cron.d/$app" + +#================================================= +# RELOAD NGINX +#================================================= +ynh_script_progression --message="Reloading NGINX web server..." --weight=1 + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Change of URL completed for $app" --last diff --git a/scripts/install b/scripts/install index 6f18a0c..9e41513 100755 --- a/scripts/install +++ b/scripts/install @@ -96,43 +96,26 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # INSTALL COMPOSER AND DEPENDENCIES #================================================= -ynh_script_progression --message="Installing composer and dependencies..." +ynh_script_progression --message="Installing Composer and dependencies..." ynh_install_composer --phpversion="$phpversion" --workdir="$final_path" +# Install missing icons +ynh_setup_source --dest_dir="$final_path/plugins/Morpheus/icons" --source_id="icons" +chmod -R 755 "$final_path/plugins/Morpheus" + #================================================= # SETUP A CRON #================================================= ynh_script_progression --message="Setuping a cron..." -ynh_replace_string --match_string="YNH_WWW_PATH" --replace_string="$final_path" --target_file="../conf/cron" -ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/cron" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/cron" -ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="../conf/cron" -cp -f ../conf/cron /etc/cron.d/$app +cp ../conf/cron /etc/cron.d/$app -#================================================= -# MODIFY A CONFIG FILE (TO DO: Automate install) -#================================================= -ynh_script_progression --message="Modifying a config file..." - -### `ynh_replace_string` is used to replace a string in a file. -### (It's compatible with sed regular expressions syntax) -## cp -f ../conf/config.ini.php "$final_path/config/config.ini.php" -## ynh_replace_string "__DB__" "$db_name" "$final_path/config/config.ini.php" -## ynh_replace_string "__DB_PASSWORD__" "$db_pwd" "$final_path/config/config.ini.php" - -#================================================= -# STORE THE CONFIG FILE CHECKSUM -#================================================= -ynh_script_progression --message="Storing the config file checksum..." - -### `ynh_store_file_checksum` is used to store the checksum of a file. -### That way, during the upgrade script, by using `ynh_backup_if_checksum_is_different`, -### you can make a backup of this file before modifying it again if the admin had modified it. - -# Calculate and store the config file checksum into the app settings -## ynh_store_file_checksum --file="$final_path/CONFIG_FILE" +ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="/etc/cron.d/$app" +ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/etc/cron.d/$app" +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="/etc/cron.d/$app" +ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="/etc/cron.d/$app" +ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$phpversion" --target_file="/etc/cron.d/$app" #================================================= # GENERIC FINALIZATION @@ -152,8 +135,6 @@ ynh_script_progression --message="Configuring SSOwat..." # Make app public if necessary or protect it 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 @@ -169,12 +150,15 @@ ynh_systemd_action --service_name=nginx --action=reload #================================================= ynh_script_progression --message="Sending a readme for the admin..." -message=" $app was successfully installed :) +message="Matomo was successfully installed :) + Please open your $app domain: https://$domain$path_url + Complete the registration process from the setup page displayed. -Details for mysql database to be enterted while registration process: -Database login: $app -Database name: $app +Details for MySQL database to be enterted while registration process: + +Database login: $app +Database name: $app Database password: $db_pwd If you are facing any problem or want to improve this app, please open a new issue here: https://github.com/YunoHost-Apps/matomo_ynh/issues" diff --git a/scripts/upgrade b/scripts/upgrade index 6f892f9..bddff85 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -22,6 +22,7 @@ path_url=$(ynh_app_setting_get --app=$app --key=path) is_public=$(ynh_app_setting_get --app=$app --key=is_public) final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # CHECK VERSION @@ -80,8 +81,32 @@ if [ "$upgrade_type" == "UPGRADE_APP" ] then 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" + if [[ ! -f "$final_path/config/config.ini.php" ]]; then + # config.ini.php is only created during the post-install process... + # it is therefore not present when the CI tests are carried out... + # This condition is only for CI test to go through the upgrade process + ynh_secure_remove --file="$final_path" + # Download, check integrity, uncompress and patch the source from app.src + ynh_setup_source --dest_dir="$final_path" + else + # Create a temporary directory + tmpdir="$(mktemp -d)" + + # Backup the config file in the temp dir + cp -a "$final_path/config/config.ini.php" "$tmpdir/config.ini.php" + + # Remove the app directory securely + ynh_secure_remove --file="$final_path" + + # Download, check integrity, uncompress and patch the source from app.src + ynh_setup_source --dest_dir="$final_path" + + # Copy the admin saved settings from tmp directory to final path + cp -a "$tmpdir/config.ini.php" "$final_path/config/config.ini.php" + + # Remove the tmp directory securely + ynh_secure_remove --file="$tmpdir" + fi fi #================================================= @@ -105,9 +130,8 @@ ynh_system_user_create --username=$app #================================================= ynh_script_progression --message="Upgrading PHP-FPM configuration..." -# Create a dedicated php-fpm config +# Create a dedicated PHP-FPM config ynh_add_fpm_config --usage=low --footprint=low --package="$extra_php_dependencies" -phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # SPECIFIC UPGRADE @@ -118,16 +142,34 @@ ynh_script_progression --message="Installating composer and dependencies..." ynh_install_composer --phpversion="$phpversion" --workdir="$final_path" +if [[ -f "$final_path/config/config.ini.php" ]]; then + pushd "$final_path" + ynh_exec_as $app ./console core:update + popd +fi + +#================================================= +# INSTALL MISSING ICONS +#================================================= + +if [ ! "$(ls -A "$final_path/plugins/Morpheus/icons")" ] +then + ynh_setup_source --dest_dir="$final_path/plugins/Morpheus/icons" --source_id="icons" + chmod -R 755 "$final_path/plugins/Morpheus" +fi + #================================================= # SETUP A CRON #================================================= ynh_script_progression --message="Setuping a cron..." -ynh_replace_string --match_string="YNH_WWW_PATH" --replace_string="$final_path" --target_file="../conf/cron" -ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/cron" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/cron" -ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="../conf/cron" -cp -f ../conf/cron /etc/cron.d/$app +cp ../conf/cron /etc/cron.d/$app + +ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="/etc/cron.d/$app" +ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/etc/cron.d/$app" +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="/etc/cron.d/$app" +ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="/etc/cron.d/$app" +ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$phpversion" --target_file="/etc/cron.d/$app" #================================================= # GENERIC FINALIZATION From c1d716aea9ebff85a84fefa35be26810c1b7b130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Wed, 6 Jan 2021 09:28:00 +0100 Subject: [PATCH 2/2] Upgrade to 4.1.0 (#27) * Upgrade to 4.1.0 --- README.md | 2 +- README_fr.md | 4 ++-- conf/app.src | 4 ++-- manifest.json | 2 +- scripts/install | 2 +- scripts/restore | 2 +- scripts/upgrade | 7 +++---- 7 files changed, 11 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 5343f38..1d31a0a 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in ## Overview Matomo is the leading Free/Libre open analytics platform. It is a full-featured PHP MySQL software program that you download and install on your own webserver. At the end of the five-minute installation process, you will be given a JavaScript code. Simply copy and paste this tag on websites you wish to track and access your analytics reports in real-time. -**Shipped version:** 4.0.5 +**Shipped version:** 4.1.0 ## Screenshots diff --git a/README_fr.md b/README_fr.md index c8c5f56..85793c6 100644 --- a/README_fr.md +++ b/README_fr.md @@ -1,7 +1,7 @@ # Matomo pour YunoHost [![Niveau d'intégration](https://dash.yunohost.org/integration/matomo.svg)](https://dash.yunohost.org/appci/app/matomo) ![](https://ci-apps.yunohost.org/ci/badges/matomo.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/matomo.maintain.svg) -[![Installer Matomo avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=matomo) +[![Installer Matomo avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=matomo) *[Read this readme in english.](./README.md)* @@ -11,7 +11,7 @@ Si vous n'avez pas YunoHost, consultez [le guide](https://yunohost.org/#/install ## Vue d'ensemble Matomo est une plateforme d'analyse open source de mesure de statistiques Web. Il s'agit d'un logiciel PHP MySQL complet que vous téléchargez et installez sur votre propre serveur Web. À la fin du processus d'installation de cinq minutes, vous recevrez un code JavaScript. Copiez et collez simplement cette balise sur les sites Web que vous souhaitez suivre et accédez à vos rapports d'analyse en temps réel. -**Version incluse :** 4.0.5 +**Version incluse :** 4.1.0 ## Captures d'écran diff --git a/conf/app.src b/conf/app.src index 2f64345..31bd2bb 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://github.com/matomo-org/matomo/archive/4.0.5.tar.gz -SOURCE_SUM=b201dbcf0ce87433a6509cb83c7e565fed2da9a88f192ab222367e74ee28d55a +SOURCE_URL=https://github.com/matomo-org/matomo/archive/4.1.0.tar.gz +SOURCE_SUM=13b74fffbe794b8de3da46e91485a5a5c71c8f0267d0db80e88889db8a44aa03 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true diff --git a/manifest.json b/manifest.json index 7f5a27d..8185c36 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Open source analytics platform for measuring Web statistics", "fr": "Plateforme d'analyse open source de mesure de statistiques Web" }, - "version": "4.0.5~ynh2", + "version": "4.1.0~ynh1", "url": "https://matomo.org", "license": "GPL-3.0-or-later", "maintainer": { diff --git a/scripts/install b/scripts/install index 9e41513..192b249 100755 --- a/scripts/install +++ b/scripts/install @@ -125,7 +125,7 @@ ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$phpversion ynh_script_progression --message="Securing files and directories..." # Set permissions to app files -chown -R $app: $final_path +chown -R $app:$app $final_path #================================================= # SETUP SSOWAT diff --git a/scripts/restore b/scripts/restore index 4a51b1d..5b97f86 100755 --- a/scripts/restore +++ b/scripts/restore @@ -71,7 +71,7 @@ ynh_system_user_create --username=$app ynh_script_progression --message="Restoring user rights..." # Restore permissions on app files -chown -R $app: $final_path +chown -R $app:$app $final_path #================================================= # RESTORE THE PHP-FPM CONFIGURATION diff --git a/scripts/upgrade b/scripts/upgrade index bddff85..3c9f6bd 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -143,9 +143,7 @@ ynh_script_progression --message="Installating composer and dependencies..." ynh_install_composer --phpversion="$phpversion" --workdir="$final_path" if [[ -f "$final_path/config/config.ini.php" ]]; then - pushd "$final_path" - ynh_exec_as $app ./console core:update - popd + php$phpversion $final_path/console core:update fi #================================================= @@ -154,6 +152,7 @@ fi if [ ! "$(ls -A "$final_path/plugins/Morpheus/icons")" ] then + ynh_script_progression --message="Installating Morpheus icons..." ynh_setup_source --dest_dir="$final_path/plugins/Morpheus/icons" --source_id="icons" chmod -R 755 "$final_path/plugins/Morpheus" fi @@ -179,7 +178,7 @@ ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$phpversion ynh_script_progression --message="Securing files and directories..." # Set permissions on app files -chown -R $app: $final_path +chown -R $app:$app $final_path #================================================= # RELOAD NGINX