From c964ac3b9ff8ce66c3c698521d84d33e441e91de Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Wed, 30 Jan 2019 16:21:42 +0100 Subject: [PATCH 1/4] Add progression bar --- scripts/_common.sh | 78 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/install | 13 +++++++- scripts/remove | 6 +++- scripts/upgrade | 9 ++++++ 4 files changed, 104 insertions(+), 2 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index caf8bc7..278d8c7 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -629,6 +629,84 @@ ynh_clean_check_starting () { #================================================= +# Print a message as INFO and show progression during an app script +# +# usage: ynh_script_progression --message=message [--weight=weight] [--time] +# | arg: -m, --message= - The text to print +# | arg: -w, --weight= - The weight for this progression. This value is 1 by default. Use a bigger value for a longer part of the script. +# | arg: -t, --time= - Print the execution time since the last call to this helper. Especially usefull to define weights. +# | arg: -l, --last= - Use for the last call of the helper, to fill te progression bar. +increment_progression=0 +previous_weight=0 +# Define base_time when the file is sourced +base_time=$(date +%s) +ynh_script_progression () { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [m]=message= [w]=weight= [t]=time [l]=last ) + local message + local weight + local time + local last + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + weight=${weight:-1} + time=${time:-0} + last=${last:-0} + + # Get execution time since the last $base_time + local exec_time=$(( $(date +%s) - $base_time )) + base_time=$(date +%s) + + # Get the number of occurrences of 'ynh_script_progression' in the script. Except those are commented. + local helper_calls="$(grep --count "^[^#]*ynh_script_progression" $0)" + # Get the number of call with a weight value + local weight_calls=$(grep --perl-regexp --count "^[^#]*ynh_script_progression.*(--weight|-w )" $0) + + # Get the weight of each occurrences of 'ynh_script_progression' in the script using --weight + local weight_valuesA="$(grep --perl-regexp "^[^#]*ynh_script_progression.*--weight" $0 | sed 's/.*--weight[= ]\([[:digit:]].*\)/\1/g')" + # Get the weight of each occurrences of 'ynh_script_progression' in the script using -w + local weight_valuesB="$(grep --perl-regexp "^[^#]*ynh_script_progression.*-w " $0 | sed 's/.*-w[= ]\([[:digit:]].*\)/\1/g')" + # Each value will be on a different line. + # Remove each 'end of line' and replace it by a '+' to sum the values. + local weight_values=$(( $(echo "$weight_valuesA" | tr '\n' '+') + $(echo "$weight_valuesB" | tr '\n' '+') 0 )) + + # max_progression is a total number of calls to this helper. + # Less the number of calls with a weight value. + # Plus the total of weight values + local max_progression=$(( $helper_calls - $weight_calls + $weight_values )) + + # Increment each execution of ynh_script_progression in this script by the weight of the previous call. + increment_progression=$(( $increment_progression + $previous_weight )) + # Store the weight of the current call in $previous_weight for next call + previous_weight=$weight + + # Set the scale of the progression bar + local scale=20 + # progress_string(1,2) should have the size of the scale. + local progress_string1="####################" + local progress_string0="...................." + + # Reduce $increment_progression to the size of the scale + if [ $last -eq 0 ] + then + local effective_progression=$(( $increment_progression * $scale / $max_progression )) + # If last is specified, fill immediately the progression_bar + else + local effective_progression=$scale + fi + + # Build $progression_bar from progress_string(1,2) according to $effective_progression + local progression_bar="${progress_string1:0:$effective_progression}${progress_string0:0:$(( $scale - $effective_progression ))}" + + local print_exec_time="" + if [ $time -eq 1 ] + then + print_exec_time=" [$(date +%Hh%Mm,%Ss --date="0 + $exec_time sec")]" + fi + + ynh_print_info "[$progression_bar] > ${message}${print_exec_time}" +} + # Send an email to inform the administrator # # usage: ynh_send_readme_to_admin --app_message=app_message [--recipients=recipients] [--type=type] diff --git a/scripts/install b/scripts/install index a359dde..e8e7818 100755 --- a/scripts/install +++ b/scripts/install @@ -19,6 +19,7 @@ ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= +ynh_script_progression --message="Retrieve arguments from the manifest" --weight=2 ssh_user=$YNH_APP_ARG_SSH_USER # Default value is null @@ -40,6 +41,7 @@ fi #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= +ynh_script_progression --message="Check if the app can be installed" --weight=2 # Correct user name # An unix user name can contains only :alnum: and . - _ @@ -61,6 +63,7 @@ ynh_print_ON #================================================= # STORE SETTINGS FROM MANIFEST #================================================= +ynh_script_progression --message="Store settings from manifest" ynh_app_setting_set $app ssh_user $ssh_user ynh_app_setting_set $app size $size @@ -70,6 +73,7 @@ ynh_app_setting_set $app size $size #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Download, check and unpack source" --weight=2 ynh_app_setting_set $app final_path $final_path # Download, check integrity, uncompress and patch the source from app.src @@ -94,6 +98,7 @@ mkdir -p "$user_dir" #================================================= # INSTALL QUOTAS SYSTEM #================================================= +ynh_script_progression --message="Install quotas system" --weight=3 # https://github.com/maniackcrudelis/ssh_chroot/blob/master/unix_quotas/unix_quotas.sh quotas_install @@ -101,6 +106,7 @@ quotas_install #================================================= # CONFIGURE FSTAB TO SUPPORT QUOTAS #================================================= +ynh_script_progression --message="Configure fstab to support quotas" --weight=3 # https://github.com/maniackcrudelis/ssh_chroot/blob/master/unix_quotas/unix_quotas.sh # Set fstab @@ -113,6 +119,7 @@ quotas_activate "$quotas_mount_point" #================================================= # CREATE THE USER WITH CHROOT_MANAGER #================================================= +ynh_script_progression --message="Create the user with Chroot_manager" --weight=5 add_password="" ynh_print_OFF @@ -175,4 +182,8 @@ message="A new chrooted directory has been created. To use it, connect to 'ssh $ If you're facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh" -ynh_send_readme_to_admin --app_message="$message" --recipients="root" +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Installation completed" --last diff --git a/scripts/remove b/scripts/remove index a533781..670c3f6 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Load settings" app=$YNH_APP_INSTANCE_NAME @@ -30,6 +31,7 @@ source "$final_path/unix_quotas/unix_quotas.sh" #================================================= # REMOVE QUOTAS OPTIONS IN FSTAB #================================================= +ynh_script_progression --message="Remove quotas options in fstab" --weight=3 user_dir="/home/yunohost.app/ssh_chroot_directories/$ssh_user" @@ -43,6 +45,7 @@ quotas_deactivate "$quotas_mount_point" #================================================= # REMOVE THE USER WITH CHROOT_MANAGER #================================================= +ynh_script_progression --message="Remove the user with Chroot_manager" --weight=3 $final_path/chroot_manager.sh deluser --name $ssh_user @@ -51,6 +54,7 @@ $final_path/chroot_manager.sh deluser --name $ssh_user #================================================= # REMOVE APP MAIN DIR #================================================= +ynh_script_progression --message="Remove app main directory" # Remove the app directory securely ynh_secure_remove "$final_path" @@ -60,4 +64,4 @@ ynh_secure_remove "$final_path" #================================================= ynh_print_info " -The directory /home/yunohost.app/ssh_chroot_directories hasn't been removed." >&2 +The directory /home/yunohost.app/ssh_chroot_directories hasn't been removed." diff --git a/scripts/upgrade b/scripts/upgrade index c25b15d..b1a6775 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -19,6 +19,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Load settings" app=$YNH_APP_INSTANCE_NAME @@ -39,6 +40,7 @@ upgrade_type=$(ynh_check_app_version_changed) if [ "$upgrade_type" == "UPGRADE_APP" ] then + ynh_script_progression --message="Download, check and unpack source" --weight=2 # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source "$final_path" fi @@ -55,6 +57,7 @@ source "$final_path/ssh_chroot/ssh_chroot.sh" #================================================= # UPDATE THE CHROOT DIRECTORY #================================================= +ynh_script_progression --message="Update the chroot directory" --weight=3 user_dir="/home/yunohost.app/ssh_chroot_directories/$ssh_user" @@ -83,3 +86,9 @@ ln -sf $final_path/chroot_manager.sh /home/yunohost.app/ssh_chroot_directories/c # Set permissions to app files chown -R root: $final_path + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Upgrade completed" --last From 08c4f7cdc90558bb3dd777d104a31a5fa757a641 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Wed, 30 Jan 2019 19:35:16 +0100 Subject: [PATCH 2/4] Changelog & html email --- scripts/_common.sh | 125 +++++++++++++++++++++++++++++++++++++++++++-- scripts/install | 6 ++- scripts/upgrade | 16 ++++++ 3 files changed, 140 insertions(+), 7 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 278d8c7..e1d5b28 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -710,7 +710,7 @@ ynh_script_progression () { # Send an email to inform the administrator # # usage: ynh_send_readme_to_admin --app_message=app_message [--recipients=recipients] [--type=type] -# | arg: -m --app_message= - The message to send to the administrator. +# | arg: -m --app_message= - The file with the content 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 @@ -723,11 +723,16 @@ ynh_send_readme_to_admin() { local recipients local type # Manage arguments with getopts + ynh_handle_getopts_args "$@" - app_message="${app_message:-...No specific information...}" + app_message="${app_message:-}" recipients="${recipients:-root}" type="${type:-install}" + # Get the value of admin_mail_html + admin_mail_html=$(ynh_app_setting_get $app admin_mail_html) + admin_mail_html="${admin_mail_html:-0}" + # Retrieve the email of users find_mails () { local list_mails="$1" @@ -774,12 +779,53 @@ ynh_send_readme_to_admin() { Specific information for the application $app. -$app_message +$(if [ -n "$app_message" ] +then + cat "$app_message" +else + echo "...No specific information..." +fi) --- Automatic diagnosis data from YunoHost -$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')" +__PRE_TAG1__$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')__PRE_TAG2__" + + # Store the message into a file for further modifications. + echo "$mail_message" > mail_to_send + + # If a html email is required. Apply html tags to the message. + if [ "$admin_mail_html" -eq 1 ] + then + # Insert 'br' tags at each ending of lines. + ynh_replace_string "$" "
" mail_to_send + + # Insert starting HTML tags + sed --in-place '1s@^@\n\n\n\n@' mail_to_send + + # Keep tabulations + ynh_replace_string " " "\ \ " mail_to_send + ynh_replace_string "\t" "\ \ " mail_to_send + + # Insert url links tags + ynh_replace_string "__URL_TAG1__\(.*\)__URL_TAG2__\(.*\)__URL_TAG3__" "\1" mail_to_send + + # Insert pre tags + ynh_replace_string "__PRE_TAG1__" "
" mail_to_send
+		ynh_replace_string "__PRE_TAG2__" "<\pre>" mail_to_send
+
+		# Insert finishing HTML tags
+		echo -e "\n\n" >> mail_to_send
+
+	# Otherwise, remove tags to keep a plain text.
+	else
+		# Remove URL tags
+		ynh_replace_string "__URL_TAG[1,3]__" "" mail_to_send
+		ynh_replace_string "__URL_TAG2__" ": " mail_to_send
+
+		# Remove PRE tags
+		ynh_replace_string "__PRE_TAG[1-2]__" "" mail_to_send
+	fi
 
 	# Define binary to use for mail command
 	if [ -e /usr/bin/bsd-mailx ]
@@ -789,8 +835,15 @@ $(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')"
 		local mail_bin=/usr/bin/mail.mailutils
 	fi
 
+	if [ "$admin_mail_html" -eq 1 ]
+	then
+		content_type="text/html"
+	else
+		content_type="text/plain"
+	fi
+
 	# Send the email to the recipients
-	echo "$mail_message" | $mail_bin -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients"
+	cat mail_to_send | $mail_bin -a "Content-Type: $content_type; charset=UTF-8" -s "$mail_subject" "$recipients"
 }
 
 #=================================================
@@ -961,3 +1014,65 @@ ynh_download_file () {
 	# Move the file to its destination
 	mv $filename $dest_dir
 }
+
+#=================================================
+
+# Create a changelog for an app after an upgrade.
+#
+# The changelog is printed into the file ./changelog for the time of the upgrade.
+#
+# In order to create a changelog, ynh_app_changelog will get info from /etc/yunohost/apps/$app/status.json
+# In order to find the current commit use by the app.
+# The remote repository, and the branch.
+# The changelog will be only the commits since the current revision.
+#
+# Because of the need of those info, ynh_app_changelog works only
+# with apps that have been installed from a list.
+#
+# usage: ynh_app_changelog
+ynh_app_changelog () {
+	get_value_from_settings ()
+	{
+		local value="$1"
+		# Extract a value from the status.json file of an installed app.
+
+		grep "$value\": \"" /etc/yunohost/apps/$app/status.json | sed "s/.*$value\": \"\([^\"]*\).*/\1/"
+	}
+
+	local current_revision="$(get_value_from_settings revision)"
+	local repo="$(get_value_from_settings url)"
+	local branch="$(get_value_from_settings branch)"
+	# ynh_app_changelog works only with an app installed from a list.
+	if [ -z "$current_revision" ] || [ -z "$repo" ] || [ -z "$branch" ]
+	then
+		ynh_print_warn "Unable to build the changelog..."
+		touch changelog
+		return 0
+	fi
+
+	# Fetch the history of the repository, without cloning it
+	mkdir git_history
+	(cd git_history
+	ynh_exec_warn_less git init
+	ynh_exec_warn_less git remote add -f origin $repo
+	# Get the line of the current commit of the installed app in the history.
+	local line_to_head=$(git log origin/$branch --pretty=oneline | grep --line-number "$current_revision" | cut -d':' -f1)
+	# Cut the history before the current commit, to keep only newer commits.
+	# Then use sed to reorganise each lines and have a nice list of commits since the last upgrade.
+	# This list is redirected into the file changelog
+	git log origin/$branch --pretty=oneline | head --lines=$(($line_to_head-1)) | sed 's/^\([[:alnum:]]*\)\(.*\)/*(\1) -> \2/g' > ../changelog)
+	# Remove 'Merge pull request' commits
+	sed -i '/Merge pull request #[[:digit:]]* from/d' changelog
+	# As well as conflict resolving commits
+	sed -i '/Merge branch .* into/d' changelog
+
+	# Get the value of admin_mail_html
+	admin_mail_html=$(ynh_app_setting_get $app admin_mail_html)
+	admin_mail_html="${admin_mail_html:-0}"
+
+	# If a html email is required. Apply html to the changelog.
+ 	if [ "$admin_mail_html" -eq 1 ]
+ 	then
+		sed -in-place "s@\*(\([[:alnum:]]*\)) -> \(.*\)@* __URL_TAG1__\2__URL_TAG2__${repo}/commit/\1__URL_TAG3__@g" changelog
+ 	fi
+}
diff --git a/scripts/install b/scripts/install
index e8e7818..b4cef76 100755
--- a/scripts/install
+++ b/scripts/install
@@ -178,9 +178,11 @@ fi
 # SEND A README FOR THE ADMIN
 #=================================================
 
-message="A new chrooted directory has been created. To use it, connect to 'ssh $ssh_user@$domain -p $ssh_port' via a terminal or by using an sftp connection with 'sftp://$ssh_user@$domain:$ssh_port/data'
+echo "A new chrooted directory has been created. To use it, connect to 'ssh $ssh_user@$domain -p $ssh_port' via a terminal or by using an sftp connection with 'sftp://$ssh_user@$domain:$ssh_port/data'
 
-If you're facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh"
+If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh__URL_TAG3__." > mail_to_send
+
+ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root"
 
 #=================================================
 # END OF SCRIPT
diff --git a/scripts/upgrade b/scripts/upgrade
index b1a6775..a683898 100755
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -87,6 +87,22 @@ ln -sf $final_path/chroot_manager.sh /home/yunohost.app/ssh_chroot_directories/c
 # Set permissions to app files
 chown -R root: $final_path
 
+#=================================================
+# SEND A README FOR THE ADMIN
+#=================================================
+
+# Build the changelog
+ynh_app_changelog || true
+
+echo "If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh__URL_TAG3__.
+
+---
+
+Changelog since your last upgrade:
+$(cat changelog)" > mail_to_send
+
+ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type="upgrade"
+
 #=================================================
 # END OF SCRIPT
 #=================================================

From bb3f5657a2a7c95bbb27c549a1013416a4ab1ff0 Mon Sep 17 00:00:00 2001
From: Maniack Crudelis 
Date: Wed, 30 Jan 2019 20:00:45 +0100
Subject: [PATCH 3/4] Require ynh 3.4

---
 manifest.json      |   4 +-
 scripts/_common.sh | 229 +--------------------------------------------
 2 files changed, 6 insertions(+), 227 deletions(-)

diff --git a/manifest.json b/manifest.json
index f663d73..c0292a7 100644
--- a/manifest.json
+++ b/manifest.json
@@ -6,7 +6,7 @@
 		"en": "ssh chroot directories with quotas disk.",
 		"fr": "Dossier ssh en chroot avec gestion de quotas."
 	},
-	"version": "1.2~ynh3",
+	"version": "1.2~ynh4",
 	"url": "https://github.com/maniackcrudelis/ssh_chroot",
 	"license": "GPL-3.0",
 	"maintainer": {
@@ -14,7 +14,7 @@
 		"email": "maniackc_dev@crudelis.fr"
 	},
 	"requirements": {
-		"yunohost": ">= 3.3.3"
+		"yunohost": ">= 3.4"
 	},
 	"multi_instance": true,
 	"services": [],
diff --git a/scripts/_common.sh b/scripts/_common.sh
index e1d5b28..e74bc0f 100644
--- a/scripts/_common.sh
+++ b/scripts/_common.sh
@@ -52,210 +52,6 @@ bool_to_true_false () {
 # FUTUR OFFICIAL HELPERS
 #=================================================
 
-# Internal helper design to allow helpers to use getopts to manage their arguments
-#
-# [internal]
-#
-# example: function my_helper()
-# {
-#     declare -Ar args_array=( [a]=arg1= [b]=arg2= [c]=arg3 )
-#     local arg1
-#     local arg2
-#     local arg3
-#     ynh_handle_getopts_args "$@"
-#
-#     [...]
-# }
-# my_helper --arg1 "val1" -b val2 -c
-#
-# usage: ynh_handle_getopts_args "$@"
-# | arg: $@    - Simply "$@" to tranfert all the positionnal arguments to the function
-#
-# This helper need an array, named "args_array" with all the arguments used by the helper
-# 	that want to use ynh_handle_getopts_args
-# Be carreful, this array has to be an associative array, as the following example:
-# declare -Ar args_array=( [a]=arg1 [b]=arg2= [c]=arg3 )
-# Let's explain this array:
-# a, b and c are short options, -a, -b and -c
-# arg1, arg2 and arg3 are the long options associated to the previous short ones. --arg1, --arg2 and --arg3
-# For each option, a short and long version has to be defined.
-# Let's see something more significant
-# declare -Ar args_array=( [u]=user [f]=finalpath= [d]=database )
-#
-# NB: Because we're using 'declare' without -g, the array will be declared as a local variable.
-#
-# Please keep in mind that the long option will be used as a variable to store the values for this option.
-# For the previous example, that means that $finalpath will be fill with the value given as argument for this option.
-#
-# Also, in the previous example, finalpath has a '=' at the end. That means this option need a value.
-# So, the helper has to be call with --finalpath /final/path, --finalpath=/final/path or -f /final/path, the variable $finalpath will get the value /final/path
-# If there's many values for an option, -f /final /path, the value will be separated by a ';' $finalpath=/final;/path
-# For an option without value, like --user in the example, the helper can be called only with --user or -u. $user will then get the value 1.
-#
-# To keep a retrocompatibility, a package can still call a helper, using getopts, with positional arguments.
-# The "legacy mode" will manage the positional arguments and fill the variable in the same order than they are given in $args_array.
-# e.g. for `my_helper "val1" val2`, arg1 will be filled with val1, and arg2 with val2.
-ynh_handle_getopts_args () {
-	# Manage arguments only if there's some provided
-	set +x
-	if [ $# -ne 0 ]
-	then
-		# Store arguments in an array to keep each argument separated
-		local arguments=("$@")
-
-		# For each option in the array, reduce to short options for getopts (e.g. for [u]=user, --user will be -u)
-		# And built parameters string for getopts
-		# ${!args_array[@]} is the list of all option_flags in the array (An option_flag is 'u' in [u]=user, user is a value)
-		local getopts_parameters=""
-		local option_flag=""
-		for option_flag in "${!args_array[@]}"
-		do
-			# Concatenate each option_flags of the array to build the string of arguments for getopts
-			# Will looks like 'abcd' for -a -b -c -d
-			# If the value of an option_flag finish by =, it's an option with additionnal values. (e.g. --user bob or -u bob)
-			# Check the last character of the value associate to the option_flag
-			if [ "${args_array[$option_flag]: -1}" = "=" ]
-			then
-				# For an option with additionnal values, add a ':' after the letter for getopts.
-				getopts_parameters="${getopts_parameters}${option_flag}:"
-			else
-				getopts_parameters="${getopts_parameters}${option_flag}"
-			fi
-			# Check each argument given to the function
-			local arg=""
-			# ${#arguments[@]} is the size of the array
-			for arg in `seq 0 $(( ${#arguments[@]} - 1 ))`
-			do
-				# And replace long option (value of the option_flag) by the short option, the option_flag itself
-				# (e.g. for [u]=user, --user will be -u)
-				# Replace long option with =
-				arguments[arg]="${arguments[arg]//--${args_array[$option_flag]}/-${option_flag} }"
-				# And long option without =
-				arguments[arg]="${arguments[arg]//--${args_array[$option_flag]%=}/-${option_flag}}"
-			done
-		done
-
-		# Read and parse all the arguments
-		# Use a function here, to use standart arguments $@ and be able to use shift.
-		parse_arg () {
-			# Read all arguments, until no arguments are left
-			while [ $# -ne 0 ]
-			do
-				# Initialize the index of getopts
-				OPTIND=1
-				# Parse with getopts only if the argument begin by -, that means the argument is an option
-				# getopts will fill $parameter with the letter of the option it has read.
-				local parameter=""
-				getopts ":$getopts_parameters" parameter || true
-
-				if [ "$parameter" = "?" ]
-				then
-					ynh_die --message="Invalid argument: -${OPTARG:-}"
-				elif [ "$parameter" = ":" ]
-				then
-					ynh_die --message="-$OPTARG parameter requires an argument."
-				else
-					local shift_value=1
-					# Use the long option, corresponding to the short option read by getopts, as a variable
-					# (e.g. for [u]=user, 'user' will be used as a variable)
-					# Also, remove '=' at the end of the long option
-					# The variable name will be stored in 'option_var'
-					local option_var="${args_array[$parameter]%=}"
-					# If this option doesn't take values
-					# if there's a '=' at the end of the long option name, this option takes values
-					if [ "${args_array[$parameter]: -1}" != "=" ]
-					then
-						# 'eval ${option_var}' will use the content of 'option_var'
-						eval ${option_var}=1
-					else
-						# Read all other arguments to find multiple value for this option.
-						# Load args in a array
-						local all_args=("$@")
-
-						# If the first argument is longer than 2 characters,
-						# There's a value attached to the option, in the same array cell
-						if [ ${#all_args[0]} -gt 2 ]; then
-							# Remove the option and the space, so keep only the value itself.
-							all_args[0]="${all_args[0]#-${parameter} }"
-							# Reduce the value of shift, because the option has been removed manually
-							shift_value=$(( shift_value - 1 ))
-						fi
-
-						# Declare the content of option_var as a variable.
-						eval ${option_var}=""
-						# Then read the array value per value
-						local i
-						for i in `seq 0 $(( ${#all_args[@]} - 1 ))`
-						do
-							# If this argument is an option, end here.
-							if [ "${all_args[$i]:0:1}" == "-" ]
-							then
-								# Ignore the first value of the array, which is the option itself
-								if [ "$i" -ne 0 ]; then
-									break
-								fi
-							else
-								# Else, add this value to this option
-								# Each value will be separated by ';'
-								if [ -n "${!option_var}" ]
-								then
-									# If there's already another value for this option, add a ; before adding the new value
-									eval ${option_var}+="\;"
-								fi
-								eval ${option_var}+=\"${all_args[$i]}\"
-								shift_value=$(( shift_value + 1 ))
-							fi
-						done
-					fi
-				fi
-
-				# Shift the parameter and its argument(s)
-				shift $shift_value
-			done
-		}
-
-		# LEGACY MODE
-		# Check if there's getopts arguments
-		if [ "${arguments[0]:0:1}" != "-" ]
-		then
-			# If not, enter in legacy mode and manage the arguments as positionnal ones..
-			# Dot not echo, to prevent to go through a helper output. But print only in the log.
-			set -x; echo "! Helper used in legacy mode !" > /dev/null; set +x
-			local i
-			for i in `seq 0 $(( ${#arguments[@]} -1 ))`
-			do
-				# Try to use legacy_args as a list of option_flag of the array args_array
-				# Otherwise, fallback to getopts_parameters to get the option_flag. But an associative arrays isn't always sorted in the correct order...
-				# Remove all ':' in getopts_parameters
-				getopts_parameters=${legacy_args:-${getopts_parameters//:}}
-				# Get the option_flag from getopts_parameters, by using the option_flag according to the position of the argument.
-				option_flag=${getopts_parameters:$i:1}
-				if [ -z "$option_flag" ]; then
-						ynh_print_warn --message="Too many arguments ! \"${arguments[$i]}\" will be ignored."
-						continue
-				fi
-				# Use the long option, corresponding to the option_flag, as a variable
-				# (e.g. for [u]=user, 'user' will be used as a variable)
-				# Also, remove '=' at the end of the long option
-				# The variable name will be stored in 'option_var'
-				local option_var="${args_array[$option_flag]%=}"
-
-				# Store each value given as argument in the corresponding variable
-				# The values will be stored in the same order than $args_array
-				eval ${option_var}+=\"${arguments[$i]}\"
-			done
-			unset legacy_args
-		else
-			# END LEGACY MODE
-			# Call parse_arg and pass the modified list of args as an array of arguments.
-			parse_arg "${arguments[@]}"
-		fi
-	fi
-	set -x
-}
-
-#=================================================
-
 # Install or update the main directory yunohost.multimedia
 #
 # usage: ynh_multimedia_build_main_dir
@@ -517,27 +313,6 @@ ynh_check_app_version_changed () {
 
 #=================================================
 
-# 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] ]
@@ -707,6 +482,10 @@ ynh_script_progression () {
 	ynh_print_info "[$progression_bar] > ${message}${print_exec_time}"
 }
 
+#=================================================
+# EXPERIMENTAL HELPERS
+#=================================================
+
 # Send an email to inform the administrator
 #
 # usage: ynh_send_readme_to_admin --app_message=app_message [--recipients=recipients] [--type=type]

From 3e2bed193b9e717c5b4ff5fae460c1b0699e4963 Mon Sep 17 00:00:00 2001
From: Maniack Crudelis 
Date: Thu, 31 Jan 2019 12:05:31 +0100
Subject: [PATCH 4/4] Enable tests with package_check

---
 check_process   |  9 +++------
 scripts/install | 23 +++++++++++++++--------
 scripts/remove  | 15 ++++++++++-----
 scripts/upgrade |  5 ++++-
 4 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/check_process b/check_process
index b72224b..695a07b 100644
--- a/check_process
+++ b/check_process
@@ -17,12 +17,9 @@
 		port_already_use=0
 		change_url=0
 ;;; Levels
-# Level 1: Manually tested...
-	Level 1=1
-# Level 2: Manually tested...
-	Level 2=1
-# Level 3: Manually tested...
-	Level 3=1
+	Level 1=auto
+	Level 2=auto
+	Level 3=auto
 # Level 4: Not relevant.
 	Level 4=na
 	Level 5=auto
diff --git a/scripts/install b/scripts/install
index b4cef76..8f043ee 100755
--- a/scripts/install
+++ b/scripts/install
@@ -33,8 +33,7 @@ app=$YNH_APP_INSTANCE_NAME
 # DISCLAIMER
 #=================================================
 
-PACKAGE_CHECK_EXEC=${PACKAGE_CHECK_EXEC:-0}
-if [ "$PACKAGE_CHECK_EXEC" != "0" ]; then
+if IS_PACKAGE_CHECK; then
 	ynh_print_warn "This app can't be tested by package check. Please see the readme for more information. https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh"
 fi
 
@@ -101,7 +100,9 @@ mkdir -p "$user_dir"
 ynh_script_progression --message="Install quotas system" --weight=3
 
 # https://github.com/maniackcrudelis/ssh_chroot/blob/master/unix_quotas/unix_quotas.sh
-quotas_install
+if ! IS_PACKAGE_CHECK; then
+	quotas_install
+fi
 
 #=================================================
 # CONFIGURE FSTAB TO SUPPORT QUOTAS
@@ -110,11 +111,14 @@ ynh_script_progression --message="Configure fstab to support quotas" --weight=3
 
 # https://github.com/maniackcrudelis/ssh_chroot/blob/master/unix_quotas/unix_quotas.sh
 # Set fstab
-quotas_find_mount_point "$user_dir"
-quotas_set_fstab "$quotas_mount_point"
+if ! IS_PACKAGE_CHECK
+then
+	quotas_find_mount_point "$user_dir"
+	quotas_set_fstab "$quotas_mount_point"
 
-# Activate quotas
-quotas_activate "$quotas_mount_point"
+	# Activate quotas
+	quotas_activate "$quotas_mount_point"
+fi
 
 #=================================================
 # CREATE THE USER WITH CHROOT_MANAGER
@@ -139,7 +143,10 @@ then
 fi
 
 ynh_print_OFF
-$final_path/chroot_manager.sh adduser --name $ssh_user $auth_opt "$auth_value" --directory "$user_dir" --quota $size
+if ! IS_PACKAGE_CHECK
+then
+	$final_path/chroot_manager.sh adduser --name $ssh_user $auth_opt "$auth_value" --directory "$user_dir" --quota $size
+fi
 ynh_print_ON
 
 #=================================================
diff --git a/scripts/remove b/scripts/remove
index 670c3f6..49a6421 100755
--- a/scripts/remove
+++ b/scripts/remove
@@ -36,18 +36,23 @@ ynh_script_progression --message="Remove quotas options in fstab" --weight=3
 user_dir="/home/yunohost.app/ssh_chroot_directories/$ssh_user"
 
 # https://github.com/maniackcrudelis/ssh_chroot/blob/master/unix_quotas/unix_quotas.sh
-quotas_find_mount_point "$user_dir"
-quotas_clean_fstab "$quotas_mount_point"
+if ! IS_PACKAGE_CHECK
+then
+	quotas_find_mount_point "$user_dir"
+	quotas_clean_fstab "$quotas_mount_point"
 
-# Deactivate quotas
-quotas_deactivate "$quotas_mount_point"
+	# Deactivate quotas
+	quotas_deactivate "$quotas_mount_point"
+fi
 
 #=================================================
 # REMOVE THE USER WITH CHROOT_MANAGER
 #=================================================
 ynh_script_progression --message="Remove the user with Chroot_manager" --weight=3
 
-$final_path/chroot_manager.sh deluser --name $ssh_user
+if ! IS_PACKAGE_CHECK; then
+	$final_path/chroot_manager.sh deluser --name $ssh_user
+fi
 
 #=================================================
 # STANDARD REMOVE
diff --git a/scripts/upgrade b/scripts/upgrade
index a683898..b9b9538 100755
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -70,7 +70,10 @@ ssh_chroot_standard_binaries "$user_dir"
 ssh_chroot_copy_binary rsync "$user_dir"
 
 # Set permissions
-ssh_chroot_set_permissions "$user_dir" $ssh_user
+if ! IS_PACKAGE_CHECK
+then
+	ssh_chroot_set_permissions "$user_dir" $ssh_user
+fi
 
 #=================================================
 # UPDATE THE LINK TO CHROOT_MANAGER