From d4c46fa38d2182ec81812d99430927145334eb56 Mon Sep 17 00:00:00 2001 From: magikcypress Date: Mon, 8 May 2017 18:49:11 +0200 Subject: [PATCH] [fix] add generic function to test install environnement --- scripts/_common | 28 ++++++++++++++++++++++++++++ scripts/install | 19 +++++++++---------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/scripts/_common b/scripts/_common index 9584cf1..f526a9b 100644 --- a/scripts/_common +++ b/scripts/_common @@ -10,6 +10,34 @@ ALL_QUIET () { # Redirige la sortie standard et d'erreur dans /dev/null $@ > /dev/null 2>&1 } +CHECK_VAR () { # Check variable is not empty +# $1 = Checking variable +# $2 = Text to display on error + test -n "$1" || (echo "$2" >&2 && false) +} + +CHECK_PATH () { # Checks / at the beginning of the path. And his absence at the end. + if [ "${path:0:1}" != "/" ]; then # If the first character is not / + path="/$path" # Add / at the beginning of path + fi + if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then # If the last character is a / and it is not the only character. + path="${path:0:${#path}-1}" # Delete last character + fi +} + +CHECK_DOMAINPATH () { # Checks the availability of the path and domain. + sudo yunohost app checkurl $domain$path -a $app +} + +CHECK_FINALPATH () { # Checks that the destination folder is not already in use. + final_path=/var/www/$app + if [ -e "$final_path" ] + then + echo "This path already contains a folder" >&2 + false + fi +} + # Substitute a string by another in a file # # usage: ynh_substitute_char string_to_find replace_string file_to_analyse diff --git a/scripts/install b/scripts/install index 205522c..73f73f8 100644 --- a/scripts/install +++ b/scripts/install @@ -14,23 +14,22 @@ is_public=$YNH_APP_ARG_IS_PUBLIC app=$YNH_APP_INSTANCE_NAME -# Check domain/path availability -sudo yunohost app checkurl "${domain}${path}" -a "$app" \ - || ynh_die "Path not available: ${domain}${path}" +CHECK_VAR "$app" "app name not set" -# Remove trailing "/" for next commands -if [[ ! "$path" == "/" ]]; then - path=${path%/} -fi +CHECK_PATH + +CHECK_DOMAINPATH + +CHECK_FINALPATH + +# Create system user dedicace for this app +ynh_system_user_create $app # Copy files to the right place final_path=/var/www/$app sudo mkdir -p $final_path extract_source $final_path -# Create system user dedicace for this app -ynh_system_user_create $app - # Copy files to the right place with the right permissions final_path=/var/www/$app sudo mkdir -p $final_path