From b67fafcf08846349ee4da5480945c83c4770cccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Tue, 17 Nov 2020 23:33:50 +0100 Subject: [PATCH] Fix package linter --- check_process | 12 ---- scripts/backup | 8 +-- scripts/change_url | 8 +-- scripts/experimental_helper.sh | 115 --------------------------------- scripts/install | 8 +-- scripts/remove | 6 +- scripts/restore | 8 +-- scripts/upgrade | 14 ++-- 8 files changed, 28 insertions(+), 151 deletions(-) diff --git a/check_process b/check_process index 500f843..7206f2b 100644 --- a/check_process +++ b/check_process @@ -19,18 +19,6 @@ incorrect_path=0 port_already_use=1 (6000) change_url=1 -;;; Levels - Level 1=auto - Level 2=auto - Level 3=auto - # https://github.com/YunoHost-Apps/gitea_ynh/blob/master/conf/login_source.sql - Level 4=1 - Level 5=auto - Level 6=auto - Level 7=auto - Level 8=0 - Level 9=0 - Level 10=0 ;;; Upgrade options ; commit=349992d4f3921e4e1adb37a0cace4a5a9eb67099 name=First package version diff --git a/scripts/backup b/scripts/backup index fa8c8ce..26e6b0f 100644 --- a/scripts/backup +++ b/scripts/backup @@ -4,16 +4,16 @@ # GENERIC START #================================================= +# Load common variables and helpers +source ../settings/scripts/experimental_helper.sh +source ../settings/scripts/_common.sh + # IMPORT GENERIC HELPERS source /usr/share/yunohost/helpers # Exit if an error occurs during the execution of the script ynh_abort_if_errors -# Load common variables and helpers -source ../settings/scripts/experimental_helper.sh -source ../settings/scripts/_common.sh - # Retrieve app settings ynh_script_progression --message="Loading installation settings..." domain=$(ynh_app_setting_get --app $app --key domain) diff --git a/scripts/change_url b/scripts/change_url index de3079f..e5efd6e 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -4,16 +4,16 @@ # GENERIC START #================================================= +# Import common cmd +source ./experimental_helper.sh +source ./_common.sh + # IMPORT GENERIC HELPERS source /usr/share/yunohost/helpers # Exit if an error occurs during the execution of the script ynh_abort_if_errors -# Import common cmd -source ./experimental_helper.sh -source ./_common.sh - ynh_script_progression --message="Loading installation settings..." # RETRIEVE ARGUMENTS diff --git a/scripts/experimental_helper.sh b/scripts/experimental_helper.sh index 23d0e32..8757149 100644 --- a/scripts/experimental_helper.sh +++ b/scripts/experimental_helper.sh @@ -1,82 +1,3 @@ -# 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 --unit=$service_name --follow --since=-0 --quiet > "$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 -e "$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 - echo "Please find here an extract of the end of the log of the service $service_name:" - journalctl --lines=$length -u $service_name >&2 - test -e "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2 - fi - - echo "" - ynh_clean_check_starting - fi -} - # Execute a command as another user # usage: exec_as USER COMMAND [ARG ...] exec_as() { @@ -334,39 +255,3 @@ ynh_handle_app_migration () { migration_process=1 fi } - -# Verify the checksum and backup the file if it's different -# This helper is primarily meant to allow to easily backup personalised/manually -# modified config files. -# -# $app should be defined when calling this helper -# -# usage: ynh_backup_if_checksum_is_different --file=file -# | arg: -f, --file - The file on which the checksum test will be perfomed. -# | ret: the name of a backup file, or nothing -# -# Requires YunoHost version 2.6.4 or higher. -ynh_backup_if_checksum_is_different () { - # Declare an array to define the options of this helper. - local legacy_args=f - 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 '_' - local checksum_value=$(ynh_app_setting_get --app=$app --key=$checksum_setting_name) - # backup_file_checksum isn't declare as local, so it can be reuse by ynh_store_file_checksum - backup_file_checksum="" - if [ -n "$checksum_value" ] - then # Proceed only if a value was stored into the app settings - if [ -e $file ] && ! echo "$checksum_value $file" | sudo md5sum -c --status - then # If the checksum is now different - backup_file_checksum="/home/yunohost.conf/backup/$file.backup.$(date '+%Y%m%d.%H%M%S')" - sudo mkdir -p "$(dirname "$backup_file_checksum")" - sudo cp -a "$file" "$backup_file_checksum" # Backup the current file - ynh_print_warn "File $file has been manually modified since the installation or last upgrade. So it has been duplicated in $backup_file_checksum" - echo "$backup_file_checksum" # Return the name of the backup file - fi - fi -} diff --git a/scripts/install b/scripts/install index f5687ad..542c639 100644 --- a/scripts/install +++ b/scripts/install @@ -4,16 +4,16 @@ # GENERIC START #================================================= +# Load common variables and helpers +source ./experimental_helper.sh +source ./_common.sh + # IMPORT GENERIC HELPERS source /usr/share/yunohost/helpers # Exit if an error occurs during the execution of the script ynh_abort_if_errors -# Load common variables and helpers -source ./experimental_helper.sh -source ./_common.sh - ynh_script_progression --message="Validating installation parameters..." # Retrieve arguments diff --git a/scripts/remove b/scripts/remove index e1c51a7..28ae1e0 100644 --- a/scripts/remove +++ b/scripts/remove @@ -4,13 +4,13 @@ # GENERIC START #================================================= -# IMPORT GENERIC HELPERS -source /usr/share/yunohost/helpers - # Load common variables and helpers source ./experimental_helper.sh source ./_common.sh +# IMPORT GENERIC HELPERS +source /usr/share/yunohost/helpers + ynh_script_progression --message="Loading installation settings..." # Retrieve domain from app settings diff --git a/scripts/restore b/scripts/restore index 49ab3e8..12f2c5c 100644 --- a/scripts/restore +++ b/scripts/restore @@ -4,16 +4,16 @@ # GENERIC START #================================================= +# Load common variables and helpers +source ../settings/scripts/experimental_helper.sh +source ../settings/scripts/_common.sh + # IMPORT GENERIC HELPERS source /usr/share/yunohost/helpers # Exit if an error occurs during the execution of the script ynh_abort_if_errors -# Load common variables and helpers -source ../settings/scripts/experimental_helper.sh -source ../settings/scripts/_common.sh - ynh_script_progression --message="Loading settings..." # Retrieve old app settings diff --git a/scripts/upgrade b/scripts/upgrade index 3a83dbc..89cd63f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -4,16 +4,16 @@ # GENERIC START #================================================= +# Load common variables and helpers +source ./experimental_helper.sh +source ./_common.sh + # IMPORT GENERIC HELPERS source /usr/share/yunohost/helpers # Exit if an error occurs during the execution of the script ynh_abort_if_errors -# Load common variables and helpers -source ./experimental_helper.sh -source ./_common.sh - # Retrieve app settings ynh_script_progression --message="Loading installation settings..." domain=$(ynh_app_setting_get --app $app --key domain) @@ -43,7 +43,7 @@ systemctl stop "$app".service [[ $YNH_APP_ID == "gogs" ]] \ && [[ "$(cat "/opt/$app/templates/.VERSION")" != 0.11.79.1211 ]] \ && ynh_die --message "It look like that you have an old gogs install. You need first upgrade gogs instance (id : $gogs_migrate_id) and after migrate to gitea." -ynh_handle_app_migration gogs gogs_migrations +ynh_handle_app_migration --migration_id=gogs --migration_list=gogs_migrations if [[ $migration_process -eq 1 ]]; then # Reload variables @@ -206,6 +206,10 @@ then ynh_permission_update --permission "main" --add "visitors" fi +# Add gitea to YunoHost's monitored services +ynh_script_progression --message="Register gitea service..." +yunohost service add "$app" --log "/var/log/$app/gitea.log" + # Set permissions ynh_script_progression --message="Protecting directory" set_permission