From c70cef0f335b09a31133a97b0ab10de845a993e3 Mon Sep 17 00:00:00 2001 From: Chris Koeritz Date: Tue, 20 Mar 2018 17:31:38 -0400 Subject: [PATCH] better handling of dir tests this adds handling of bad returns from the find_apps_folder and test_apps_folder methods. previously we were relying on them to bail out with an exit, but cannot do that when using them within shell aliases in same shell. we need them to just return their status, and now any place using them checks the status. where appropriate this causes that outer shell to exit, but now the switchto macro will not bail out if the user chooses quit. --- scripts/site_avenger/avcoreup.sh | 3 ++- scripts/site_avenger/powerup.sh | 3 ++- scripts/site_avenger/shared_site_mgr.sh | 17 ++++++++++++----- scripts/site_avenger/sitepush.sh | 3 ++- scripts/site_avenger/siteup.sh | 3 ++- scripts/site_avenger/standup.sh | 3 ++- scripts/site_avenger/teardown.sh | 3 ++- 7 files changed, 24 insertions(+), 11 deletions(-) diff --git a/scripts/site_avenger/avcoreup.sh b/scripts/site_avenger/avcoreup.sh index 2ae511cb..33c3daaf 100644 --- a/scripts/site_avenger/avcoreup.sh +++ b/scripts/site_avenger/avcoreup.sh @@ -18,7 +18,7 @@ source "$WORKDIR/shared_site_mgr.sh" sep -check_application_dir "$BASE_APPLICATION_PATH" +check_apps_root "$BASE_APPLICATION_PATH" # find proper webroot where the site will be initialized. if [ -z "$app_dirname" ]; then @@ -27,6 +27,7 @@ if [ -z "$app_dirname" ]; then else test_app_folder "$BASE_APPLICATION_PATH" "$app_dirname" fi +test_or_die "finding and testing app folder" # where we expect to find our checkout folder underneath. full_app_dir="$BASE_APPLICATION_PATH/$app_dirname" diff --git a/scripts/site_avenger/powerup.sh b/scripts/site_avenger/powerup.sh index 46070f60..eccb0b6a 100644 --- a/scripts/site_avenger/powerup.sh +++ b/scripts/site_avenger/powerup.sh @@ -59,7 +59,7 @@ source "$WORKDIR/shared_site_mgr.sh" sep -check_application_dir "$BASE_APPLICATION_PATH" +check_apps_root "$BASE_APPLICATION_PATH" # find proper webroot where the site will be initialized. if [ -z "$app_dirname" ]; then @@ -68,6 +68,7 @@ if [ -z "$app_dirname" ]; then else test_app_folder "$BASE_APPLICATION_PATH" "$app_dirname" fi +test_or_die "finding and testing app folder" # where we expect to find our checkout folder underneath. full_app_dir="$BASE_APPLICATION_PATH/$app_dirname" diff --git a/scripts/site_avenger/shared_site_mgr.sh b/scripts/site_avenger/shared_site_mgr.sh index 6f731e69..f8247765 100644 --- a/scripts/site_avenger/shared_site_mgr.sh +++ b/scripts/site_avenger/shared_site_mgr.sh @@ -28,7 +28,7 @@ test_or_die "loading site management configuration from: $SITE_MANAGEMENT_CONFIG export NO_CHECKIN_VENDOR=true # tests that the main storage folder for apps exists. -function check_application_dir() +function check_apps_root() { local appdir="$1"; shift if [ ! -d "$appdir" ]; then @@ -63,6 +63,7 @@ the standard pattern for cakephp projects." source "$SITE_MANAGEMENT_CONFIG_FILE" test_or_die "loading site management configuration from: $SITE_MANAGEMENT_CONFIG_FILE" + return 0 } # this function will seek out top-level directories in the target directory passed in. @@ -100,14 +101,14 @@ function find_app_folder() options=( $(find "$appsdir" -mindepth 1 -maxdepth 1 -type d -exec basename {} ';') "Quit") select app_dirname in "${options[@]}"; do case $app_dirname in - "Quit") echo ; echo "Quitting from the script."; exit 1; ;; + "Quit") echo ; echo "Quitting from the script."; return 1; ;; *) echo ; echo "You picked folder '$app_dirname'" ; break; ;; esac done if [ -z "$app_dirname" ]; then echo "The folder was not provided. This script needs a directory name" echo "within which to initialize the site." - exit 1 + return 1 fi PS3="$holdps3" fi @@ -115,9 +116,11 @@ function find_app_folder() test_or_die "Testing application folder: $app_dirname" echo "Application folder is: $app_dirname" + return 0 } -# ensures that the app directory name is valid. +# ensures that the app directory name is valid and then loads the config +# for the app (either via a specific file or using the defaults). function test_app_folder() { local appsdir="$1"; shift @@ -388,7 +391,7 @@ function switch_to() # check for parameters. app_dirname="$1"; shift - check_application_dir "$BASE_APPLICATION_PATH" + check_apps_root "$BASE_APPLICATION_PATH" # find proper webroot where the site will be initialized. if [ -z "$app_dirname" ]; then @@ -397,6 +400,10 @@ function switch_to() else test_app_folder "$BASE_APPLICATION_PATH" "$app_dirname" fi + if [ $? -ne 0 ]; then + echo "Could not locate that application directory" + return 1 + fi # where we expect to find our checkout folder underneath. full_app_dir="$BASE_APPLICATION_PATH/$app_dirname" diff --git a/scripts/site_avenger/sitepush.sh b/scripts/site_avenger/sitepush.sh index 1336a891..52e2e13d 100644 --- a/scripts/site_avenger/sitepush.sh +++ b/scripts/site_avenger/sitepush.sh @@ -19,7 +19,7 @@ source "$WORKDIR/shared_site_mgr.sh" sep -check_application_dir "$BASE_APPLICATION_PATH" +check_apps_root "$BASE_APPLICATION_PATH" # find proper webroot where the site will be initialized. if [ -z "$app_dirname" ]; then @@ -28,6 +28,7 @@ if [ -z "$app_dirname" ]; then else test_app_folder "$BASE_APPLICATION_PATH" "$app_dirname" fi +test_or_die "finding and testing app folder" # where we expect to find our checkout folder underneath. full_app_dir="$BASE_APPLICATION_PATH/$app_dirname" diff --git a/scripts/site_avenger/siteup.sh b/scripts/site_avenger/siteup.sh index 282d0cdc..e2a70593 100644 --- a/scripts/site_avenger/siteup.sh +++ b/scripts/site_avenger/siteup.sh @@ -19,7 +19,7 @@ source "$WORKDIR/shared_site_mgr.sh" sep -check_application_dir "$BASE_APPLICATION_PATH" +check_apps_root "$BASE_APPLICATION_PATH" # find proper webroot where the site will be initialized. if [ -z "$app_dirname" ]; then @@ -28,6 +28,7 @@ if [ -z "$app_dirname" ]; then else test_app_folder "$BASE_APPLICATION_PATH" "$app_dirname" fi +test_or_die "finding and testing app folder" # where we expect to find our checkout folder underneath. full_app_dir="$BASE_APPLICATION_PATH/$app_dirname" diff --git a/scripts/site_avenger/standup.sh b/scripts/site_avenger/standup.sh index c4a6cb26..3ba100f3 100644 --- a/scripts/site_avenger/standup.sh +++ b/scripts/site_avenger/standup.sh @@ -55,7 +55,7 @@ source "$WORKDIR/shared_site_mgr.sh" sep -check_application_dir "$BASE_APPLICATION_PATH" +check_apps_root "$BASE_APPLICATION_PATH" # find proper webroot where the site will be initialized. if [ -z "$app_dirname" ]; then @@ -64,6 +64,7 @@ if [ -z "$app_dirname" ]; then else test_app_folder "$BASE_APPLICATION_PATH" "$app_dirname" fi +test_or_die "finding and testing app folder" #echo "!! domain being added is: $DOMAIN_NAME" diff --git a/scripts/site_avenger/teardown.sh b/scripts/site_avenger/teardown.sh index 5bfcbd46..91de9420 100644 --- a/scripts/site_avenger/teardown.sh +++ b/scripts/site_avenger/teardown.sh @@ -47,7 +47,7 @@ source "$WORKDIR/shared_site_mgr.sh" sep -check_application_dir "$BASE_APPLICATION_PATH" +check_apps_root "$BASE_APPLICATION_PATH" # find proper webroot where the site will be initialized. if [ -z "$app_dirname" ]; then @@ -56,6 +56,7 @@ if [ -z "$app_dirname" ]; then else test_app_folder "$BASE_APPLICATION_PATH" "$app_dirname" fi +test_or_die "finding and testing app folder" sep -- 2.34.1