From 30013f9a476d918b3571d69bfee801ae9f2a26db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 29 Mar 2024 12:15:57 +0100 Subject: [PATCH] Manifest v2 --- check_process | 29 ------ conf/app.src | 5 -- conf/systemd.service | 2 +- doc/ADMIN.md | 1 + doc/DISCLAIMER.md | 8 -- doc/PRE_INSTALL.md | 1 + manifest.json | 67 -------------- manifest.toml | 69 ++++++++++++++ scripts/_common.sh | 3 - scripts/backup | 36 ++------ scripts/change_url | 92 +------------------ scripts/install | 182 ++++++++----------------------------- scripts/remove | 68 ++------------ scripts/restore | 109 +++++----------------- scripts/upgrade | 210 ++++++++++++------------------------------- tests.toml | 10 +++ 16 files changed, 211 insertions(+), 681 deletions(-) delete mode 100644 check_process delete mode 100644 conf/app.src create mode 100644 doc/ADMIN.md delete mode 100644 doc/DISCLAIMER.md create mode 100644 doc/PRE_INSTALL.md delete mode 100644 manifest.json create mode 100644 manifest.toml create mode 100644 tests.toml diff --git a/check_process b/check_process deleted file mode 100644 index 479cd4d..0000000 --- a/check_process +++ /dev/null @@ -1,29 +0,0 @@ -# See here for more information -# https://github.com/YunoHost/package_check#syntax-check_process-file - -;; Test complet - ; pre-install - sudo yunohost app install https://github.com/YunoHost-Apps/zerotier_ynh --force - ; Manifest - domain="domain.tld" - path="/" - admin="john" - is_public=1 - password="DaB3estPassw0rd" - ; Checks - pkg_linter=1 - setup_sub_dir=0 - setup_root=1 - setup_nourl=0 - setup_private=1 - setup_public=1 - upgrade=1 - ;upgrade=1 from_commit=CommitHash - backup_restore=1 - multi_instance=0 - port_already_use=0 - change_url=1 -;;; Upgrade options - ; commit=CommitHash - name=Name and date of the commit. - manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=DaB3estPassw0rd&port=666& diff --git a/conf/app.src b/conf/app.src deleted file mode 100644 index eb85509..0000000 --- a/conf/app.src +++ /dev/null @@ -1,5 +0,0 @@ -SOURCE_URL=https://github.com/key-networks/ztncui/archive/42248c13593e90f62238ee79ea5708a54eacf753.zip -SOURCE_SUM=596450AF9F567D64EBDD488F0F379E3BFC0BB569EDEA6C832ADF0DC3DA693F0F -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=zip -SOURCE_IN_SUBDIR=true diff --git a/conf/systemd.service b/conf/systemd.service index ed26158..545c591 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -7,7 +7,7 @@ Type=simple User=__APP__ Group=__APP__ Environment="__YNH_NODE_LOAD_PATH__" -WorkingDirectory=__FINALPATH__/src/ +WorkingDirectory=__INSTALL_DIR__/src/ ExecStart=__YNH_NPM__ start StandardOutput=append:/var/log/__APP__/__APP__.log StandardError=inherit diff --git a/doc/ADMIN.md b/doc/ADMIN.md new file mode 100644 index 0000000..ef7e18a --- /dev/null +++ b/doc/ADMIN.md @@ -0,0 +1 @@ +Multiple users can use the app, you have to add them manually in `/opt/key-networks/ztncui/src/etc/passwd`, see ztncui's documentation. diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md deleted file mode 100644 index e16555a..0000000 --- a/doc/DISCLAIMER.md +++ /dev/null @@ -1,8 +0,0 @@ -### Dependency - -* [ZeroTier for YunoHost](https://github.com/YunoHost-Apps/zerotier_ynh) has to be installed beforehand. - -### Multi-users support - - * LDAP and HTTP auth are not supported. - * Multiple users can use the app, you have to add them manually in `/opt/key-networks/ztncui/src/etc/passwd`, see ztncui's documentation. diff --git a/doc/PRE_INSTALL.md b/doc/PRE_INSTALL.md new file mode 100644 index 0000000..9723e2e --- /dev/null +++ b/doc/PRE_INSTALL.md @@ -0,0 +1 @@ +[ZeroTier for YunoHost](https://github.com/YunoHost-Apps/zerotier_ynh) has to be installed beforehand if it's not already installed. diff --git a/manifest.json b/manifest.json deleted file mode 100644 index f566c89..0000000 --- a/manifest.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "name": "Zerotier UI", - "id": "ztncui", - "packaging_format": 1, - "description": { - "en": "ZeroTier network controller user interface", - "fr": "Interface utilisateur pour le contrôleur de réseau ZeroTier" - }, - "version": "20230311~ynh1", - "url": "https://key-networks.com/ztncui", - "upstream": { - "license": "GPL-3.0-only", - "website": "https://key-networks.com/ztncui/", - "code": "https://github.com/key-networks/ztncui" - }, - "license": "GPL-3.0-only", - "maintainer": { - "name": "tituspijean", - "email": "tituspijean@outlook.com" - }, - "requirements": { - "yunohost": ">= 4.3" - }, - "services": [], - "multi_instance": false, - "arguments": { - "install": [ - { - "name": "warning", - "type": "alert", - "ask": { - "en": "REMINDER: ztncui needs the ZeroTier app to be already installed.", - "fr": "RAPPEL: ztncui nécessite que l'app ZeroTier soit déjà installée." - } - }, - { - "name": "domain", - "type": "domain", - "help": { - "en": "Ztncui can only be installed at the root of a domain.", - "fr": "Ztncui ne peut être installée qu'à la racine d'un domaine." - } - }, - { - "name": "is_public", - "type": "boolean", - "help": { - "en": "Ztncui has its own login system, but setting it as private is advised.", - "fr": "Ztncui a son propre système de connexion, mais la rendre privée est conseillé." - }, - "default": false - }, - { - "name": "admin", - "type": "user" - }, - { - "name": "password", - "type": "password", - "help": { - "en": "It will always be asked by Ztncui, in addition to your YunoHost credentials if set to private.", - "fr": "Il sera toujours demandé par Ztncui, en plus des identifiants YunoHost si l'app est privée." - } - } - ] - } -} diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..78fca41 --- /dev/null +++ b/manifest.toml @@ -0,0 +1,69 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json + +packaging_format = 2 + +id = "ztncui" +name = "Zerotier UI" +description.en = "ZeroTier network controller user interface" +description.fr = "Interface utilisateur pour le contrôleur de réseau ZeroTier" + +version = "20230311~ynh2" + +maintainers = ["tituspijean"] + +[upstream] +license = "GPL-3.0-only" +website = "https://key-networks.com/ztncui/" +code = "https://github.com/key-networks/ztncui" +cpe = "???" # FIXME: optional but recommended if relevant, this is meant to contain the Common Platform Enumeration, which is sort of a standard id for applications defined by the NIST. In particular, Yunohost may use this is in the future to easily track CVE (=security reports) related to apps. The CPE may be obtained by searching here: https://nvd.nist.gov/products/cpe/search. For example, for Nextcloud, the CPE is 'cpe:2.3:a:nextcloud:nextcloud' (no need to include the version number) +fund = "???" # FIXME: optional but recommended (or remove if irrelevant / not applicable). This is meant to be an URL where people can financially support this app, especially when its development is based on volunteers and/or financed by its community. YunoHost may later advertise it in the webadmin. + +[integration] +yunohost = ">=11.2" +architectures = "all" +multi_instance = false +ldap = "?" # FIXME: replace with true, false, or "not_relevant". Not to confuse with the "sso" key : the "ldap" key corresponds to wether or not a user *can* login on the app using its YunoHost credentials. +sso = "?" # FIXME: replace with true, false, or "not_relevant". Not to confuse with the "ldap" key : the "sso" key corresponds to wether or not a user is *automatically logged-in* on the app when logged-in on the YunoHost portal. +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] + help.en = "Ztncui can only be installed at the root of a domain." + help.fr = "Ztncui ne peut être installée qu'à la racine d'un domaine." + type = "domain" + + [install.init_main_permission] + help.en = "Ztncui has its own login system, but setting it as private is advised." + help.fr = "Ztncui a son propre système de connexion, mais la rendre privée est conseillé." + type = "group" + default = false + + [install.admin] + type = "user" + + [install.password] + help.en = "It will always be asked by Ztncui, in addition to your YunoHost credentials if set to private." + help.fr = "Il sera toujours demandé par Ztncui, en plus des identifiants YunoHost si l'app est privée." + type = "password" + +[resources] + [resources.sources.main] + url = "https://github.com/key-networks/ztncui/archive/42248c13593e90f62238ee79ea5708a54eacf753.zip" + sha256 = "596450af9f567d64ebdd488f0f379e3bfc0bb569edea6c832adf0dc3da693f0f" + + autoupdate.strategy = "latest_github_commit" + + [resources.system_user] + + [resources.install_dir] + + [resources.permissions] + main.url = "/" + + [resources.ports] + main.default = 8095 + + [resources.apt] + packages = ["g++"] diff --git a/scripts/_common.sh b/scripts/_common.sh index 01dc4fc..7912aa4 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -6,9 +6,6 @@ nodejs_version=14 -# dependencies used by the app -pkg_dependencies="g++" - #================================================= # PERSONAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index bbe4879..18aea2a 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -9,26 +7,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { - true -} -# 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) - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= @@ -38,27 +16,23 @@ 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 +# BACKUP THE SYSTEM CONFIGURATION #================================================= ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# SPECIFIC BACKUP -#================================================= -# BACKUP LOGROTATE -#================================================= +ynh_backup --src_path="/etc/systemd/system/$app.service" ynh_backup --src_path="/etc/logrotate.d/$app" #================================================= -# BACKUP SYSTEMD +# BACKUP VARIOUS FILES #================================================= -ynh_backup --src_path="/etc/systemd/system/$app.service" +ynh_backup --src_path="/var/log/$app/" #================================================= # END OF SCRIPT diff --git a/scripts/change_url b/scripts/change_url index 2e7d687..3435532 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -9,61 +7,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -old_domain=$YNH_APP_OLD_DOMAIN -old_path=$YNH_APP_OLD_PATH - -new_domain=$YNH_APP_NEW_DOMAIN -new_path=$YNH_APP_NEW_PATH - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -# Needed for helper "ynh_add_nginx_config" -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. - ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" - - # restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# CHECK WHICH PARTS SHOULD BE CHANGED -#================================================= - -change_domain=0 -if [ "$old_domain" != "$new_domain" ] -then - change_domain=1 -fi - -change_path=0 -if [ "$old_path" != "$new_path" ] -then - change_path=1 -fi - -#================================================= -# STANDARD MODIFICATIONS #================================================= # STOP SYSTEMD SERVICE #================================================= @@ -76,45 +19,14 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app #================================================= ynh_script_progression --message="Updating NGINX web server configuration..." -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 -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 - -#================================================= -# GENERIC FINALISATION #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." -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..." - -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index 101d01f..08d9482 100644 --- a/scripts/install +++ b/scripts/install @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,69 +8,24 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# MANAGE SCRIPT FAILURE +# INITIALIZE AND STORE SETTINGS #================================================= -ynh_clean_setup () { - ### Remove this function if there's nothing to clean before calling the remove script. - true -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# RETRIEVE ARGUMENTS FROM THE MANIFEST -#================================================= - -domain=$YNH_APP_ARG_DOMAIN -path_url="/" #$YNH_APP_ARG_PATH -is_public=$YNH_APP_ARG_IS_PUBLIC -admin=$YNH_APP_ARG_ADMIN -password=$YNH_APP_ARG_PASSWORD - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS -#================================================= -ynh_script_progression --message="Validating installation parameters..." --weight=1 - # Testing if ZeroTier is installed -yunohost app list | grep -q "id: zerotier" || ynh_die "ZeroTier is needed, but it is not installed. There is a package for that!" +if ! yunohost app list | grep -q "id: zerotier"; then + ynh_die "ZeroTier is needed, but it is not installed. There is a package for that!" +fi -final_path=/opt/yunohost/$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=1 - -ynh_app_setting_set --app=$app --key=domain --value=$domain -ynh_app_setting_set --app=$app --key=final_path --value=$final_path - -#================================================= -# STANDARD MODIFICATIONS -#================================================= -# FIND AND OPEN A PORT -#================================================= -ynh_script_progression --message="Finding an available port..." --weight=1 - -# Find an available port -port=$(ynh_find_port --port=8095) -ynh_app_setting_set --app=$app --key=port --value=$port +# Let's retrieve information on the ZeroTier installation +zt_token="$( "$final_path/src/etc/passwd" - -# Store user settings -ynh_app_setting_set --app=$app --key=admin --value=$admin -ynh_app_setting_set --app=$app --key=hashedpassword --value=$hashedpassword +hashedpassword=$(echo -n "$password" | $install_dir/src/node_modules/.bin/argon2-cli -e) +echo "{\"$admin\":{\"name\":\"$admin\",\"pass_set\":true,\"hash\":\"$hashedpassword\"}}" > "$install_dir/src/etc/passwd" #================================================= # LINK CERTIFICATES #================================================= # Even though one can stay in HTTP mode, the ztncui requires SSL certificates -# let's use the ones of the domain -pushd $final_path/src/etc/tls - cp /etc/yunohost/certs/$domain/key.pem privkey.pem - cp /etc/yunohost/certs/$domain/crt.pem fullchain.pem -popd +# let's use the ones of the domain +cp "/etc/yunohost/certs/$domain/key.pem" "$install_dir/src/etc/tls/privkey.pem" +cp "/etc/yunohost/certs/$domain/crt.pem" "$install_dir/src/etc/tls/fullchain.pem" #================================================= -# SETUP SYSTEMD +# SYSTEM CONFIGURATION #================================================= -ynh_script_progression --message="Configuring a systemd service..." --weight=1 +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 + +# Create a dedicated nginx config +ynh_add_nginx_config # Create a dedicated systemd config ynh_add_systemd_config - -#================================================= -# GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - -# Set permissions to app files -chown -R $app: $final_path - -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Configuring log rotation..." --weight=1 +yunohost service add "$app" --description "ZeroTier network controller user interface" --log "/var/log/$app/$app.log" # Use logrotate to manage application logfile(s) ynh_use_logrotate -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 - -yunohost service add $app --description "ZeroTier network controller user interface" --log "/var/log/$app/$app.log" - #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting the systemd service..." --weight=1 +ynh_script_progression --message="Starting $app's systemd service..." --weight=1 -# Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" - -#================================================= -# SETUP SSOWAT -#================================================= -ynh_script_progression --message="Configuring SSOwat..." - -# Make app public if necessary -if [ $is_public -eq 1 ] -then - ynh_permission_update --permission "main" --add visitors -fi - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading nginx web server..." --weight=1 - -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 54b350d..e35e571 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,73 +8,24 @@ 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) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - -#================================================= -# STANDARD REMOVE -#================================================= -# REMOVE SERVICE INTEGRATION IN YUNOHOST +# REMOVE SYSTEM CONFIGURATIONS #================================================= +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 # Remove the service from the list of services known by Yunohost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null -then - ynh_script_progression --message="Removing $app service..." --weight=1 - yunohost service remove $app +if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then + yunohost service remove "$app" fi -#================================================= -# STOP AND REMOVE SERVICE -#================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 - # Remove the dedicated systemd config ynh_remove_systemd_config -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." --weight=2 - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - -ynh_remove_nodejs - -#================================================= -# 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 -#================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 - # Remove the dedicated NGINX config ynh_remove_nginx_config -#================================================= -# REMOVE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Removing logrotate configuration..." --weight=1 - # Remove the app-specific logrotate config ynh_remove_logrotate -#================================================= -# SPECIFIC REMOVE #================================================= # REMOVE VARIOUS FILES #================================================= @@ -86,14 +35,11 @@ ynh_script_progression --message="Removing various files..." --weight=1 ynh_secure_remove --file="/var/log/$app" #================================================= -# GENERIC FINALIZATION +# REMOVE DEPENDENCIES #================================================= -# REMOVE DEDICATED USER -#================================================= -ynh_script_progression --message="Removing the dedicated system user..." --weight=1 +ynh_script_progression --message="Removing NodeJS..." --weight=2 -# Delete a system user -ynh_system_user_delete --username=$app +ynh_remove_nodejs #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index 53a3c3c..d080f03 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,112 +8,47 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= -# MANAGE SCRIPT FAILURE +# INSTALL DEPENDENCIES #================================================= +ynh_script_progression --message="Installing NodeJS..." --weight=2 -ynh_clean_setup () { - #### Remove this function if there's nothing to clean before calling the remove script. - true -} -# 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) -nodejs_version=$(ynh_app_setting_get --app=$app --key=nodejs_version) - -#================================================= -# 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 -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_install_nodejs --nodejs_version="$nodejs_version" +ynh_use_nodejs #================================================= # 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" + +chown -R "$app:$app" "$install_dir" #================================================= -# RECREATE THE DEDICATED USER +# RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 -# Create the dedicated user (if not existing) -ynh_system_user_create --username=$app - -#================================================= -# RESTORE USER RIGHTS -#================================================= - -# Restore permissions on app files -chown -R $app: $final_path - -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=2 - -ynh_install_app_dependencies $pkg_dependencies - -ynh_install_nodejs --nodejs_version=$nodejs_version - -#================================================= -# RESTORE SYSTEMD -#================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/systemd/system/$app.service" -systemctl enable $app.service --quiet - -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 - -yunohost service add $app --description "ZeroTier network controller user interface" --log "/var/log/$app/$app.log" - -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 - -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" - -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= +systemctl enable "$app.service" --quiet +yunohost service add "$app" --description "ZeroTier network controller user interface" --log "/var/log/$app/$app.log" ynh_restore_file --origin_path="/etc/logrotate.d/$app" -mkdir -p "/var/log/$app" #================================================= -# GENERIC FINALIZATION +# RESTORE VARIOUS FILES #================================================= -# RELOAD NGINX AND PHP-FPM + +ynh_restore_file --origin_path="/var/log/$app/" + #================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 +# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE +#================================================= +ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 + +ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/upgrade b/scripts/upgrade index fd7fc21..7f1ac8e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,206 +8,114 @@ 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) -path_url=$(ynh_app_setting_get --app=$app --key=path) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -port=$(ynh_app_setting_get --app=$app --key=port) -admin=$(ynh_app_setting_get --app=$app --key=admin) -hashedpassword=$(ynh_app_setting_get --app=$app --key=hashedpassword) - -#================================================= -# CHECK VERSION +# INITIALIZE AND STORE SETTINGS #================================================= -upgrade_type=$(ynh_check_app_version_changed) +# Testing if ZeroTier is installed +if ! yunohost app list | grep -q "id: zerotier"; then + ynh_die "ZeroTier is needed, but it is not installed. There is a package for that!" +fi + +# Let's retrieve information on the ZeroTier installation +zt_token="$( "$final_path/src/etc/passwd" + # Setup user credentials file + echo "{\"$admin\":{\"name\":\"$admin\",\"pass_set\":$pass_set,\"hash\":\"$hashedpassword\"}}" > "$install_dir/src/etc/passwd" else - pass_set="true" + pass_set="true" fi -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=3 - -# 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 #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression --message="Stopping $app's systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log" + +#================================================= +# INSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Upgrading NodeJS..." --weight=2 + +ynh_install_nodejs --nodejs_version="$nodejs_version" +ynh_use_nodejs #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Upgrading source files..." --weight=1 -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." --weight=1 +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source --dest_dir="$install_dir" --full_replace=1 - # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path" -fi +chown -R "$app:$app" "$install_dir" #================================================= -# NGINX CONFIGURATION +# UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1 +ynh_script_progression --message="Updating $app's configuration files..." --weight=1 -# Create a dedicated nginx config -ynh_add_nginx_config +ynh_add_config --template="env" --destination="$install_dir/src/.env" -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=2 +chown "$app:$app" "$install_dir/src/.env" +chmod 600 "$install_dir/src/.env" -ynh_install_app_dependencies $pkg_dependencies - -if [ $nodejs_version != $(ynh_app_setting_get --app=$app --key=nodejs_version) ]; then - ynh_remove_nodejs - ynh_install_nodejs --nodejs_version=$nodejs_version -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 $app $final_path - -#================================================= -# SPECIFIC UPGRADE #================================================= # NPM INSTALL #================================================= -ynh_script_progression --message="Performing Node app installation..." --weight=3 +ynh_script_progression --message="Building $app..." --weight=3 -chown -R $app: $final_path - -ynh_use_nodejs - -pushd $final_path/src - ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH HOME=$final_path $ynh_npm install node-gyp - ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH HOME=$final_path $ynh_npm install argon2-cli - ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH HOME=$final_path $ynh_npm install - ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH HOME=$final_path $ynh_npm audit fix +pushd "$install_dir/src" + ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" "HOME=$install_dir" "$ynh_npm" install node-gyp + ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" "HOME=$install_dir" "$ynh_npm" install argon2-cli + ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" "HOME=$install_dir" "$ynh_npm" install + ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" "HOME=$install_dir" "$ynh_npm" audit fix popd -#================================================= -# MODIFY A CONFIG FILE -#================================================= - -# Let's retrieve information on the ZeroTier installation -zt_token="$(