From 25bf428e280f463fb85c3f8332b523415c56f816 Mon Sep 17 00:00:00 2001 From: Simon Mellerin Date: Mon, 28 Dec 2020 16:06:54 +0100 Subject: [PATCH 1/8] Update Readme --- README.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3ae1972..30a3dca 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # æneria for YunoHost -**DO NOT USE, WORK IN PROGRESS** - [![Integration level](https://dash.yunohost.org/integration/aeneria.svg)](https://dash.yunohost.org/appci/app/aeneria) ![](https://ci-apps.yunohost.org/ci/badges/aeneria.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/aeneria.maintain.svg) [![Install æneria with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=aeneria) @@ -9,10 +7,10 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.* ## Overview -The idea of [æneria](https://gitlab.com/aeneria/aeneria-app) is to display electricity consumption and weather data on a little dashboard that allow the user to: +The idea of [æneria](https://gitlab.com/aeneria/aeneria-app) is to display energy consumption and weather data on a little dashboard that allow the user to: - * Better understand his electricity consumption - * Analyse his electricity consumption throw weather data + * Better understand our own energy consumption + * Analyse energy consumption throw weather data **Shipped version:** 1.0.3 @@ -22,8 +20,9 @@ The idea of [æneria](https://gitlab.com/aeneria/aeneria-app) is to display elec ## Configuration -* First of all, you'll need a Linky (obviously) and an [Enedis account](https://mon-compte-client.enedis.fr/) -* After you have installed the app, just visit it and follow instructions +* First of all, you'll need a Linky and an [Enedis account](https://mon-compte-client.enedis.fr/) +* In your Enedis space, go to ["Gérer l'accès à mes données"](https://mon-compte-particulier.enedis.fr/donnees/) tab, and allow Enedis to collect and store your hourly consumption +* After that, install æneria to your Yunohost instance, visit it and just follow instructions * That's it, now wait a bit to see data appear ! ## Documentation @@ -36,7 +35,7 @@ More information can be found on [æneria documentation](https://docs.aeneria.co This new version introduced some breaking changes in data structure: migration from Pilea can't be done automaticly. -But don't worry, you can easilly transfer your data from Pilea to æneria, just follow [this documentation](https://docs.aeneria.com/fr/latest/administrateur/pilea_migration.html). +But don't worry, you can easilly transfer your data from Pilea to æneria following [this documentation](https://docs.aeneria.com/fr/latest/administrateur/pilea_migration.html). ## YunoHost specific features From 3ac589ee21768fbd76ae37faaee71d5f569585d9 Mon Sep 17 00:00:00 2001 From: Simon Mellerin Date: Mon, 28 Dec 2020 16:07:52 +0100 Subject: [PATCH 2/8] Bump to aeneria 1.0.4 --- README.md | 2 +- conf/app.src | 4 ++-- manifest.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 30a3dca..43f0962 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ The idea of [æneria](https://gitlab.com/aeneria/aeneria-app) is to display ener * Better understand our own energy consumption * Analyse energy consumption throw weather data - **Shipped version:** 1.0.3 + **Shipped version:** 1.0.4 ## Screenshots diff --git a/conf/app.src b/conf/app.src index b1e136d..3d9e227 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://statics.aeneria.com/aeneria-app-1.0.3.tar.gz -SOURCE_SUM=f61cf16edd8a435f693261243e2d671487f28e8253c17885da77397cd8878887 +SOURCE_URL=https://statics.aeneria.com/aeneria-app-1.0.4.tar.gz +SOURCE_SUM=900e165d2992c1349b2ed1fff8fda7ec999b78c70e6a14043800defdb715a91d SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true diff --git a/manifest.json b/manifest.json index a2a7ef4..6df8e61 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "A little dashboard to analyse your electricity consumption data from Linky & weather", "fr": "Un petit tableau de bord pour analyser votre consomation d'électricité à partir des données d'un Linky et de la météo" }, - "version": "1.0.3~ynh1", + "version": "1.0.4~ynh1", "url": "https://gitlab.com/aeneria/aeneria-app", "license": "AGPL-3.0-or-later", "maintainer": { From 1641bfede4e28b2dea58788fe9fa2bd0b26d1493 Mon Sep 17 00:00:00 2001 From: Simon Mellerin Date: Wed, 30 Dec 2020 14:21:53 +0100 Subject: [PATCH 3/8] Update change_url script from example package --- scripts/change_url | 81 +++++++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 33 deletions(-) diff --git a/scripts/change_url b/scripts/change_url index 9e1f901..95e7130 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -21,10 +21,23 @@ new_path=$YNH_APP_NEW_PATH app=$YNH_APP_INSTANCE_NAME +#================================================= +# LOAD SETTINGS +#================================================= +ynh_script_progression --message="Loading installation settings..." --time --weight=1 + +# Needed for helper "ynh_add_nginx_config" +final_path=$(ynh_app_setting_get --app=$app --key=final_path) + +# Add settings here as needed by your application +#db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#db_user=$db_name +#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." --weight=1 +ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --time --weight=1 # Backup the current version of the app ynh_backup_before_upgrade @@ -32,7 +45,7 @@ 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 + # Restore it if the upgrade fails ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script @@ -45,64 +58,66 @@ ynh_abort_if_errors change_domain=0 if [ "$old_domain" != "$new_domain" ] then - change_domain=1 + change_domain=1 fi change_path=0 if [ "$old_path" != "$new_path" ] then - change_path=1 + change_path=1 fi #================================================= # STANDARD MODIFICATIONS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 + +ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" + #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating nginx web server configuration..." --weight=1 +ynh_script_progression --message="Updating NGINX web server configuration..." --time --weight=1 nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf -# Change the path in the nginx config file +# 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" - # Store path_url setting - ynh_app_setting_set --app=$app --key=path_url --value="$path_url" - # Create a dedicated nginx config - ynh_add_nginx_config - if [ "$path_url" = "/" ] - then - # Replace "//" location (due to nginx template) - # Prevent from replacing in "http://" expressions by excluding ":" as preceding character - sed --in-place "s@\([^:]\)//@\1/@g" "$nginx_conf_path" - else - # Move prefix comment #for-subdir at end of lines - sed --in-place "s/#for-subdir\(.*\)/\1 #for-subdir/g" "$nginx_conf_path" - fi - ynh_store_file_checksum --file="$nginx_conf_path" + # 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 +# 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" + # 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 #================================================= # GENERIC FINALISATION +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --time --weight=1 + +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" + #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --weight=1 +ynh_script_progression --message="Reloading NGINX web server..." --time --weight=1 ynh_systemd_action --service_name=nginx --action=reload @@ -110,4 +125,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" +ynh_script_progression --message="Change of URL completed for $app" --time --last From 4dd9bd0cd1228136c9ae623637ed1d2a0959a563 Mon Sep 17 00:00:00 2001 From: Simon Mellerin Date: Wed, 30 Dec 2020 14:22:23 +0100 Subject: [PATCH 4/8] Small updates --- check_process | 4 ++-- sources/patches/app-00-ldap-auth.patch | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/check_process b/check_process index 1acfa2a..d0ff635 100644 --- a/check_process +++ b/check_process @@ -13,7 +13,7 @@ setup_private=1 setup_public=1 upgrade=1 - upgrade=1 from_commit=702db62e7b25c06972301828b275529a087a98ba + upgrade=1 from_commit=25bf428e280f463fb85c3f8332b523415c56f816 backup_restore=1 multi_instance=1 incorrect_path=1 @@ -25,5 +25,5 @@ Email= Notification=change ;;; Upgrade options - ; commit=702db62e7b25c06972301828b275529a087a98ba + ; commit=25bf428e280f463fb85c3f8332b523415c56f816 name=1.0.3 diff --git a/sources/patches/app-00-ldap-auth.patch b/sources/patches/app-00-ldap-auth.patch index f5c54be..1a3ec39 100644 --- a/sources/patches/app-00-ldap-auth.patch +++ b/sources/patches/app-00-ldap-auth.patch @@ -2,8 +2,6 @@ commit c7a763a0fae7e1933f280b29bd2a1911b01f7170 Author: Simon Mellerin Date: Fri Nov 27 12:19:02 2020 +0100 - toto - diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 15ef608..8516775 100644 --- a/config/packages/security.yaml From 4e7e0f7353e2abca2f83728344c72326b3d02f42 Mon Sep 17 00:00:00 2001 From: Simon Mellerin Date: Wed, 30 Dec 2020 20:14:56 +0100 Subject: [PATCH 5/8] Fix change url script --- scripts/change_url | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/scripts/change_url b/scripts/change_url index 95e7130..9779b31 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -69,13 +69,6 @@ fi #================================================= # STANDARD MODIFICATIONS -#================================================= -# STOP SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 - -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" - #================================================= # MODIFY URL IN NGINX CONF #================================================= @@ -107,13 +100,6 @@ fi #================================================= # GENERIC FINALISATION -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." --time --weight=1 - -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" - #================================================= # RELOAD NGINX #================================================= From 69206d2626f72d6b5977d72229a52db42b4c2640 Mon Sep 17 00:00:00 2001 From: Simon Mellerin Date: Wed, 30 Dec 2020 20:31:36 +0100 Subject: [PATCH 6/8] Upgrade script - test with temp dir --- scripts/upgrade | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index f3a01f5..3c74d8f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -85,8 +85,16 @@ if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Upgrading source files..." + # Create tmpdir for new sources + tmpdir="$(ynh_smart_mktemp min_size=300)" + # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path" + ynh_setup_source --dest_dir="$tmpdir" + + # Replace the old aeneria by the new one + ynh_secure_remove --file="$final_path" + mv "$tmpdir" "$final_path" + ynh_secure_remove --file="$tmpdir" fi #================================================= From 8170057e5b14670b11a06b14b544c9c338afb9bc Mon Sep 17 00:00:00 2001 From: Simon Mellerin Date: Wed, 30 Dec 2020 21:21:51 +0100 Subject: [PATCH 7/8] Helpers - refacto + add ynh_smart_mktemp --- scripts/_common.sh | 50 +++++++++++++++++++++++++++++++++++++++++++++ scripts/install | 1 - scripts/upgrade | 1 - scripts/ynh_exec_as | 14 ------------- 4 files changed, 50 insertions(+), 16 deletions(-) delete mode 100644 scripts/ynh_exec_as diff --git a/scripts/_common.sh b/scripts/_common.sh index 328f4d1..d311cb1 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -19,6 +19,56 @@ extra_php_dependencies="php${YNH_PHP_VERSION}-zip php${YNH_PHP_VERSION}-pgsql ph # EXPERIMENTAL HELPERS #================================================= +# Execute a command as another user +# usage: exec_as USER COMMAND [ARG ...] +ynh_exec_as() { + local USER=$1 + shift 1 + + if [[ $USER = $(whoami) ]]; then + eval "$@" + else + sudo -u "$USER" "$@" + fi +} + +# Check available space before creating a temp directory. +# +# usage: ynh_smart_mktemp --min_size="Min size" +# +# | arg: -s, --min_size= - Minimal size needed for the temporary directory, in Mb +ynh_smart_mktemp () { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [s]=min_size= ) + local min_size + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + min_size="${min_size:-300}" + # Transform the minimum size from megabytes to kilobytes + min_size=$(( $min_size * 1024 )) + + # Check if there's enough free space in a directory + is_there_enough_space () { + local free_space=$(df --output=avail "$1" | sed 1d) + test $free_space -ge $min_size + } + + if is_there_enough_space /tmp; then + local tmpdir=/tmp + elif is_there_enough_space /var; then + local tmpdir=/var + elif is_there_enough_space /; then + local tmpdir=/ + elif is_there_enough_space /home; then + local tmpdir=/home + else + ynh_die "Insufficient free space to continue..." + fi + + echo "$(mktemp --directory --tmpdir="$tmpdir")" +} + #================================================= # FUTURE OFFICIAL HELPERS #================================================= diff --git a/scripts/install b/scripts/install index 54fdcb7..c0a858e 100644 --- a/scripts/install +++ b/scripts/install @@ -7,7 +7,6 @@ #================================================= source _common.sh -source ynh_exec_as source /usr/share/yunohost/helpers #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 3c74d8f..c08700d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,7 +7,6 @@ #================================================= source _common.sh -source ynh_exec_as source /usr/share/yunohost/helpers #================================================= diff --git a/scripts/ynh_exec_as b/scripts/ynh_exec_as deleted file mode 100644 index 2e849dc..0000000 --- a/scripts/ynh_exec_as +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -# Execute a command as another user -# usage: exec_as USER COMMAND [ARG ...] -ynh_exec_as() { - local USER=$1 - shift 1 - - if [[ $USER = $(whoami) ]]; then - eval "$@" - else - sudo -u "$USER" "$@" - fi -} From 8a3b580713c22efd47c216c8f54a9eee2db3a620 Mon Sep 17 00:00:00 2001 From: Simon Mellerin Date: Thu, 31 Dec 2020 12:11:01 +0100 Subject: [PATCH 8/8] Upgrade script - add comment --- scripts/upgrade | 6 ++++++ sources/patches/app-00-ldap-auth.patch | 1 + 2 files changed, 7 insertions(+) diff --git a/scripts/upgrade b/scripts/upgrade index c08700d..4672232 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -84,6 +84,12 @@ if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Upgrading source files..." + # For aeneria source update, we use a temporary directory because + # without it, patche can't be apply correctly: + # In 'app-00-ldap-auth.patch' we create a new file, if we try + # to apply the patch a second time while the file already exists, it + # throws a warning leading to an upgrade fail. + # Create tmpdir for new sources tmpdir="$(ynh_smart_mktemp min_size=300)" diff --git a/sources/patches/app-00-ldap-auth.patch b/sources/patches/app-00-ldap-auth.patch index 1a3ec39..09ec5aa 100644 --- a/sources/patches/app-00-ldap-auth.patch +++ b/sources/patches/app-00-ldap-auth.patch @@ -176,3 +176,4 @@ index 0000000..39ba1e8 + return $values[0]; + } +} +--