From f7ac631aea741cf7b38e612772f98c53f72d8b6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Wed, 31 May 2023 21:08:32 +0200 Subject: [PATCH] v2 --- actions.json | 77 ------------------ manifest.json | 63 --------------- manifest.toml | 23 +++--- scripts/_common.sh | 3 - scripts/actions/change_password | 56 -------------- scripts/actions/change_theme | 55 ------------- scripts/actions/public_private | 94 ---------------------- scripts/backup | 21 ----- scripts/change_url | 114 +-------------------------- scripts/install | 112 +-------------------------- scripts/remove | 47 ----------- scripts/restore | 57 +------------- scripts/upgrade | 133 +------------------------------- tests.toml | 3 + 14 files changed, 22 insertions(+), 836 deletions(-) delete mode 100644 actions.json delete mode 100644 manifest.json delete mode 100755 scripts/actions/change_password delete mode 100755 scripts/actions/change_theme delete mode 100755 scripts/actions/public_private create mode 100644 tests.toml diff --git a/actions.json b/actions.json deleted file mode 100644 index 34dfc3f..0000000 --- a/actions.json +++ /dev/null @@ -1,77 +0,0 @@ -[ - { - "id": "public_private", - "name": "Move to public or private", - "command": "/bin/bash scripts/actions/public_private", - "user": "root", - "accepted_return_codes": [ - 0 - ], - "description": { - "en": "Change the public access of the app.", - "fr": "Modifiez l'accès public de l'application." - }, - "arguments": [ - { - "name": "is_public", - "type": "boolean", - "ask": { - "en": "Is it a public app?", - "fr": "Est-ce une application publique ?" - }, - "default": true - } - ] - }, - { - "id": "change_password", - "name": "Change the admin password", - "command": "/bin/bash scripts/actions/change_password", - "user": "root", - "accepted_return_codes": [ - 0 - ], - "description": { - "en": "Change the admin password of the app.", - "fr": "Change le mot de passe administrateur de l'app." - }, - "arguments": [ - { - "name": "password", - "type": "password", - "ask": { - "en": "New password", - "fr": "Nouveau mot de passe" - } - } - ] - }, - { - "id": "change_theme", - "name": "Change the theme", - "command": "/bin/bash scripts/actions/change_theme", - "user": "root", - "accepted_return_codes": [ - 0 - ], - "description": { - "en": "Change the theme of the app.", - "fr": "Change le thème de l'app." - }, - "arguments": [ - { - "name": "theme", - "type": "string", - "ask": { - "en": "Choose a theme", - "fr": "Choisissez un theme" - }, - "choices": [ - "default", - "milligram" - ], - "default": "milligram" - } - ] - } -] \ No newline at end of file diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 4e620a7..0000000 --- a/manifest.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "name": "Lstu", - "id": "lstu", - "packaging_format": 1, - "description": { - "en": "URL Shortener", - "fr": "Raccourcisseur d'URL" - }, - "version": "0.26.0~ynh2", - "url": "https://lstu.fr", - "upstream": { - "license": "WTFPL", - "website": "https://lstu.fr", - "demo": "https://lstu.fr", - "admindoc": "https://framagit.org/fiat-tux/hat-softwares/lstu/wikis/home", - "code": "https://framagit.org/fiat-tux/hat-softwares/lstu" - }, - "license": "WTFPL", - "maintainer": { - "name": "frju365", - "email": "abld@abld.info" - }, - "requirements": { - "yunohost": ">= 4.3.0" - }, - "multi_instance": true, - "services": [ - "nginx" - ], - "arguments": { - "install": [ - { - "name": "domain", - "type": "domain" - }, - { - "name": "path", - "type": "path", - "example": "/lstu", - "default": "/lstu" - }, - { - "name": "is_public", - "type": "boolean", - "default": false - }, - { - "name": "theme", - "type": "string", - "ask": { - "en": "Choose a theme", - "fr": "Choisissez un theme" - }, - "choices": ["default", "milligram"], - "default": "milligram" - }, - { - "name": "password", - "type": "password" - } - ] - } -} diff --git a/manifest.toml b/manifest.toml index 36c8ce1..bea3cd0 100644 --- a/manifest.toml +++ b/manifest.toml @@ -15,26 +15,22 @@ website = "https://lstu.fr" demo = "https://lstu.fr" admindoc = "https://framagit.org/fiat-tux/hat-softwares/lstu/wikis/home" code = "https://framagit.org/fiat-tux/hat-softwares/lstu" -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 = ">= 4.3.0" -architectures = "all" # FIXME: can be replaced by a list of supported archs using the dpkg --print-architecture nomenclature (amd64/i386/armhf/arm64), for example: ["amd64", "i386"] +yunohost = ">= 11.1.19" +architectures = "all" multi_instance = true -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, ... +ldap = true +sso = true +disk = "50M" +ram.build = "50M" +ram.runtime = "50M" [install] [install.domain] - # this is a generic question - ask strings are automatically handled by Yunohost's core type = "domain" [install.path] - # this is a generic question - ask strings are automatically handled by Yunohost's core type = "path" default = "/lstu" @@ -50,7 +46,6 @@ ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requiremen default = "milligram" [install.password] - # this is a generic question - ask strings are automatically handled by Yunohost's core type = "password" [resources] @@ -58,6 +53,7 @@ ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requiremen url = "https://framagit.org/fiat-tux/hat-softwares/lstu/-/archive/0.26-0/lstu-0.26-0.tar.gz" sha256 = "323c81b4cb04a97eda7cb37b2a63d16e808591fd46eb4326f6619200ce742960" + [resources.ports] [resources.system_user] @@ -66,5 +62,8 @@ ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requiremen [resources.permissions] main.url = "/" + [resources.apt] + packages = "build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql carton libpod-parser-perl" + [resources.database] type = "postgresql" diff --git a/scripts/_common.sh b/scripts/_common.sh index 79d1443..03f3ceb 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,9 +4,6 @@ # COMMON VARIABLES #================================================= -# dependencies used by the app -#REMOVEME? pkg_dependencies="build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql carton libpod-parser-perl" - #================================================= # PERSONAL HELPERS #================================================= diff --git a/scripts/actions/change_password b/scripts/actions/change_password deleted file mode 100755 index dbd4551..0000000 --- a/scripts/actions/change_password +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash - -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -source scripts/_common.sh -source /usr/share/yunohost/helpers - -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -# Get is_public -password=${YNH_ACTION_PASSWORD} -hashed_password=$(echo -n $password | sha256sum | cut -d' ' -f1) - -app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} - -final_path=$(ynh_app_setting_get $app final_path) - -#================================================= -# CHECK IF AN ACTION HAS TO BE DONE -#================================================= - -hashed_password_old=$(ynh_app_setting_get $app hashed_password) - -if [ "$hashed_password" == "$hashed_password_old" ] -then - ynh_die --message="Same password." --ret_code=0 -fi - -#================================================= -# SPECIFIC ACTION -#================================================= -# MOVE TO PUBLIC OR PRIVATE -#================================================= - -ynh_backup_if_checksum_is_different "$final_path/lstu.conf" -ynh_replace_string "$hashed_password_old" "$hashed_password" "${final_path}/lstu.conf" -ynh_store_file_checksum "${final_path}/lstu.conf" - -# Update the config of the app -ynh_app_setting_set $app hashed_password $hashed_password - -#================================================= -# RELOAD NGINX -#================================================= - -ynh_systemd_action --service_name=$app --action="reload" --log_path="systemd" --line_match="Server available at" - -#================================================= -# END OF SCRIPT -#================================================= diff --git a/scripts/actions/change_theme b/scripts/actions/change_theme deleted file mode 100755 index 6c72973..0000000 --- a/scripts/actions/change_theme +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash - -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -source scripts/_common.sh -source /usr/share/yunohost/helpers - -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -# Get is_public -theme=${YNH_ACTION_THEME} - -app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} - -final_path=$(ynh_app_setting_get $app final_path) - -#================================================= -# CHECK IF AN ACTION HAS TO BE DONE -#================================================= - -theme_old=$(ynh_app_setting_get $app theme) - -if [ "$theme" == "$theme_old" ] -then - ynh_die --message="Same theme." --ret_code=0 -fi - -#================================================= -# SPECIFIC ACTION -#================================================= -# MOVE TO PUBLIC OR PRIVATE -#================================================= - -ynh_backup_if_checksum_is_different "$final_path/lstu.conf" -ynh_replace_string "$theme_old" "$theme" "${final_path}/lstu.conf" -ynh_store_file_checksum "${final_path}/lstu.conf" - -# Update the config of the app -ynh_app_setting_set $app theme $theme - -#================================================= -# RELOAD NGINX -#================================================= - -ynh_systemd_action --service_name=$app --action="reload" --log_path="systemd" --line_match="Server available at" - -#================================================= -# END OF SCRIPT -#================================================= diff --git a/scripts/actions/public_private b/scripts/actions/public_private deleted file mode 100755 index 97a6ba7..0000000 --- a/scripts/actions/public_private +++ /dev/null @@ -1,94 +0,0 @@ -#!/bin/bash - -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -source scripts/_common.sh -source /usr/share/yunohost/helpers - -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -# Get is_public -is_public=${YNH_ACTION_IS_PUBLIC} - -app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} - -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -port=$(ynh_app_setting_get $app port) -final_path=$(ynh_app_setting_get $app final_path) -secret=$(ynh_app_setting_get $app secret) -db_name=$(ynh_app_setting_get $app db_name) -db_user=$db_name -db_pwd=$(ynh_app_setting_get $app psqlpwd) -theme=$(ynh_app_setting_get $app theme) -hashed_password=$(ynh_app_setting_get $app hashed_password) - -#================================================= -# CHECK IF ARGUMENTS ARE CORRECT -#================================================= - -#================================================= -# CHECK IF AN ACTION HAS TO BE DONE -#================================================= - -is_public_old=$(ynh_app_setting_get $app is_public) - -if [ $is_public -eq $is_public_old ] -then - ynh_die --message="is_public is already set as $is_public." --ret_code=0 -fi - -#================================================= -# SPECIFIC ACTION -#================================================= -# MOVE TO PUBLIC OR PRIVATE -#================================================= - -if [ $is_public -eq 0 ]; -then - ynh_add_config --template="../conf/lstu.conf.ldap" --destination="$final_path/lstu.conf" -else - ynh_add_config --template="../conf/lstu.conf.template" --destination="$final_path/lstu.conf" -fi - -if [ $is_public -eq 0 ]; then - public_private="private" -else - public_private="public" -fi - -if [ $is_public -eq 0 ] -then - # If the app is private, only the shortened URLs are publics. - if [ "$path_url" == "/" ]; then - # If the path is /, clear it to prevent any error with the regex. - path_url="" - fi - # Modify the domain to be used in a regex - domain_regex=$(echo "$domain" | sed 's@-@.@g') - ynh_app_setting_set $app protected_regex "$domain_regex$path_url/login$","$domain_regex$path_url/logout$","$domain_regex$path_url/api$","$domain_regex$path_url/extensions$","$domain_regex$path_url/stats$","$domain_regex$path_url/d/.*$","$domain_regex$path_url/a$","$domain_regex$path_url/$" -else - ynh_app_setting_delete $app protected_regex -fi - -# Regen ssowat configuration -yunohost app ssowatconf - -# Update the config of the app -ynh_app_setting_set $app is_public $is_public - -#================================================= -# RELOAD NGINX -#================================================= - -ynh_systemd_action --service_name=$app --action="reload" --log_path="systemd" --line_match="Server available at" - -#================================================= -# END OF SCRIPT -#================================================= diff --git a/scripts/backup b/scripts/backup index 0247afc..0f520f0 100644 --- a/scripts/backup +++ b/scripts/backup @@ -10,27 +10,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -#REMOVEME? ynh_clean_setup () { - true -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_print_info --message="Loading installation settings..." - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#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) - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= diff --git a/scripts/change_url b/scripts/change_url index 9a52508..6ef2cea 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -9,70 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -#REMOVEME? old_domain=$YNH_APP_OLD_DOMAIN -#REMOVEME? old_path=$YNH_APP_OLD_PATH - -#REMOVEME? new_domain=$YNH_APP_NEW_DOMAIN -#REMOVEME? new_path=$YNH_APP_NEW_PATH - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_script_progression --message="Loading installation settings..." - -#REMOVEME? # Needed for helper "ynh_add_nginx_config" -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) - -# Add settings here as needed by your application -#REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port) -#REMOVEME? is_public=$(ynh_app_setting_get --app=$app --key=is_public) -#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) -#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) -#REMOVEME? db_user=$db_name -#REMOVEME? secret=$(ynh_app_setting_get --app=$app --key=secret) -#REMOVEME? theme=$(ynh_app_setting_get --app=$app --key=theme) -#REMOVEME? hashed_password=$(ynh_app_setting_get --app=$app --key=hashed_password) - -#================================================= -# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP -#================================================= -#REMOVEME? ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." - -# Backup the current version of the app -#REMOVEME? ynh_backup_before_upgrade -#REMOVEME? ynh_clean_setup () { - #REMOVEME? ynh_clean_check_starting - # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. -#REMOVEME? ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" - - # Restore it if the upgrade fails -#REMOVEME? ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - -#================================================= -# CHECK WHICH PARTS SHOULD BE CHANGED -#================================================= - -#REMOVEME? change_domain=0 -#REMOVEME? if [ "$old_domain" != "$new_domain" ] -then - #REMOVEME? change_domain=1 -fi - -#REMOVEME? change_path=0 -#REMOVEME? if [ "$old_path" != "$new_path" ] -then - #REMOVEME? change_path=1 -fi - #================================================= # STANDARD MODIFICATIONS #================================================= @@ -89,37 +25,13 @@ ynh_script_progression --message="Updating NGINX web server configuration..." ynh_change_url_nginx_config -#REMOVEME? 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 -#REMOVEME? ynh_backup_if_checksum_is_different --file="$nginx_conf_path" - # Set global variables for NGINX helper -#REMOVEME? domain="$old_domain" -#REMOVEME? path="$new_path" - # Create a dedicated NGINX config -#REMOVEME? 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 -#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 -#REMOVEME? ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" -fi - #================================================= # SPECIFIC MODIFICATIONS #================================================= # UPDATE A CONFIG FILE #================================================= ynh_script_progression --message="Updating a configuration file..." -#REMOVEME? + domain="$new_domain" path="$new_path" @@ -130,23 +42,6 @@ else ynh_add_config --template="../conf/lstu.conf.template" --destination="$install_dir/lstu.conf" fi -#================================================= -# UPDATE SSOWAT -#================================================= -ynh_script_progression --message="Reconfigure SSOwat" - -#REMOVEME? if [ $is_public -eq 0 ] -then - # If the app is private, only the shortened URLs are publics. - if [ "$path" == "/" ]; then - # If the path is /, clear it to prevent any error with the regex. -#REMOVEME? path="" - fi - # Modify the domain to be used in a regex - domain_regex=$(echo "$domain" | sed 's@-@.@g') -#REMOVEME? ynh_app_setting_set $app protected_regex "$domain_regex$path/login$","$domain_regex$path/logout$","$domain_regex$path/api$","$domain_regex$path/extensions$","$domain_regex$path/stats$","$domain_regex$path/d/.*$","$domain_regex$path/a$","$domain_regex$path/$" -fi - #================================================= # GENERIC FINALISATION #================================================= @@ -157,13 +52,6 @@ ynh_script_progression --message="Starting a systemd service..." # Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Server available at" -#================================================= -# RELOAD NGINX -#================================================= -#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." - -#REMOVEME? #REMOVEME? ynh_systemd_action --service_name=nginx --action=reload - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/install b/scripts/install index 876eec1..6a194c2 100644 --- a/scripts/install +++ b/scripts/install @@ -9,102 +9,29 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -#REMOVEME? ynh_clean_setup () { - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -#REMOVEME? domain=$YNH_APP_ARG_DOMAIN -#REMOVEME? path=$YNH_APP_ARG_PATH -#REMOVEME? is_public=$YNH_APP_ARG_IS_PUBLIC -#REMOVEME? theme=$YNH_APP_ARG_THEME -#REMOVEME? password=$YNH_APP_ARG_PASSWORD - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - secret=$(ynh_string_random --length=24) hashed_password=$(echo -n $password | sha256sum | cut -d' ' -f1) -#================================================= -# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS -#================================================= -#REMOVEME? ynh_script_progression --message="Validating installation parameters..." - -#REMOVEME? install_dir=/var/www/$app -#REMOVEME? test ! -e "$install_dir" || ynh_die --message="This path already contains a folder" - -# Register (book) web path -#REMOVEME? ynh_webpath_register --app=$app --domain=$domain --path=$path - #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -#REMOVEME? ynh_script_progression --message="Storing installation settings..." +ynh_script_progression --message="Storing installation settings..." -#REMOVEME? ynh_app_setting_set --app=$app --key=domain --value=$domain -#REMOVEME? ynh_app_setting_set --app=$app --key=path --value=$path -ynh_app_setting_set --app=$app --key=is_public --value=$is_public -ynh_app_setting_set --app=$app --key=theme --value=$theme ynh_app_setting_set --app=$app --key=secret --value=$secret -#REMOVEME? ynh_app_setting_set --app=$app --key=hashed_password --value=$hashed_password - -#================================================= -# STANDARD MODIFICATIONS -#================================================= -# FIND AND OPEN A PORT -#================================================= -#REMOVEME? ynh_script_progression --message="Finding an available port..." - -# Find an available port -#REMOVEME? port=$(ynh_find_port --port=8095) -#REMOVEME? ynh_app_setting_set --app=$app --key=port --value=$port - -#================================================= -# INSTALL DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Installing dependencies..." - -#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# CREATE DEDICATED USER -#================================================= -#REMOVEME? ynh_script_progression --message="Configuring system user..." - -# Create a system user -#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" - -#================================================= -# CREATE A POSTGRESQL DATABASE -#================================================= -#REMOVEME? ynh_script_progression --message="Creating a PostgreSQL database..." - -# Create postgresql database -#REMOVEME? ynh_psql_test_if_first_run -#REMOVEME? db_name=$(ynh_sanitize_dbid --db_name=$app) -#REMOVEME? db_user=$db_name -#REMOVEME? ynh_app_setting_set --app=$app --key=db_name --value=$db_name -#REMOVEME? ynh_psql_setup_db --db_user=$db_user --db_name=$db_name +ynh_app_setting_set --app=$app --key=hashed_password --value=$hashed_password #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." -#REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir" -chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" @@ -123,12 +50,7 @@ ynh_add_nginx_config #================================================= ynh_script_progression --message="Adding a configuration file..." -#REMOVEME? if [ $is_public -eq 0 ]; -then - ynh_add_config --template="../conf/lstu.conf.ldap" --destination="$install_dir/lstu.conf" -else - ynh_add_config --template="../conf/lstu.conf.template" --destination="$install_dir/lstu.conf" -fi +ynh_add_config --template="../conf/lstu.conf.ldap" --destination="$install_dir/lstu.conf" #================================================= # INSTALL LSTU @@ -170,34 +92,6 @@ ynh_script_progression --message="Starting a systemd service..." # Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Server available at" -#================================================= -# SETUP SSOWAT -#================================================= -#REMOVEME? ynh_script_progression --message="Configuring permissions..." - -# Everyone can access the app. -# The "main" permission is automatically created before the install script. -#REMOVEME? ynh_permission_update --permission="main" --add="visitors" - -#REMOVEME? if [ $is_public -eq 0 ] -then - # If the app is private, only the shortened URLs are publics. - if [ "$path" == "/" ]; then - # If the path is /, clear it to prevent any error with the regex. - path="" - fi - # Modify the domain to be used in a regex - domain_regex=$(echo "$domain" | sed 's@-@.@g') -#REMOVEME? ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path/login$","$domain_regex$path/logout$","$domain_regex$path/api$","$domain_regex$path/extensions$","$domain_regex$path/stats$","$domain_regex$path/d/.*$","$domain_regex$path/a$","$domain_regex$path/$" -fi - -#================================================= -# RELOAD NGINX -#================================================= -#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." - -#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/remove b/scripts/remove index e3f88dd..f49d8b3 100644 --- a/scripts/remove +++ b/scripts/remove @@ -9,19 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_script_progression --message="Loading installation settings..." - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#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 #================================================= @@ -51,22 +38,6 @@ ynh_script_progression --message="Removing logrotate configuration..." # Remove the app-specific logrotate config ynh_remove_logrotate -#================================================= -# REMOVE THE POSTGRESQL DATABASE -#================================================= -#REMOVEME? ynh_script_progression --message="Removing the PostgreSQL database..." - -# Remove a database if it exists, along with the associated user -#REMOVEME? ynh_psql_remove_db --db_user=$db_user --db_name=$db_name - -#================================================= -# REMOVE APP MAIN DIR -#================================================= -#REMOVEME? ynh_script_progression --message="Removing app main directory..." - -# Remove the app directory securely -#REMOVEME? ynh_secure_remove --file="$install_dir" - #================================================= # REMOVE NGINX CONFIGURATION #================================================= @@ -75,14 +46,6 @@ ynh_script_progression --message="Removing NGINX web server configuration..." # Remove the dedicated NGINX config ynh_remove_nginx_config -#================================================= -# REMOVE DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Removing dependencies..." - -# Remove metapackage and its dependencies -#REMOVEME? ynh_remove_app_dependencies - #================================================= # SPECIFIC REMOVE #================================================= @@ -93,16 +56,6 @@ ynh_script_progression --message="Removing various files..." # Remove the log files ynh_secure_remove --file="/var/log/$app.log" -#================================================= -# GENERIC FINALIZATION -#================================================= -# REMOVE DEDICATED USER -#================================================= -#REMOVEME? ynh_script_progression --message="Removing the dedicated system user..." - -# Delete a system user -#REMOVEME? ynh_system_user_delete --username=$app - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index 3a83388..678c06b 100644 --- a/scripts/restore +++ b/scripts/restore @@ -10,48 +10,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -#REMOVEME? ynh_clean_setup () { - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_script_progression --message="Loading installation settings..." - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#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? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) - -#================================================= -# CHECK IF THE APP CAN BE RESTORED -#================================================= -#REMOVEME? ynh_script_progression --message="Validating restoration parameters..." - -#REMOVEME? test ! -d $install_dir \ - || ynh_die --message="There is already a directory: $install_dir " - -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -#REMOVEME? ynh_script_progression --message="Recreating the dedicated system user..." - -# Create the dedicated user (if not existing) -#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" - #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -59,20 +17,9 @@ ynh_script_progression --message="Restoring the app main directory..." ynh_restore_file --origin_path="$install_dir" -chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." - -# Define and install dependencies -#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies - #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= @@ -83,10 +30,8 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= -#REMOVEME? ynh_script_progression --message="Restoring the PostregSQL database..." +ynh_script_progression --message="Restoring the PostregSQL database..." -#REMOVEME? ynh_psql_test_if_first_run -#REMOVEME? ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index f68b950..089257e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,47 +9,12 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_script_progression --message="Loading installation settings..." - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) -#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path) -#REMOVEME? is_public=$(ynh_app_setting_get --app=$app --key=is_public) -#REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port) -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) -#REMOVEME? secret=$(ynh_app_setting_get --app=$app --key=secret) -#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) -#REMOVEME? db_user=$db_name -#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) -#REMOVEME? theme=$(ynh_app_setting_get --app=$app theme) -#REMOVEME? hashed_password=$(ynh_app_setting_get --app=$app --key=hashed_password) - #================================================= # CHECK VERSION #================================================= -ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." - -# Backup the current version of the app -#REMOVEME? ynh_backup_before_upgrade -#REMOVEME? ynh_clean_setup () { - ynh_clean_check_starting - # Restore it if the upgrade fails -#REMOVEME? ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -64,62 +29,11 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" #================================================= ynh_script_progression --message="Ensuring downward compatibility..." -# 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 [ -z "$db_pwd" ]; then -#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) # Fix old db_pwd - if [ -z "$db_pwd" ]; then -#REMOVEME? ynh_psql_test_if_first_run - db_name=$(ynh_sanitize_dbid --db_name="$app") - db_user=$db_name - # Initialize database and store postgres password for upgrade -#REMOVEME? ynh_psql_setup_db --db_user="$db_user" --db_name="$db_name" -#REMOVEME? ynh_app_setting_set --app="$app" --key=db_name --value="$db_name" -#REMOVEME? #REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) # Password created in ynh_psql_setup_db function - else - ynh_app_setting_delete --app=$app --key=db_pwd -#REMOVEME? ynh_app_setting_set --app=$app --key=psqlpwd --value=$db_pwd - fi -fi - if [ -z "$theme" ]; then theme="milligram" ynh_app_setting_set --app=$app --key=theme --value=$theme fi -if [ -z "$hashed_password" ]; then - # Generate random password - password=$(ynh_string_random --length=8) - hashed_password=$(echo -n $password | sha256sum | cut -d' ' -f1) - - echo "The new version of LSTU provide an admin and a stats area which required a password." > mail_to_send - echo "" >> mail_to_send - echo "This password is: $password" >> mail_to_send - - ynh_send_readme_to_admin --app_message="mail_to_send" --type="upgrade" - -#REMOVEME? ynh_app_setting_set --app=$app --key=hashed_password --value=$hashed_password -fi - -# In previous versions, the port was mistakenly exposed to the outside world >_> -if yunohost firewall list | grep -q "\- $port$" -then - ynh_script_progression --message="Closing port $port..." - ynh_exec_warn_less yunohost firewall disallow TCP $port -fi - -#================================================= -# CREATE DEDICATED USER -#================================================= -#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." - -# Create a dedicated user (if not existing) -#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -129,20 +43,12 @@ then ynh_script_progression --message="Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$install_dir" #--keep="lstu.conf" + ynh_setup_source --dest_dir="$install_dir" --keep="lstu.conf" fi -chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." - -#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies - #================================================= # NGINX CONFIGURATION #================================================= @@ -156,14 +62,9 @@ ynh_add_nginx_config #================================================= # UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Updating a configuration file..." +#ynh_script_progression --message="Updating a configuration file..." -#REMOVEME? if [ $is_public -eq 0 ]; -then - ynh_add_config --template="../conf/lstu.conf.ldap" --destination="$install_dir/lstu.conf" -else - ynh_add_config --template="../conf/lstu.conf.template" --destination="$install_dir/lstu.conf" -fi +#ynh_add_config --template="../conf/lstu.conf.ldap" --destination="$install_dir/lstu.conf" #================================================= # BUILD LSU @@ -206,34 +107,6 @@ ynh_script_progression --message="Starting a systemd service..." ynh_systemd_action --service_name=$app --action=reload --line_match="Reloaded Shortened URLs service." --log_path="systemd" -#================================================= -# SETUP SSOWAT -#================================================= -#REMOVEME? ynh_script_progression --message="Configuring permissions..." - -# Everyone can access the app. -# The "main" permission is automatically created before the install script. -#REMOVEME? ynh_permission_update --permission="main" --add="visitors" - -#REMOVEME? if [ $is_public -eq 0 ] -then - # If the app is private, only the shortened URLs are publics. - if [ "$path" == "/" ]; then - # If the path is /, clear it to prevent any error with the regex. - path="" - fi - # Modify the domain to be used in a regex - domain_regex=$(echo "$domain" | sed 's@-@.@g') -#REMOVEME? ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path/login$","$domain_regex$path/logout$","$domain_regex$path/api$","$domain_regex$path/extensions$","$domain_regex$path/stats$","$domain_regex$path/d/.*$","$domain_regex$path/a$","$domain_regex$path/$" -fi - -#================================================= -# RELOAD NGINX -#================================================= -#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." - -#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..cbbeef1 --- /dev/null +++ b/tests.toml @@ -0,0 +1,3 @@ +test_format = 1.0 + +[default]