From 2e93c29a45ae9d58694c0de962151e6829739380 Mon Sep 17 00:00:00 2001 From: Chris Koeritz Date: Fri, 18 May 2018 18:01:41 -0400 Subject: [PATCH] using THISDIR instead of WORKDIR for the auto-location stuff, we're now using the more self-descriptive name of THISDIR for where the script started up in. --- infobase/examples/bashisms/script_location.sh | 2 +- scripts/archival/backup_trac.sh | 4 +-- scripts/core/connect_feisty_meow.sh | 4 +-- scripts/core/functions.sh | 2 +- scripts/core/launch_feisty_meow.sh | 2 +- scripts/security/cool_permissionator.sh | 31 +++++++++++++------ scripts/shunit/example_shunit_test.sh | 6 ++-- scripts/site_avenger/avcoreup.sh | 4 +-- scripts/site_avenger/powerup.sh | 6 ++-- .../site_avenger/revamp_cakelampvm_v002.sh | 4 +-- .../site_avenger/revamp_cakelampvm_v003.sh | 4 +-- scripts/site_avenger/shared_site_mgr.sh | 6 ++-- scripts/site_avenger/sitepush.sh | 4 +-- scripts/site_avenger/siteup.sh | 4 +-- scripts/site_avenger/standup.sh | 6 ++-- scripts/site_avenger/teardown.sh | 6 ++-- scripts/system/add_apache_site.sh | 4 +-- scripts/system/add_domain.sh | 4 +-- scripts/system/add_swap_mount.sh | 4 +-- scripts/system/remove_apache_site.sh | 4 +-- scripts/system/remove_domain.sh | 4 +-- 21 files changed, 64 insertions(+), 51 deletions(-) diff --git a/infobase/examples/bashisms/script_location.sh b/infobase/examples/bashisms/script_location.sh index 7fa942a6..bea06161 100644 --- a/infobase/examples/bashisms/script_location.sh +++ b/infobase/examples/bashisms/script_location.sh @@ -6,5 +6,5 @@ ORIGINATING_FOLDER="$( \cd "$(\dirname "$0")" && /bin/pwd )" # another slightly tighter version: -export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. +export THISDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. diff --git a/scripts/archival/backup_trac.sh b/scripts/archival/backup_trac.sh index f96e5ae5..dadb6219 100644 --- a/scripts/archival/backup_trac.sh +++ b/scripts/archival/backup_trac.sh @@ -2,12 +2,12 @@ # backs up a trac repository into a tar.gz file. -export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. +export THISDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. trac_path="$1"; shift archive_path="$1"; shift # call our arbitrary backer upper, since this is a simple single directory case. -bash $WORKDIR/backup_arbitrary.sh "$trac_path" "$archive_path" "trac_bkup" +bash $THISDIR/backup_arbitrary.sh "$trac_path" "$archive_path" "trac_bkup" diff --git a/scripts/core/connect_feisty_meow.sh b/scripts/core/connect_feisty_meow.sh index 6f6ffd38..211bba7b 100644 --- a/scripts/core/connect_feisty_meow.sh +++ b/scripts/core/connect_feisty_meow.sh @@ -5,9 +5,9 @@ # this script adds the feisty inits code to .bashrc, if we think it has not yet been added. # auto-locate the feisty meow scripts, since they supposedly are not enabled yet. -export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. +export THISDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. # normalize the path we want to cobble together. -export FEISTY_MEOW_APEX="$( \cd "$WORKDIR/../.." && \pwd )" +export FEISTY_MEOW_APEX="$( \cd "$THISDIR/../.." && \pwd )" echo calculated apex as $FEISTY_MEOW_APEX diff --git a/scripts/core/functions.sh b/scripts/core/functions.sh index efc7df54..494c43c5 100644 --- a/scripts/core/functions.sh +++ b/scripts/core/functions.sh @@ -933,7 +933,7 @@ return 0 # site avenger aliases function switchto() { - WORKDIR="$FEISTY_MEOW_SCRIPTS/site_avenger" + THISDIR="$FEISTY_MEOW_SCRIPTS/site_avenger" source "$FEISTY_MEOW_SCRIPTS/site_avenger/shared_site_mgr.sh" switch_to "$1" } diff --git a/scripts/core/launch_feisty_meow.sh b/scripts/core/launch_feisty_meow.sh index f793c6d9..0d7d54be 100644 --- a/scripts/core/launch_feisty_meow.sh +++ b/scripts/core/launch_feisty_meow.sh @@ -19,7 +19,7 @@ ############## # this script cannot handle figuring out where it lives, so approaches that -# get the WORKDIR will fail. this is a consequence of this always being used +# get the THISDIR will fail. this is a consequence of this always being used # in bash's 'source' directive, which does not pass the script name as # argument 0. instead, we just check for the bad condition of a malconfigured # script system and try to repair it. diff --git a/scripts/security/cool_permissionator.sh b/scripts/security/cool_permissionator.sh index 340e2242..e66cab86 100644 --- a/scripts/security/cool_permissionator.sh +++ b/scripts/security/cool_permissionator.sh @@ -28,11 +28,18 @@ function reapply_cool_permissions() fi # fix some permissions for important security considerations. - harsh_perm $HOME/.ssh + if [ -d $HOME/.ssh ]; then + harsh_perm $HOME/.ssh + fi + +#hmmm: consider adding feisty meow apex to the dirname list below. -#hmmm: consider adding feisty meow apex to the list below. # iterate across the list of dirs we want cooluser to own and change their ownership. - for dirname in $HOME $DEFAULT_FEISTYMEOW_ORG_DIR /usr/local/${cooluser} /home/games $arch_addin; do + for dirname in $HOME \ + $DEFAULT_FEISTYMEOW_ORG_DIR \ + /usr/local/${cooluser} \ + /home/games \ + $arch_addin; do if [ -d "$dirname" ]; then echo "revising ownership on '$dirname'" sudo chown -R ${cooluser}:${cooluser} "$dirname" @@ -40,19 +47,19 @@ function reapply_cool_permissions() fi done - # special case for archives directory. + # special case for archives directory in stuffing. if [ -d /z/stuffing -o -L /z/stuffing ]; then - sudo chown ${cooluser}:${cooluser} /z + sudo chown ${cooluser}:${cooluser} /z/ test_or_die "chowning /z for ${cooluser}" sudo chmod g+rx,o+rx /z test_or_die "chmodding /z/ for ${cooluser}" - sudo chown ${cooluser}:${cooluser} /z/stuffing + sudo chown ${cooluser}:${cooluser} /z/stuffing/ test_or_die "chowning /z/stuffing for ${cooluser}" sudo chmod g+rx,o-rwx /z/stuffing test_or_die "chmodding /z/stuffing for ${cooluser}" pushd /z/stuffing &>/dev/null if [ -d archives -o -L archives ]; then - sudo chown ${cooluser}:${cooluser} archives + sudo chown ${cooluser}:${cooluser} archives/ test_or_die "chowning /z/stuffing/archives for ${cooluser}" sudo chmod -R g+rwx archives test_or_die "chmodding /z/stuffing/archives for ${cooluser}" @@ -60,7 +67,7 @@ function reapply_cool_permissions() popd &>/dev/null fi - # make the logs readable by normal humans. + # make the log files readable by normal humans. sudo bash $FEISTY_MEOW_SCRIPTS/security/normal_perm.sh /var/log test_or_die "setting normal perms on /var/log" } @@ -69,11 +76,17 @@ function reapply_cool_permissions() # than when it's just being sourced. # this runs the cool permission applier on the current user. -if [[ $0 =~ .*reapply_cool_permissions\.sh.* ]]; then +if [[ $0 =~ .*cool_permissionator\.sh.* ]]; then +echo A THISDIR="$( \cd "$(\dirname "$0")" && /bin/pwd )" +echo B + export FEISTY_MEOW_APEX="$( \cd "$THISDIR/../.." && \pwd )" +echo B.2 source "$THISDIR/../core/launch_feisty_meow.sh" test_or_die "sourcing the feisty meow launcher" +echo C reapply_cool_permissions $(logname) test_or_die "reapplying cool permissions on $(logname)" +echo D fi diff --git a/scripts/shunit/example_shunit_test.sh b/scripts/shunit/example_shunit_test.sh index 17b3dd89..8931aef1 100644 --- a/scripts/shunit/example_shunit_test.sh +++ b/scripts/shunit/example_shunit_test.sh @@ -5,13 +5,13 @@ # Author: Chris Koeritz # license gnu gpl v3 -export WORKDIR="$( \cd "$(\dirname "$0")" && /bin/pwd )" # obtain the script's working directory. +export THISDIR="$( \cd "$(\dirname "$0")" && /bin/pwd )" # obtain the script's working directory. if [[ ! "$0" =~ ^/.* ]]; then # re-run the script with an absolute path if it didn't start out that way; otherwise, # shunit is not happy with finding the script. - exec "$WORKDIR/$(basename $0)" $* + exec "$THISDIR/$(basename $0)" $* fi -cd $WORKDIR +cd $THISDIR oneTimeSetUp() { diff --git a/scripts/site_avenger/avcoreup.sh b/scripts/site_avenger/avcoreup.sh index 33c3daaf..106c1fd3 100644 --- a/scripts/site_avenger/avcoreup.sh +++ b/scripts/site_avenger/avcoreup.sh @@ -5,7 +5,7 @@ # updates just the site avenger core portion of an app. -export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. +export THISDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. ############################ @@ -14,7 +14,7 @@ export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's work # check for parameters. app_dirname="$1"; shift -source "$WORKDIR/shared_site_mgr.sh" +source "$THISDIR/shared_site_mgr.sh" sep diff --git a/scripts/site_avenger/powerup.sh b/scripts/site_avenger/powerup.sh index eccb0b6a..28e03240 100644 --- a/scripts/site_avenger/powerup.sh +++ b/scripts/site_avenger/powerup.sh @@ -20,8 +20,8 @@ # It will have to be told the theme name, but will assume it's 'Turtle' to # start with. The concept of the theme comes from cakephp. -export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. -export FEISTY_MEOW_APEX="$( \cd "$WORKDIR/../.." && \pwd )" +export THISDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. +export FEISTY_MEOW_APEX="$( \cd "$THISDIR/../.." && \pwd )" source "$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh" @@ -55,7 +55,7 @@ if [ "$app_dirname" == "-help" -o "$app_dirname" == "--help" ]; then print_instructions fi -source "$WORKDIR/shared_site_mgr.sh" +source "$THISDIR/shared_site_mgr.sh" sep diff --git a/scripts/site_avenger/revamp_cakelampvm_v002.sh b/scripts/site_avenger/revamp_cakelampvm_v002.sh index b71d8835..20f721c1 100644 --- a/scripts/site_avenger/revamp_cakelampvm_v002.sh +++ b/scripts/site_avenger/revamp_cakelampvm_v002.sh @@ -16,8 +16,8 @@ fi ############## -export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. -export FEISTY_MEOW_APEX="$( \cd "$WORKDIR/../.." && \pwd )" +export THISDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. +export FEISTY_MEOW_APEX="$( \cd "$THISDIR/../.." && \pwd )" export NO_HELLO=right source "$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh" diff --git a/scripts/site_avenger/revamp_cakelampvm_v003.sh b/scripts/site_avenger/revamp_cakelampvm_v003.sh index 771f81e2..ccd40659 100644 --- a/scripts/site_avenger/revamp_cakelampvm_v003.sh +++ b/scripts/site_avenger/revamp_cakelampvm_v003.sh @@ -16,8 +16,8 @@ fi ############## -export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. -export FEISTY_MEOW_APEX="$( \cd "$WORKDIR/../.." && \pwd )" +export THISDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. +export FEISTY_MEOW_APEX="$( \cd "$THISDIR/../.." && \pwd )" export NO_HELLO=right source "$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh" diff --git a/scripts/site_avenger/shared_site_mgr.sh b/scripts/site_avenger/shared_site_mgr.sh index b0ce7d6d..4f35016d 100644 --- a/scripts/site_avenger/shared_site_mgr.sh +++ b/scripts/site_avenger/shared_site_mgr.sh @@ -5,7 +5,7 @@ # This contains a bunch of reusable functions that help out in managing websites. -# This script is sourced, and relies on the value of WORKDIR, which should +# This script is sourced, and relies on the value of THISDIR, which should # point at the directory where the site management scripts are stored, # especially this one. @@ -17,7 +17,7 @@ export SSM_LOG_FILE="$TMP/$(logname)-siteavenger-script.log" # if there is none, we will use our default version. export SITE_MANAGEMENT_CONFIG_FILE if [ -z "$SITE_MANAGEMENT_CONFIG_FILE" ]; then - SITE_MANAGEMENT_CONFIG_FILE="$WORKDIR/config/default.app" + SITE_MANAGEMENT_CONFIG_FILE="$THISDIR/config/default.app" echo "$(date_stringer): Site management config file was not set. Using default:" >> "$SSM_LOG_FILE" echo "$(date_stringer): $SITE_MANAGEMENT_CONFIG_FILE" >> "$SSM_LOG_FILE" fi @@ -45,7 +45,7 @@ function locate_config_file() { local app_dirname="$1"; shift - local configfile="$WORKDIR/config/${app_dirname}.app" + local configfile="$THISDIR/config/${app_dirname}.app" echo "$(date_stringer): config file guessed?: $configfile" >> "$SSM_LOG_FILE" if [ ! -f "$configfile" ]; then # this is not a good config file. we can't auto-guess the config. diff --git a/scripts/site_avenger/sitepush.sh b/scripts/site_avenger/sitepush.sh index 52e2e13d..8a69d5da 100644 --- a/scripts/site_avenger/sitepush.sh +++ b/scripts/site_avenger/sitepush.sh @@ -5,7 +5,7 @@ # checks the chosen site into the online git repository. -export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. +export THISDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. ############################ @@ -15,7 +15,7 @@ export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's work app_dirname="$1"; shift repo_name="$1"; shift -source "$WORKDIR/shared_site_mgr.sh" +source "$THISDIR/shared_site_mgr.sh" sep diff --git a/scripts/site_avenger/siteup.sh b/scripts/site_avenger/siteup.sh index e2a70593..8c186ad9 100644 --- a/scripts/site_avenger/siteup.sh +++ b/scripts/site_avenger/siteup.sh @@ -5,7 +5,7 @@ # updates a site avenger app. -export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. +export THISDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. ############################ @@ -15,7 +15,7 @@ export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's work app_dirname="$1"; shift repo_name="$1"; shift -source "$WORKDIR/shared_site_mgr.sh" +source "$THISDIR/shared_site_mgr.sh" sep diff --git a/scripts/site_avenger/standup.sh b/scripts/site_avenger/standup.sh index 3ba100f3..72378ca8 100644 --- a/scripts/site_avenger/standup.sh +++ b/scripts/site_avenger/standup.sh @@ -6,8 +6,8 @@ # management scripts. So far, the scripts rely on at least php. The support # is much more powerful if the site is based on cakephp and site avenger. -export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. -export FEISTY_MEOW_APEX="$( \cd "$WORKDIR/../.." && \pwd )" +export THISDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. +export FEISTY_MEOW_APEX="$( \cd "$THISDIR/../.." && \pwd )" source "$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh" @@ -51,7 +51,7 @@ fi # through to ask for access. sudo bash -c 'echo sudo permissions acquired.' -source "$WORKDIR/shared_site_mgr.sh" +source "$THISDIR/shared_site_mgr.sh" sep diff --git a/scripts/site_avenger/teardown.sh b/scripts/site_avenger/teardown.sh index 91de9420..68fa0e14 100644 --- a/scripts/site_avenger/teardown.sh +++ b/scripts/site_avenger/teardown.sh @@ -5,8 +5,8 @@ # # Author: Chris Koeritz -export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. -export FEISTY_MEOW_APEX="$( \cd "$WORKDIR/../.." && \pwd )" +export THISDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. +export FEISTY_MEOW_APEX="$( \cd "$THISDIR/../.." && \pwd )" source "$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh" @@ -43,7 +43,7 @@ fi # through to ask for access. sudo bash -c 'echo sudo permissions acquired.' -source "$WORKDIR/shared_site_mgr.sh" +source "$THISDIR/shared_site_mgr.sh" sep diff --git a/scripts/system/add_apache_site.sh b/scripts/system/add_apache_site.sh index 778b22d5..d3d4595d 100644 --- a/scripts/system/add_apache_site.sh +++ b/scripts/system/add_apache_site.sh @@ -3,8 +3,8 @@ # creates a new apache website for a specified domain. # auto-find the scripts, since we might want to run this as sudo. -export WORKDIR="$( \cd "$(\dirname "$0")" && /bin/pwd )" # obtain the script's working directory. -export FEISTY_MEOW_APEX="$( \cd "$WORKDIR/../.." && \pwd )" +export THISDIR="$( \cd "$(\dirname "$0")" && /bin/pwd )" # obtain the script's working directory. +export FEISTY_MEOW_APEX="$( \cd "$THISDIR/../.." && \pwd )" source "$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh" source "$FEISTY_MEOW_SCRIPTS/system/common_sysadmin.sh" diff --git a/scripts/system/add_domain.sh b/scripts/system/add_domain.sh index e12faa7b..78009042 100644 --- a/scripts/system/add_domain.sh +++ b/scripts/system/add_domain.sh @@ -10,8 +10,8 @@ # # Author: Chris Koeritz -export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. -export FEISTY_MEOW_APEX="$( \cd "$WORKDIR/../.." && \pwd )" +export THISDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. +export FEISTY_MEOW_APEX="$( \cd "$THISDIR/../.." && \pwd )" source "$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh" source "$FEISTY_MEOW_SCRIPTS/system/common_sysadmin.sh" diff --git a/scripts/system/add_swap_mount.sh b/scripts/system/add_swap_mount.sh index 608ffc5c..b400fcb9 100644 --- a/scripts/system/add_swap_mount.sh +++ b/scripts/system/add_swap_mount.sh @@ -1,8 +1,8 @@ #!/bin/bash # auto-find the scripts, since we might want to run this as sudo. -export WORKDIR="$( \cd "$(\dirname "$0")" && /bin/pwd )" # obtain the script's working directory. -export FEISTY_MEOW_APEX="$( \cd "$WORKDIR/../.." && \pwd )" +export THISDIR="$( \cd "$(\dirname "$0")" && /bin/pwd )" # obtain the script's working directory. +export FEISTY_MEOW_APEX="$( \cd "$THISDIR/../.." && \pwd )" source "$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh" if [[ $EUID != 0 ]]; then diff --git a/scripts/system/remove_apache_site.sh b/scripts/system/remove_apache_site.sh index ef6c8b6d..6d23e7ab 100644 --- a/scripts/system/remove_apache_site.sh +++ b/scripts/system/remove_apache_site.sh @@ -3,8 +3,8 @@ # uninstalls the apache website for a specified domain. # auto-find the scripts, since we might want to run this as sudo. -export WORKDIR="$( \cd "$(\dirname "$0")" && /bin/pwd )" # obtain the script's working directory. -export FEISTY_MEOW_APEX="$( \cd "$WORKDIR/../.." && \pwd )" +export THISDIR="$( \cd "$(\dirname "$0")" && /bin/pwd )" # obtain the script's working directory. +export FEISTY_MEOW_APEX="$( \cd "$THISDIR/../.." && \pwd )" source "$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh" source "$FEISTY_MEOW_SCRIPTS/system/common_sysadmin.sh" diff --git a/scripts/system/remove_domain.sh b/scripts/system/remove_domain.sh index f734878a..45bb487c 100644 --- a/scripts/system/remove_domain.sh +++ b/scripts/system/remove_domain.sh @@ -6,8 +6,8 @@ # # Author: Chris Koeritz -export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. -export FEISTY_MEOW_APEX="$( \cd "$WORKDIR/../.." && \pwd )" +export THISDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. +export FEISTY_MEOW_APEX="$( \cd "$THISDIR/../.." && \pwd )" source "$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh" source "$FEISTY_MEOW_SCRIPTS/system/common_sysadmin.sh" -- 2.34.1