From aa37d46ddb0fcab66c3f00a3415e99e7bc8f6e01 Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Mon, 30 Aug 2021 23:12:28 +0200 Subject: [PATCH] upgrade package --- check_process | 35 ++-- conf/app.src | 6 +- conf/nginx.conf | 2 + manifest.json | 35 ++-- scripts/_common.sh | 468 +-------------------------------------------- scripts/_variables | 4 - scripts/install | 18 +- 7 files changed, 49 insertions(+), 519 deletions(-) delete mode 100644 scripts/_variables diff --git a/check_process b/check_process index d4cecc9..13b38ac 100644 --- a/check_process +++ b/check_process @@ -1,31 +1,26 @@ -;; Test1 +;; Test complet ; Manifest - domain="domain.tld" (DOMAIN) - path="/" (PATH) + domain="domain.tld" + path="/path" + is_public=1 ; Checks pkg_linter=1 setup_sub_dir=1 setup_root=1 setup_nourl=0 setup_private=1 - setup_public=0 + setup_public=1 upgrade=1 + #upgrade=1 from_commit=CommitHash backup_restore=1 - multi_instance=0 - incorrect_path=1 - port_already_use=1 (9001) - change_url=0 -;;; Levels - Level 1=auto - Level 2=auto - Level 3=auto - Level 4=na - Level 5=auto - Level 6=auto - Level 7=auto - Level 8=0 - Level 9=0 - Level 10=0 + multi_instance=1 + port_already_use=0 + change_url=1 ;;; Options Email= -Notification=change +Notification=none +;;; 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=pass&port=666& + diff --git a/conf/app.src b/conf/app.src index 571acde..2b3a701 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,6 +1,6 @@ -SOURCE_URL=https://github.com/timeoff-management/application/archive/v0.10.0.tar.gz -SOURCE_SUM=3dc6e8ab0d4a151bf8b30a0fd2094af6 -SOURCE_SUM_PRG=md5sum +SOURCE_URL=https://github.com/timeoff-management/timeoff-management-application/archive/refs/tags/1.3.3.tar.gz +SOURCE_SUM=e320350dbf1d1ce272cee1db845e3658945d57e49eb97a56df3d00cf63ab6fe6 +SOURCE_SUM_PRG=sha256sum ARCH_FORMAT=tar.gz SOURCE_IN_SUBDIR=true SOURCE_FILENAME= diff --git a/conf/nginx.conf b/conf/nginx.conf index ab2eb0b..f4bd84e 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,7 +1,9 @@ location __PATH__/ { + if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent; } + proxy_pass http://127.0.0.1:__PORT__/; proxy_set_header Host $host; proxy_buffering off; diff --git a/manifest.json b/manifest.json index 13bdd81..a6f998f 100644 --- a/manifest.json +++ b/manifest.json @@ -3,17 +3,25 @@ "id": "timeoff", "packaging_format": 1, "description": { - "en": "Open source, simple yet powerful absence management software for small and medium size business." + "en": "Web application for managing employee absences" }, - "version": "0.10.0~ynh2", + "version": "1.3.3~ynh1", "url": "https://timeoff.management/", + "upstream": { + "license": "MIT", + "website": "https://timeoff.management/", + "demo": "https://demo.example.com", + "admindoc": "https://timeoff.management/support/main-page.html", + "userdoc": "https://yunohost.org/apps", + "code": "https://github.com/timeoff-management/timeoff-management-application" + }, "license": "MIT", "maintainer": { "name": "Julien Malik", "email": "ju@paraiso.me" }, "requirements": { - "yunohost": ">= 2.7.10" + "yunohost": ">= 4.2.4" }, "multi_instance": false, "services": [ @@ -25,22 +33,13 @@ { "name": "domain", "type": "domain", - "ask": { - "en": "Choose a domain for Timeoff Management.", - "fr": "Choisissez un domaine pour Timeoff Management." - }, - "example": "sub.domain.org" + "example": "example.com" }, - { - "name": "path", - "type": "path", - "ask": { - "en": "Choose a path for Timeoff Management, only / is supported", - "fr": "Choisissez un chemin pour Timeoff Management, seulement / est supporté pour l'instant" - }, - "example": "/", - "default": "/" - } + { + "name": "is_public", + "type": "boolean", + "default": true + } ] } } diff --git a/scripts/_common.sh b/scripts/_common.sh index df0814d..55f4bd5 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,474 +1,20 @@ #!/bin/bash #================================================= -# BACKUP +# COMMON VARIABLES #================================================= -HUMAN_SIZE () { # Transforme une taille en Ko en une taille lisible pour un humain - human=$(numfmt --to=iec --from-unit=1K $1) - echo $human -} +# nodejs version +nodejs_version=14 -CHECK_SIZE () { # Vérifie avant chaque backup que l'espace est suffisant - file_to_analyse=$1 - backup_size=$(du --summarize "$file_to_analyse" | cut -f1) - free_space=$(df --output=avail "/home/yunohost.backup" | sed 1d) - - if [ $free_space -le $backup_size ] - then - ynh_print_err "Espace insuffisant pour sauvegarder $file_to_analyse." - ynh_print_err "Espace disponible: $(HUMAN_SIZE $free_space)" - ynh_die "Espace nécessaire: $(HUMAN_SIZE $backup_size)" - fi -} +#================================================= +# PERSONAL HELPERS +#================================================= #================================================= # EXPERIMENTAL HELPERS #================================================= -# INFOS -# n (Node version management) utilise la variable PATH pour stocker le path de la version de node à utiliser. -# C'est ainsi qu'il change de version -# ynh_install_nodejs installe la version de nodejs demandée en argument, avec n -# ynh_use_nodejs active une version de nodejs dans le script courant -# 3 variables sont mises à disposition, et 2 sont stockées dans la config de l'app -# - nodejs_path: Le chemin absolu de cette version de node -# Utilisé pour des appels directs à node. -# - nodejs_version: Simplement le numéro de version de nodejs pour cette application -# - nodejs_use_version: Un alias pour charger une version de node dans le shell courant. -# Utilisé pour démarrer un service ou un script qui utilise node ou npm -# Dans ce cas, c'est $PATH qui contient le chemin de la version de node. Il doit être propagé sur les autres shell si nécessaire. - -n_install_dir="/opt/node_n" -node_version_path="/opt/node_n/n/versions/node" -# N_PREFIX est le dossier de n, il doit être chargé dans les variables d'environnement pour n. -export N_PREFIX="$n_install_dir" - -ynh_install_n () { - echo "Installation of N - Node.js version management" >&2 - # Build an app.src for n - mkdir -p "../conf" - echo "SOURCE_URL=https://github.com/tj/n/archive/v2.1.7.tar.gz -SOURCE_SUM=2ba3c9d4dd3c7e38885b37e02337906a1ee91febe6d5c9159d89a9050f2eea8f" > "../conf/n.src" - # Download and extract n - ynh_setup_source "$n_install_dir/git" n - # Install n - (cd "$n_install_dir/git" - PREFIX=$N_PREFIX make install 2>&1) -} - -# ynh_use_nodejs () { -# nodejs_version=$(ynh_app_setting_get $app nodejs_version) -# -# load_n_path="[[ :$PATH: == *\":$n_install_dir/bin:\"* ]] || PATH=\"$n_install_dir/bin:$PATH\"; N_PREFIX="$n_install_dir"" -# -# nodejs_use_version="$n_install_dir/bin/n -q $nodejs_version" -# -# # "Load" a version of node -# eval $load_n_path; $nodejs_use_version -# -# # Get the absolute path of this version of node -# nodejs_path="$(n bin $nodejs_version)" -# -# # Make an alias for node use -# ynh_node_exec="eval $load_n_path; n use $nodejs_version" -# } - -ynh_install_nodejs () { - # Use n, https://github.com/tj/n to manage the nodejs versions - nodejs_version="$1" - - # Create $n_install_dir - mkdir -p "$n_install_dir" - - # Load n path in PATH - CLEAR_PATH="$n_install_dir/bin:$PATH" - # Remove /usr/local/bin in PATH in case of node has already setup. - PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') - - # Move an existing node binary, to avoid to block n. - test -x /usr/bin/node && mv /usr/bin/node /usr/bin/node_n - test -x /usr/bin/npm && mv /usr/bin/npm /usr/bin/npm_n - - # If n is not previously setup, install it - if ! test n --version > /dev/null 2>&1 - then - ynh_install_n - fi - - # Modify the default N_PREFIX in n script - ynh_replace_string "^N_PREFIX=\${N_PREFIX-.*}$" "N_PREFIX=\${N_PREFIX-$N_PREFIX}" "$n_install_dir/bin/n" - - # Restore /usr/local/bin in PATH - PATH=$CLEAR_PATH - - # And replace the old node binary. - test -x /usr/bin/node_n && mv /usr/bin/node_n /usr/bin/node - test -x /usr/bin/npm_n && mv /usr/bin/npm_n /usr/bin/npm - - # Install the requested version of nodejs - n $nodejs_version - - # Find the last "real" version for this major version of node. - real_nodejs_version=$(find $node_version_path/$nodejs_version* -maxdepth 0 | sort --version-sort | tail --lines=1) - real_nodejs_version=$(basename $real_nodejs_version) - - # Create a symbolic link for this major version. If the file doesn't already exist - if [ ! -e "$node_version_path/$nodejs_version" ] - then - ln --symbolic --force --no-target-directory $node_version_path/$real_nodejs_version $node_version_path/$nodejs_version - fi - - # Store the ID of this app and the version of node requested for it - echo "$YNH_APP_ID:$nodejs_version" | tee --append "$n_install_dir/ynh_app_version" - - # Store nodejs_version into the config of this app - ynh_app_setting_set $app nodejs_version $nodejs_version - - # Build the update script and set the cronjob - ynh_cron_upgrade_node - -# ynh_use_nodejs -} - -# print the path of node/npm binaries for a specific version of node -ynh_get_nodejs_bindir () { - nodejs_version="$1" - dirname $(/opt/node_n/bin/n bin $nodejs_version) -} - -ynh_remove_nodejs () { -# ynh_use_nodejs - - # Remove the line for this app - sed --in-place "/$YNH_APP_ID:$nodejs_version/d" "$n_install_dir/ynh_app_version" - - # If no another app uses this version of nodejs, remove it. - if ! grep --quiet "$nodejs_version" "$n_install_dir/ynh_app_version" - then - n rm $nodejs_version - fi - - # If no another app uses n, remove n - if [ ! -s "$n_install_dir/ynh_app_version" ] - then - ynh_secure_remove "$n_install_dir" - ynh_secure_remove "/usr/local/n" - sed --in-place "/N_PREFIX/d" /root/.bashrc - fi -} - -ynh_cron_upgrade_node () { - # Build the update script - cat > "$n_install_dir/node_update.sh" << EOF -#!/bin/bash - -version_path="$node_version_path" -n_install_dir="$n_install_dir" - -# Log the date -date - -# List all real installed version of node -all_real_version="\$(find \$version_path/* -maxdepth 0 -type d | sed "s@\$version_path/@@g")" - -# Keep only the major version number of each line -all_real_version=\$(echo "\$all_real_version" | sed 's/\..*\$//') - -# Remove double entries -all_real_version=\$(echo "\$all_real_version" | sort --unique) - -# Read each major version -while read version -do - echo "Update of the version \$version" - sudo \$n_install_dir/bin/n \$version - - # Find the last "real" version for this major version of node. - real_nodejs_version=\$(find \$version_path/\$version* -maxdepth 0 | sort --version-sort | tail --lines=1) - real_nodejs_version=\$(basename \$real_nodejs_version) - - # Update the symbolic link for this version - sudo ln --symbolic --force --no-target-directory \$version_path/\$real_nodejs_version \$version_path/\$version -done <<< "\$(echo "\$all_real_version")" -EOF - - chmod +x "$n_install_dir/node_update.sh" - - # Build the cronjob - cat > "/etc/cron.daily/node_update" << EOF -#!/bin/bash - -$n_install_dir/node_update.sh >> $n_install_dir/node_update.log -EOF - - chmod +x "/etc/cron.daily/node_update" -} - #================================================= - -# Start or restart a service and follow its booting -# -# usage: ynh_check_starting "Line to match" [Log file] [Timeout] [Service name] -# -# | arg: Line to match - The line to find in the log to attest the service have finished to boot. -# | arg: Log file - The log file to watch -# | arg: Service name -# /var/log/$app/$app.log will be used if no other log is defined. -# | arg: Timeout - The maximum time to wait before ending the watching. Defaut 300 seconds. -ynh_check_starting () { - local line_to_match="$1" - local service_name="${4:-$app}" - local app_log="${2:-/var/log/$service_name/$service_name.log}" - local timeout=${3:-300} - - ynh_clean_check_starting () { - # Stop the execution of tail. - kill -s 15 $pid_tail 2>&1 - ynh_secure_remove "$templog" 2>&1 - } - - echo "Starting of $service_name" >&2 - systemctl stop $service_name - local templog="$(mktemp)" - # Following the starting of the app in its log - tail -F -n0 "$app_log" > "$templog" & - # Get the PID of the tail command - local pid_tail=$! - systemctl start $service_name - - local i=0 - for i in `seq 1 $timeout` - do - # Read the log until the sentence is found, that means the app finished to start. Or run until the timeout - if grep --quiet "$line_to_match" "$templog" - then - echo "The service $service_name has correctly started." >&2 - break - fi - echo -n "." >&2 - sleep 1 - done - if [ $i -eq $timeout ] - then - echo "The service $service_name didn't fully started before the timeout." >&2 - fi - - echo "" - ynh_clean_check_starting -} - +# FUTURE OFFICIAL HELPERS #================================================= - -ynh_print_log () { - echo "${1}" -} - -# Print an info on stdout -# -# usage: ynh_print_info "Text to print" -# | arg: text - The text to print -ynh_print_info () { - ynh_print_log "[INFO] ${1}" -} - -# Print a error on stderr -# -# usage: ynh_print_err "Text to print" -# | arg: text - The text to print -ynh_print_err () { - ynh_print_log "[ERR] ${1}" >&2 -} - -# Remove any logs for all the following commands. -# -# usage: ynh_print_OFF -# WARNING: You should be careful with this helper, and never forgot to use ynh_print_ON as soon as possible to restore the logging. -ynh_print_OFF () { - set +x -} - -# Restore the logging after ynh_print_OFF -# -# usage: ynh_print_ON -ynh_print_ON () { - set -x - # Print an echo only for the log, to be able to know that ynh_print_ON has been called. - echo ynh_print_ON > /dev/null -} - -#================================================= - -# Create a dedicated fail2ban config (jail and filter conf files) -# -# usage: ynh_add_fail2ban_config log_file filter [max_retry [ports]] -# | arg: log_file - Log file to be checked by fail2ban -# | arg: failregex - Failregex to be looked for by fail2ban -# | arg: max_retry - Maximum number of retries allowed before banning IP address - default: 3 -# | arg: ports - Ports blocked for a banned IP address - default: http,https -ynh_add_fail2ban_config () { - # Process parameters - logpath=$1 - failregex=$2 - max_retry=${3:-3} - ports=${4:-http,https} - - test -n "$logpath" || ynh_die "ynh_add_fail2ban_config expects a logfile path as first argument and received nothing." - test -n "$failregex" || ynh_die "ynh_add_fail2ban_config expects a failure regex as second argument and received nothing." - - finalfail2banjailconf="/etc/fail2ban/jail.d/$app.conf" - finalfail2banfilterconf="/etc/fail2ban/filter.d/$app.conf" - ynh_backup_if_checksum_is_different "$finalfail2banjailconf" 1 - ynh_backup_if_checksum_is_different "$finalfail2banfilterconf" 1 - - sudo tee $finalfail2banjailconf <&2 - echo "WARNING${fail2ban_error#*WARNING}" >&2 - fi -} - -# Remove the dedicated fail2ban config (jail and filter conf files) -# -# usage: ynh_remove_fail2ban_config -ynh_remove_fail2ban_config () { - ynh_secure_remove "/etc/fail2ban/jail.d/$app.conf" - ynh_secure_remove "/etc/fail2ban/filter.d/$app.conf" - sudo systemctl restart fail2ban -} - -#================================================= - -# Read the value of a key in a ynh manifest file -# -# usage: ynh_read_manifest manifest key -# | arg: manifest - Path of the manifest to read -# | arg: key - Name of the key to find -ynh_read_manifest () { - manifest="$1" - key="$2" - python3 -c "import sys, json;print(json.load(open('$manifest'))['$key'])" -} - -# Exit without error if the package is up to date -# -# This helper should be used to avoid an upgrade of a package -# when it's not needed. -# -# To force an upgrade, even if the package is up to date, -# you have to set the variable YNH_FORCE_UPGRADE before. -# example: sudo YNH_FORCE_UPGRADE=1 yunohost app upgrade MyApp -# -# usage: ynh_abort_if_up_to_date -ynh_abort_if_up_to_date () { - local force_upgrade=${YNH_FORCE_UPGRADE:-0} - local package_check=${PACKAGE_CHECK_EXEC:-0} - - local version=$(ynh_read_manifest "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" "version" || echo 1.0) - local last_version=$(ynh_read_manifest "../manifest.json" "version" || echo 1.0) - if [ "$version" = "$last_version" ] - then - if [ "$force_upgrade" != "0" ] - then - echo "Upgrade forced by YNH_FORCE_UPGRADE." >&2 - unset YNH_FORCE_UPGRADE - elif [ "$package_check" != "0" ] - then - echo "Upgrade forced for package check." >&2 - else - ynh_die "Up-to-date, nothing to do" 0 - fi - fi -} - -#================================================= - -# Send an email to inform the administrator -# -# usage: ynh_send_readme_to_admin app_message [recipients] -# | arg: app_message - The message to send to the administrator. -# | arg: recipients - The recipients of this email. Use spaces to separate multiples recipients. - default: root -# example: "root admin@domain" -# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you -# example: "root admin@domain user1 user2" -ynh_send_readme_to_admin() { - local app_message="${1:-...No specific information...}" - local recipients="${2:-root}" - - # Retrieve the email of users - find_mails () { - local list_mails="$1" - local mail - local recipients=" " - # Read each mail in argument - for mail in $list_mails - do - # Keep root or a real email address as it is - if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@" - then - recipients="$recipients $mail" - else - # But replace an user name without a domain after by its email - if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null) - then - recipients="$recipients $mail" - fi - fi - done - echo "$recipients" - } - recipients=$(find_mails "$recipients") - - local mail_subject="☁️🆈🅽🅷☁️: \`$app\` was just installed!" - - local mail_message="This is an automated message from your beloved YunoHost server. - -Specific information for the application $app. - -$app_message - ---- -Automatic diagnosis data from YunoHost - -$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')" - - # Send the email to the recipients - echo "$mail_message" | mail -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients" -} - -#================================================= -#============= FUTURE YUNOHOST HELPER ============ -#================================================= - -# Delete a file checksum from the app settings -# -# $app should be defined when calling this helper -# -# usage: ynh_remove_file_checksum file -# | arg: file - The file for which the checksum will be deleted -ynh_delete_file_checksum () { - local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_' - ynh_app_setting_delete $app $checksum_setting_name -} diff --git a/scripts/_variables b/scripts/_variables deleted file mode 100644 index cb3494a..0000000 --- a/scripts/_variables +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -# Version of nodejs -nodejs_version=8 diff --git a/scripts/install b/scripts/install index ae64f6a..4ac84d7 100644 --- a/scripts/install +++ b/scripts/install @@ -8,17 +8,11 @@ source _common.sh source /usr/share/yunohost/helpers -# Load common variables for all scripts. -source _variables #================================================= # MANAGE FAILURE OF THE SCRIPT #================================================= -ynh_clean_setup () { -# Nettoyage des résidus d'installation non pris en charge par le script remove. - ynh_clean_check_starting -} ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée. #================================================= @@ -34,16 +28,14 @@ app=$YNH_APP_INSTANCE_NAME # CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS #================================================= +ynh_script_progression --message="Validating installation parameters..." + final_path=/var/www/$app -test ! -e "$final_path" || ynh_die "This path already contains a folder" +config_path=/home/yunohost.app/$app +test ! -e "$final_path" || ynh_die --message="This path already contains a folder" -# Normalize the url path syntax -path_url=$(ynh_normalize_url_path $path_url) - -# Check web path availability -ynh_webpath_available $domain $path_url # Register (book) web path -ynh_webpath_register $app $domain $path_url +ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST