diff --git a/README.md b/README.md index f733235..3da16bb 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,9 @@ Supported, with LDAP. #### Supported architectures -* x86-64b - [![Build Status](https://ci-apps.yunohost.org/jenkins/job/etherpad_mypads%20(Official)/badge/icon)](https://ci-apps.yunohost.org/jenkins/job/etherpad_mypads%20(Official)/) -* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/jenkins/job/etherpad_mypads%20(Official)%20(%7EARM%7E)/badge/icon)](https://ci-apps-arm.yunohost.org/jenkins/job/etherpad_mypads%20(Official)%20(%7EARM%7E)/) +* x86-64b - [![](https://ci-apps.yunohost.org/ci/logs/etherpad_mypads%20%28Official%29.svg)](https://ci-apps.yunohost.org/ci/apps/etherpad_mypads/) +* ARMv8-A - [![](https://ci-apps-arm.yunohost.org/ci/logs/etherpad_mypads%20%28Official%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/etherpad_mypads/) +* Jessie x86-64b - [![](https://ci-stretch.nohost.me/ci/logs/etherpad_mypads%20%28Official%29.svg)](https://ci-stretch.nohost.me/ci/apps/etherpad_mypads/) ## Limitations diff --git a/README_fr.md b/README_fr.md index b6b605c..d43108e 100644 --- a/README_fr.md +++ b/README_fr.md @@ -40,8 +40,9 @@ Supportée, avec LDAP. #### Architectures supportées. -* x86-64b - [![Build Status](https://ci-apps.yunohost.org/jenkins/job/etherpad_mypads%20(Official)/badge/icon)](https://ci-apps.yunohost.org/jenkins/job/etherpad_mypads%20(Official)/) -* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/jenkins/job/etherpad_mypads%20(Official)%20(%7EARM%7E)/badge/icon)](https://ci-apps-arm.yunohost.org/jenkins/job/etherpad_mypads%20(Official)%20(%7EARM%7E)/) +* x86-64b - [![](https://ci-apps.yunohost.org/ci/logs/etherpad_mypads%20%28Official%29.svg)](https://ci-apps.yunohost.org/ci/apps/etherpad_mypads/) +* ARMv8-A - [![](https://ci-apps-arm.yunohost.org/ci/logs/etherpad_mypads%20%28Official%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/etherpad_mypads/) +* Jessie x86-64b - [![](https://ci-stretch.nohost.me/ci/logs/etherpad_mypads%20%28Official%29.svg)](https://ci-stretch.nohost.me/ci/apps/etherpad_mypads/) ## Limitations diff --git a/scripts/_common.sh b/scripts/_common.sh index 44a54cc..48f5b48 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -23,146 +23,37 @@ CHECK_SIZE () { # Vérifie avant chaque backup que l'espace est suffisant } #================================================= -# EXPERIMENTAL HELPERS -#================================================= - -# 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; specify "systemd" to read systemd journal for specified service -# /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. -# | arg: Service name - -ynh_check_starting () { - local line_to_match="$1" - local app_log="${2:-/var/log/$service_name/$service_name.log}" - local timeout=${3:-300} - local service_name="${4:-$app}" - - echo "Starting of $service_name" >&2 - systemctl stop $service_name - local templog="$(mktemp)" - # Following the starting of the app in its log - if [ "$app_log" == "systemd" ] ; then - # Read the systemd journal - journalctl -u $service_name -f --since=-45 > "$templog" & - else - # Read the specified log file - tail -F -n0 "$app_log" > "$templog" & - fi - # Get the PID of the last 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, which means the app finished starting. 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 start before the timeout." >&2 - fi - - echo "" - ynh_clean_check_starting -} -# Clean temporary process and file used by ynh_check_starting -# (usually used in ynh_clean_setup scripts) -# -# usage: ynh_clean_check_starting - -ynh_clean_check_starting () { - # Stop the execution of tail. - kill -s 15 $pid_tail 2>&1 - ynh_secure_remove "$templog" 2>&1 -} - -#================================================= - -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 -} - -# Execute a command and force the result to be printed on stdout -# -# usage: ynh_exec_warn_less command to execute -# usage: ynh_exec_warn_less "command to execute | following command" -# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe. -# -# | arg: command - command to execute -ynh_exec_warn_less () { - eval $@ 2>&1 -} - -# 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 -} - +# FUTUR OFFICIAL HELPERS #================================================= # 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 +# | arg: -l, --logpath= - Log file to be checked by fail2ban +# | arg: -r, --failregex= - Failregex to be looked for by fail2ban +# | arg: -m, --max_retry= - Maximum number of retries allowed before banning IP address - default: 3 +# | arg: -p, --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 + ynh_store_file_checksum "$finalfail2banjailconf" + ynh_store_file_checksum "$finalfail2banfilterconf" + + if [ "$(lsb_release --codename --short)" != "jessie" ]; then + systemctl reload fail2ban + else + systemctl restart fail2ban + fi + local fail2ban_error="$(journalctl -u fail2ban | tail -n50 | grep "WARNING.*$app.*")" + if [ -n "$fail2ban_error" ] + then + echo "[ERR] Fail2ban failed to load the jail for $app" >&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" - systemctl restart fail2ban + ynh_secure_remove "/etc/fail2ban/jail.d/$app.conf" + ynh_secure_remove "/etc/fail2ban/filter.d/$app.conf" + if [ "$(lsb_release --codename --short)" != "jessie" ]; then + systemctl reload fail2ban + else + systemctl restart fail2ban + fi } #================================================= @@ -205,28 +104,39 @@ ynh_remove_fail2ban_config () { # 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 +# | arg: -m, --manifest= - Path of the manifest to read +# | arg: -k, --key= - Name of the key to find ynh_read_manifest () { - manifest="$1" - key="$2" - python3 -c "import sys, json;print(json.load(open('$manifest', encoding='utf-8'))['$key'])" + # Declare an array to define the options of this helper. + declare -Ar args_array=( [m]=manifest= [k]=manifest_key= ) + local manifest + local manifest_key + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + python3 -c "import sys, json;print(json.load(open('$manifest', encoding='utf-8'))['$manifest_key'])" } -# Read the upstream version from the manifest +# Read the upstream version from the manifest # The version number in the manifest is defined by ~ynh # For example : 4.3-2~ynh3 # This include the number before ~ynh # In the last example it return 4.3-2 # -# usage: ynh_app_upstream_version +# usage: ynh_app_upstream_version [-m manifest] +# | arg: -m, --manifest= - Path of the manifest to read ynh_app_upstream_version () { - manifest_path="../manifest.json" - if [ ! -e "$manifest_path" ]; then - manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place - fi - version_key=$(ynh_read_manifest "$manifest_path" "version") - echo "${version_key/~ynh*/}" + declare -Ar args_array=( [m]=manifest= ) + local manifest + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + manifest="${manifest:-../manifest.json}" + if [ ! -e "$manifest" ]; then + manifest="../settings/manifest.json" # Into the restore script, the manifest is not at the same place + fi + version_key=$(ynh_read_manifest --manifest="$manifest" --manifest_key="version") + echo "${version_key/~ynh*/}" } # Read package version from the manifest @@ -235,34 +145,50 @@ ynh_app_upstream_version () { # This include the number after ~ynh # In the last example it return 3 # -# usage: ynh_app_package_version +# usage: ynh_app_package_version [-m manifest] +# | arg: -m, --manifest= - Path of the manifest to read ynh_app_package_version () { - manifest_path="../manifest.json" - if [ ! -e "$manifest_path" ]; then - manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place - fi - version_key=$(ynh_read_manifest "$manifest_path" "version") - echo "${version_key/*~ynh/}" + declare -Ar args_array=( [m]=manifest= ) + local manifest + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + manifest="${manifest:-../manifest.json}" + if [ ! -e "$manifest" ]; then + manifest="../settings/manifest.json" # Into the restore script, the manifest is not at the same place + fi + version_key=$(ynh_read_manifest --manifest="$manifest" --manifest_key="version") + echo "${version_key/*~ynh/}" } -# Exit without error if the package is up to date +# Checks the app version to upgrade with the existing app version and returns: +# - UPGRADE_APP if the upstream app version has changed +# - UPGRADE_PACKAGE if only the YunoHost package has changed # -# This helper should be used to avoid an upgrade of a package -# when it's not needed. +## It stops the current script without error if the package is up-to-date +# +# This helper should be used to avoid an upgrade of an app, or the upstream part +# of it, 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 () { +# usage: ynh_check_app_version_changed +ynh_check_app_version_changed () { 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 + # By default, upstream app version has changed + local return_value="UPGRADE_APP" + + local current_version=$(ynh_read_manifest --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" --manifest_key="version" || echo 1.0) + local current_upstream_version="$(ynh_app_upstream_version --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json")" + local update_version=$(ynh_read_manifest --manifest="../manifest.json" --manifest_key="version" || echo 1.0) + local update_upstream_version="$(ynh_app_upstream_version)" + + if [ "$current_version" == "$update_version" ] ; then + # Complete versions are the same if [ "$force_upgrade" != "0" ] then echo "Upgrade forced by YNH_FORCE_UPGRADE." >&2 @@ -273,7 +199,122 @@ ynh_abort_if_up_to_date () { else ynh_die "Up-to-date, nothing to do" 0 fi + elif [ "$current_upstream_version" == "$update_upstream_version" ] ; then + # Upstream versions are the same, only YunoHost package versions differ + return_value="UPGRADE_PACKAGE" fi + echo $return_value +} + +#================================================= + +# Delete a file checksum from the app settings +# +# $app should be defined when calling this helper +# +# usage: ynh_remove_file_checksum file +# | arg: -f, --file= - The file for which the checksum will be deleted +ynh_delete_file_checksum () { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [f]=file= ) + local file + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + local checksum_setting_name=checksum_${file//[\/ ]/_} # Replace all '/' and ' ' by '_' + ynh_app_setting_delete $app $checksum_setting_name +} + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +# Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started +# +# usage: ynh_systemd_action [-n service_name] [-a action] [ [-l "line to match"] [-p log_path] [-t timeout] [-e length] ] +# | arg: -n, --service_name= - Name of the service to reload. Default : $app +# | arg: -a, --action= - Action to perform with systemctl. Default: start +# | arg: -l, --line_match= - Line to match - The line to find in the log to attest the service have finished to boot. +# If not defined it don't wait until the service is completely started. +# | arg: -p, --log_path= - Log file - Path to the log file. Default : /var/log/$app/$app.log +# | arg: -t, --timeout= - Timeout - The maximum time to wait before ending the watching. Default : 300 seconds. +# | arg: -e, --length= - Length of the error log : Default : 20 +ynh_systemd_action() { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [n]=service_name= [a]=action= [l]=line_match= [p]=log_path= [t]=timeout= [e]=length= ) + local service_name + local action + local line_match + local length + local log_path + local timeout + + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + local service_name="${service_name:-$app}" + local action=${action:-start} + local log_path="${log_path:-/var/log/$service_name/$service_name.log}" + local length=${length:-20} + local timeout=${timeout:-300} + + # Start to read the log + if [[ -n "${line_match:-}" ]] + then + local templog="$(mktemp)" + # Following the starting of the app in its log + if [ "$log_path" == "systemd" ] ; then + # Read the systemd journal + journalctl -u $service_name -f --since=-45 > "$templog" & + else + # Read the specified log file + tail -F -n0 "$log_path" > "$templog" & + fi + # Get the PID of the tail command + local pid_tail=$! + fi + + echo "${action^} the service $service_name" >&2 + systemctl $action $service_name \ + || ( journalctl --lines=$length -u $service_name >&2 \ + ; test -n "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2 \ + ; false ) + + # Start the timeout and try to find line_match + if [[ -n "${line_match:-}" ]] + then + 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_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 + journalctl --lines=$length -u $service_name >&2 + test -n "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2 + fi + + echo "" + ynh_clean_check_starting + fi +} + +# Clean temporary process and file used by ynh_check_starting +# (usually used in ynh_clean_setup scripts) +# +# usage: ynh_clean_check_starting +ynh_clean_check_starting () { + # Stop the execution of tail. + kill -s 15 $pid_tail 2>&1 + ynh_secure_remove "$templog" 2>&1 } #================================================= @@ -281,14 +322,20 @@ ynh_abort_if_up_to_date () { # 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 +# | arg: -m --app_message= - The message to send to the administrator. +# | arg: -r, --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}" + # Declare an array to define the options of this helper. + declare -Ar args_array=( [m]=app_message= [r]=recipients= ) + local app_message + local recipients + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + local app_message="${app_message:-...No specific information...}" + local recipients="${recipients:-root}" # Retrieve the email of users find_mails () { @@ -341,35 +388,15 @@ $(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')" #================================================= -# Reload (or other actions) a service and print a log in case of failure. -# -# usage: ynh_system_reload service_name [action] -# | arg: service_name - Name of the service to reload -# | arg: action - Action to perform with systemctl. Default: reload -ynh_system_reload () { - local service_name=$1 - local action=${2:-reload} - - # Reload, restart or start and print the log if the service fail to start or reload - systemctl $action $service_name || ( journalctl --lines=20 -u $service_name >&2 && false) -} - -#================================================= - -# 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 -} - -#================================================= - ynh_maintenance_mode_ON () { + # Load value of $path_url and $domain from the config if their not set + if [ -z $path_url ]; then + path_url=$(ynh_app_setting_get $app path) + fi + if [ -z $domain ]; then + domain=$(ynh_app_setting_get $app domain) + fi + # Create an html to serve as maintenance notice echo " @@ -416,6 +443,14 @@ include conf.d/yunohost_panel.conf.inc; } ynh_maintenance_mode_OFF () { + # Load value of $path_url and $domain from the config if their not set + if [ -z $path_url ]; then + path_url=$(ynh_app_setting_get $app path) + fi + if [ -z $domain ]; then + domain=$(ynh_app_setting_get $app domain) + fi + # Rewrite the nginx config file to redirect from ${path_url}_maintenance to the real url of the app. echo "rewrite ^${path_url}_maintenance/(.*)$ ${path_url}/\$1 redirect;" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" systemctl reload nginx diff --git a/scripts/backup b/scripts/backup index 311dfb4..9bd8e1e 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,12 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -if [ ! -e _common.sh ]; then - # Get the _common.sh file if it's not in the current directory - cp ../settings/scripts/_common.sh ./_common.sh - chmod a+rx _common.sh -fi -source _common.sh +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= diff --git a/scripts/change_url b/scripts/change_url index 3b4ec90..fc028f1 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -21,6 +21,11 @@ new_path=$YNH_APP_NEW_PATH app=$YNH_APP_INSTANCE_NAME +#================================================= +# LOAD SETTINGS +#================================================= + +final_path=$(ynh_app_setting_get $app final_path) mypads=$(ynh_app_setting_get $app mypads) #================================================= @@ -81,30 +86,15 @@ then # Make a backup of the original nginx config file if modified ynh_backup_if_checksum_is_different "$nginx_conf_path" - # Move from sub path to root - if [ "$new_path" == "/" ] - then - ynh_replace_string "^location $old_path/" "location $new_path" "$nginx_conf_path" - ynh_replace_string "^.*rewrite.*\^/" "#sub_path_only&" "$nginx_conf_path" - ynh_replace_string "^location ~\* $old_path/" "location ~* $new_path" "$nginx_conf_path" + # Set global variables for nginx helper + domain="$old_domain" + path_url="$new_path" - # Change the path in the two rewrite instructions - ynh_replace_string "\(rewrite *\^\)$old_path\$ $old_path/*" "\1$new_path$ $new_path" "$nginx_conf_path" - ynh_replace_string "\(rewrite *\^\)$old_path/*admin\$ $old_path/*" "\1${new_path}admin\$ $new_path" "$nginx_conf_path" + # Store path_url setting + ynh_app_setting_set $app path "$path_url" - # Move to a sub path - else - ynh_replace_string "^location $old_path.*" "location $new_path/ {" "$nginx_conf_path" - ynh_replace_string "^#sub_path_only" "" "$nginx_conf_path" - ynh_replace_string "^location ~\* $old_path/*" "location ~* $new_path/" "$nginx_conf_path" - - # Change the path in the two rewrite instructions - ynh_replace_string "\(rewrite *\^\)$old_path\$ $old_path/*" "\1$new_path$ $new_path/" "$nginx_conf_path" - ynh_replace_string "\(rewrite *\^\)$old_path/*admin\$ $old_path/*" "\1$new_path/admin\$ $new_path/" "$nginx_conf_path" - fi - - # Calculate and store the nginx config file checksum - ynh_store_file_checksum "$nginx_conf_path" + # Create a dedicated nginx config + ynh_add_nginx_config fi # Change the domain for nginx @@ -114,23 +104,22 @@ then ynh_delete_file_checksum "$nginx_conf_path" mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf - nginx_conf_path=/etc/nginx/conf.d/$new_domain.d/$app.conf - # Calculate and store the nginx config file checksum - ynh_store_file_checksum "$nginx_conf_path" + # Store file checksum for the new config file location + ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf" fi #================================================= # RELOAD NGINX #================================================= -ynh_system_reload nginx +ynh_systemd_action --action=reload --service_name=nginx #================================================= # CHECK ETHERPAD STARTING #================================================= # Wait for etherpad fully started -ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "120" +ynh_systemd_action --action=restart --line_match="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120" #================================================= # DEACTIVE MAINTENANCE MODE diff --git a/scripts/install b/scripts/install index 929c3af..9c6c1dd 100644 --- a/scripts/install +++ b/scripts/install @@ -54,8 +54,6 @@ test ! -e "$final_path" || ynh_die "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 @@ -73,12 +71,6 @@ ynh_app_setting_set $app export $export ynh_app_setting_set $app mypads $mypads ynh_app_setting_set $app useldap $useldap -#================================================= -# ACTIVATE MAINTENANCE MODE -#================================================= - -ynh_maintenance_mode_ON - #================================================= # STANDARD MODIFICATIONS #================================================= @@ -123,11 +115,6 @@ ynh_setup_source "$final_path" # Download, check integrity and uncompress the so # NGINX CONFIGURATION #================================================= -if [ "$path_url" != "/" ] -then - ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf" -fi -ynh_replace_string "__PATH__/" "${path_url%/}/" "../conf/nginx.conf" ynh_add_nginx_config #================================================= @@ -260,7 +247,7 @@ fi # SETUP FAIL2BAN #================================================= -ynh_add_fail2ban_config "/var/log/nginx/$domain-access.log" " .* \"POST /mypads/api/auth/login HTTP/1.1\" 400" 5 +ynh_add_fail2ban_config --logpath="/var/log/nginx/$domain-access.log" --failregex=" .* \"POST /mypads/api/auth/login HTTP/1.1\" 400" --max_retry=5 #================================================= # SETUP SSOWAT @@ -276,14 +263,14 @@ fi # RELOAD NGINX #================================================= -ynh_system_reload nginx +ynh_systemd_action --action=reload --service_name=nginx #================================================= # CHECK ETHERPAD STARTING #================================================= # Wait for etherpad to be fully started -ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "120" +ynh_systemd_action --action=restart --line_match="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120" if [ $mypads -eq 1 ] then @@ -291,7 +278,7 @@ then mysql -u $db_name -p$db_pwd $db_name < "../conf/lang_mypads.sql" # Wait for etherpad to be fully started - ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "120" + ynh_systemd_action --action=restart --line_match="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120" fi #================================================= diff --git a/scripts/restore b/scripts/restore index 56e3f83..577f2cf 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,12 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -if [ ! -e _common.sh ]; then - # Get the _common.sh file if it's not in the current directory - cp ../settings/scripts/_common.sh ./_common.sh - chmod a+rx _common.sh -fi -source _common.sh +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers # Load common variables for all scripts. source ../settings/scripts/_variables @@ -152,20 +147,20 @@ systemctl enable $app.service ynh_restore_file "/etc/fail2ban/jail.d/$app.conf" ynh_restore_file "/etc/fail2ban/filter.d/$app.conf" -ynh_system_reload fail2ban restart +ynh_systemd_action --action=restart --service_name=fail2ban #================================================= # RELOAD NGINX #================================================= -ynh_system_reload nginx +ynh_systemd_action --action=reload --service_name=nginx #================================================= # CHECK ETHERPAD STARTING #================================================= # Wait for etherpad to be fully started -ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "120" +ynh_systemd_action --action=restart --line_match="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120" #================================================= # DEACTIVE MAINTENANCE MODE diff --git a/scripts/upgrade b/scripts/upgrade index 7941647..3eb193d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -34,9 +34,9 @@ useldap=$(ynh_app_setting_get $app useldap) #================================================= # Wait for etherpad to be fully started -ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "120" +ynh_systemd_action --action=restart --line_match="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120" -ynh_abort_if_up_to_date +upgrade_type=$(ynh_check_app_version_changed) #================================================= # FIX OLD THINGS @@ -114,7 +114,7 @@ ynh_maintenance_mode_ON # STOP ETHERPAD #================================================= -ynh_system_reload $app stop +ynh_systemd_action --action=stop #================================================= # STANDARD UPGRADE STEPS @@ -122,17 +122,15 @@ ynh_system_reload $app stop # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_setup_source "$final_path" # Download, check integrity and uncompress the source from app.src +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_setup_source "$final_path" # Download, check integrity and uncompress the source from app.src +fi #================================================= # NGINX CONFIGURATION #================================================= -if [ "$path_url" != "/" ] -then - ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf" -fi -ynh_replace_string "__PATH__/" "${path_url%/}/" "../conf/nginx.conf" ynh_add_nginx_config #================================================= @@ -172,40 +170,43 @@ done <<< "$(ls -1 "$final_path/node_modules" | grep "^ep_")") # CONFIGURE ETHERPAD #================================================= -ynh_backup_if_checksum_is_different "$final_path/settings.json" # Verify the checksum and backup the file if it's different -ynh_backup_if_checksum_is_different "$final_path/credentials.json" # Verify the checksum and backup the file if it's different -cp ../conf/settings.json "$final_path/settings.json" -cp ../conf/credentials.json "$final_path/credentials.json" -ynh_replace_string "__PORT__" "$port" "$final_path/settings.json" -ynh_replace_string "__DB_USER__" "$app" "$final_path/credentials.json" -db_pwd=$(ynh_app_setting_get $app mysqlpwd) -ynh_print_OFF; password=$(ynh_app_setting_get $app password); ynh_print_ON -ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/credentials.json" -ynh_replace_string "__ADMIN__" "$admin" "$final_path/credentials.json" -ynh_print_OFF; ynh_replace_special_string "__PASSWD__" "$password" "$final_path/credentials.json"; ynh_print_ON -if [ "$export" = "abiword" ] +if [ "$upgrade_type" == "UPGRADE_APP" ] then - abiword_path=`which abiword` # Get abiword binary path - ynh_replace_string "\"abiword\" : null" "\"abiword\" : \"$abiword_path\"" "$final_path/settings.json" # Renseigne l'emplacement de abiword dans la config de etherpad -elif [ "$export" = "libreoffice" ] -then - soffice_path=`which soffice` # Get soffice binary path - ynh_replace_string "\"soffice\" : null" "\"soffice\" : \"$soffice_path\"" "$final_path/settings.json" # Renseigne l'emplacement de abiword dans la config de etherpad -fi -if test -z $language; then - language=en # If upgrading from a version which doesn't support translations, set language to English by default - ynh_app_setting_set $app language $language -fi -ynh_replace_string "__LANGUAGE__" "$language" "$final_path/settings.json" + ynh_backup_if_checksum_is_different "$final_path/settings.json" # Verify the checksum and backup the file if it's different + ynh_backup_if_checksum_is_different "$final_path/credentials.json" # Verify the checksum and backup the file if it's different + cp ../conf/settings.json "$final_path/settings.json" + cp ../conf/credentials.json "$final_path/credentials.json" + ynh_replace_string "__PORT__" "$port" "$final_path/settings.json" + ynh_replace_string "__DB_USER__" "$app" "$final_path/credentials.json" + db_pwd=$(ynh_app_setting_get $app mysqlpwd) + ynh_print_OFF; password=$(ynh_app_setting_get $app password); ynh_print_ON + ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/credentials.json" + ynh_replace_string "__ADMIN__" "$admin" "$final_path/credentials.json" + ynh_print_OFF; ynh_replace_special_string "__PASSWD__" "$password" "$final_path/credentials.json"; ynh_print_ON + if [ "$export" = "abiword" ] + then + abiword_path=`which abiword` # Get abiword binary path + ynh_replace_string "\"abiword\" : null" "\"abiword\" : \"$abiword_path\"" "$final_path/settings.json" # Renseigne l'emplacement de abiword dans la config de etherpad + elif [ "$export" = "libreoffice" ] + then + soffice_path=`which soffice` # Get soffice binary path + ynh_replace_string "\"soffice\" : null" "\"soffice\" : \"$soffice_path\"" "$final_path/settings.json" # Renseigne l'emplacement de abiword dans la config de etherpad + fi + if test -z $language; then + language=en # If upgrading from a version which doesn't support translations, set language to English by default + ynh_app_setting_set $app language $language + fi + ynh_replace_string "__LANGUAGE__" "$language" "$final_path/settings.json" -# Use ldap for mypads -if [ $mypads -eq 1 ] && [ $useldap -eq 1 ] -then - ynh_replace_string "//noldap" "" "$final_path/settings.json" -fi + # Use ldap for mypads + if [ $mypads -eq 1 ] && [ $useldap -eq 1 ] + then + ynh_replace_string "//noldap" "" "$final_path/settings.json" + fi -ynh_store_file_checksum "$final_path/settings.json" # Recalculate and store the config file checksum into the app settings -ynh_store_file_checksum "$final_path/credentials.json" # Recalculate and store the config file checksum into the app settings + ynh_store_file_checksum "$final_path/settings.json" # Recalculate and store the config file checksum into the app settings + ynh_store_file_checksum "$final_path/credentials.json" # Recalculate and store the config file checksum into the app settings +fi #================================================= # CREATE DEDICATED USER @@ -226,7 +227,7 @@ chown $app -R /var/log/$app/etherpad.log # UPGRADE FAIL2BAN #================================================= -ynh_add_fail2ban_config "/var/log/nginx/$domain-access.log" " .* \"POST /mypads/api/auth/login HTTP/1.1\" 400" 5 +ynh_add_fail2ban_config --logpath="/var/log/nginx/$domain-access.log" --failregex=" .* \"POST /mypads/api/auth/login HTTP/1.1\" 400" --max_retry=5 #================================================= # SETUP LOGROTATE @@ -266,14 +267,14 @@ fi # RELOAD NGINX #================================================= -ynh_system_reload nginx +ynh_systemd_action --action=reload --service_name=nginx #================================================= # CHECK ETHERPAD STARTING #================================================= # Wait for etherpad to be fully started -ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "120" +ynh_systemd_action --action=restart --line_match="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120" #================================================= # DEACTIVE MAINTENANCE MODE