From: Martin Schwenke Date: Wed, 29 Jun 2016 07:36:05 +0000 (+1000) Subject: ctdb-scripts: Update script boilerplate to avoid shellcheck warnings X-Git-Tag: tdb-1.3.10~488 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f227c26178c2eaf3fae49f32a90ec905f85005f4;p=thirdparty%2Fsamba.git ctdb-scripts: Update script boilerplate to avoid shellcheck warnings * Assign the output of dirname to temporary variable to avoid word splitting when directory name contains whitespace * Drop export of CTDB_BASE to avoid masking broken return value - functions file does the export anyway * Quote path when including functions file Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/config/ctdb-crash-cleanup.sh b/ctdb/config/ctdb-crash-cleanup.sh index 78eaa932654..bcecbfeb564 100755 --- a/ctdb/config/ctdb-crash-cleanup.sh +++ b/ctdb/config/ctdb-crash-cleanup.sh @@ -5,9 +5,9 @@ # [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; echo "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") -. "$CTDB_BASE/functions" +. "${CTDB_BASE}/functions" # If ctdb is running, just exit if service ctdb status >/dev/null 2>&1 ; then diff --git a/ctdb/config/debug-hung-script.sh b/ctdb/config/debug-hung-script.sh index cef004b5046..921683c4669 100755 --- a/ctdb/config/debug-hung-script.sh +++ b/ctdb/config/debug-hung-script.sh @@ -4,9 +4,9 @@ # for other operating systems. [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; echo "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") -. "$CTDB_BASE/functions" +. "${CTDB_BASE}/functions" loadconfig ctdb diff --git a/ctdb/config/debug_locks.sh b/ctdb/config/debug_locks.sh index 8e337518aff..c0bbfcc2e57 100755 --- a/ctdb/config/debug_locks.sh +++ b/ctdb/config/debug_locks.sh @@ -8,9 +8,9 @@ # rather than mutex locks. [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; echo "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") -. "$CTDB_BASE/functions" +. "${CTDB_BASE}/functions" # Default fallback location for database directories. # These can be overwritten from CTDB configuration diff --git a/ctdb/config/events.d/00.ctdb b/ctdb/config/events.d/00.ctdb index bb150acce0a..4feea8530c9 100755 --- a/ctdb/config/events.d/00.ctdb +++ b/ctdb/config/events.d/00.ctdb @@ -4,9 +4,10 @@ # elsewhere. [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") + +. "${CTDB_BASE}/functions" -. $CTDB_BASE/functions loadconfig ctdb_setup_service_state_dir "ctdb" diff --git a/ctdb/config/events.d/01.reclock b/ctdb/config/events.d/01.reclock index da37cf8835d..f2bf2d74334 100755 --- a/ctdb/config/events.d/01.reclock +++ b/ctdb/config/events.d/01.reclock @@ -2,9 +2,10 @@ # script to check accessibility to the reclock file on a node [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") + +. "${CTDB_BASE}/functions" -. $CTDB_BASE/functions loadconfig # If CTDB_RECOVERY_LOCK specifies a helper then exit because this diff --git a/ctdb/config/events.d/05.system b/ctdb/config/events.d/05.system index bfa8e7b4c4e..13f8837a17c 100755 --- a/ctdb/config/events.d/05.system +++ b/ctdb/config/events.d/05.system @@ -2,9 +2,10 @@ # ctdb event script for checking local file system utilization [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") + +. "${CTDB_BASE}/functions" -. $CTDB_BASE/functions loadconfig ctdb_setup_service_state_dir "system-monitoring" diff --git a/ctdb/config/events.d/06.nfs b/ctdb/config/events.d/06.nfs index 2a069f33033..d0611a59ea7 100755 --- a/ctdb/config/events.d/06.nfs +++ b/ctdb/config/events.d/06.nfs @@ -2,9 +2,9 @@ # script to manage nfs in a clustered environment [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") -. $CTDB_BASE/functions +. "${CTDB_BASE}/functions" service_name="nfs" loadconfig diff --git a/ctdb/config/events.d/10.external b/ctdb/config/events.d/10.external index 40f4680e63c..4b22dc7681b 100644 --- a/ctdb/config/events.d/10.external +++ b/ctdb/config/events.d/10.external @@ -8,9 +8,10 @@ # * For connection tracking/killing to work this script must be enabled. [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") + +. "${CTDB_BASE}/functions" -. $CTDB_BASE/functions loadconfig if [ -z "$CTDB_PUBLIC_ADDRESSES" ] ; then diff --git a/ctdb/config/events.d/10.interface b/ctdb/config/events.d/10.interface index 204f4c650bd..1d5aaa4d3aa 100755 --- a/ctdb/config/events.d/10.interface +++ b/ctdb/config/events.d/10.interface @@ -6,9 +6,10 @@ # public interface [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") + +. "${CTDB_BASE}/functions" -. $CTDB_BASE/functions loadconfig [ -z "$CTDB_PUBLIC_ADDRESSES" ] && { diff --git a/ctdb/config/events.d/11.natgw b/ctdb/config/events.d/11.natgw index d6f8161efd9..980c4c43deb 100755 --- a/ctdb/config/events.d/11.natgw +++ b/ctdb/config/events.d/11.natgw @@ -6,9 +6,9 @@ # [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") -. $CTDB_BASE/functions +. "${CTDB_BASE}/functions" service_name=natgw diff --git a/ctdb/config/events.d/11.routing b/ctdb/config/events.d/11.routing index 2fe560f73f1..20b99730b0c 100755 --- a/ctdb/config/events.d/11.routing +++ b/ctdb/config/events.d/11.routing @@ -18,9 +18,10 @@ # bond1 10.3.3.0/24 10.0.0.1 [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") + +. "${CTDB_BASE}/functions" -. $CTDB_BASE/functions loadconfig [ -f $CTDB_BASE/static-routes ] || { diff --git a/ctdb/config/events.d/13.per_ip_routing b/ctdb/config/events.d/13.per_ip_routing index cfcd484a8c8..5085f37c88a 100755 --- a/ctdb/config/events.d/13.per_ip_routing +++ b/ctdb/config/events.d/13.per_ip_routing @@ -1,9 +1,10 @@ #!/bin/sh [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") + +. "${CTDB_BASE}/functions" -. $CTDB_BASE/functions loadconfig service_name=per_ip_routing diff --git a/ctdb/config/events.d/20.multipathd b/ctdb/config/events.d/20.multipathd index 64748dae61c..b5f71e55630 100755 --- a/ctdb/config/events.d/20.multipathd +++ b/ctdb/config/events.d/20.multipathd @@ -7,13 +7,13 @@ # [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") -. $CTDB_BASE/functions +. "${CTDB_BASE}/functions" service_name="multipathd" -loadconfig +loadconfig [ -n "$CTDB_MONITOR_MPDEVICES" ] || exit 0 diff --git a/ctdb/config/events.d/31.clamd b/ctdb/config/events.d/31.clamd index 15751a9c601..2e5eefea251 100755 --- a/ctdb/config/events.d/31.clamd +++ b/ctdb/config/events.d/31.clamd @@ -2,9 +2,9 @@ # event script to manage clamd in a cluster environment [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") -. $CTDB_BASE/functions +. "${CTDB_BASE}/functions" detect_init_style diff --git a/ctdb/config/events.d/40.vsftpd b/ctdb/config/events.d/40.vsftpd index 92a0e9955e9..c1f193bcf8e 100755 --- a/ctdb/config/events.d/40.vsftpd +++ b/ctdb/config/events.d/40.vsftpd @@ -2,9 +2,9 @@ # event strict to manage vsftpd in a cluster environment [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") -. $CTDB_BASE/functions +. "${CTDB_BASE}/functions" service_name="vsftpd" # make sure the service is stopped first diff --git a/ctdb/config/events.d/41.httpd b/ctdb/config/events.d/41.httpd index ac0c9419c6c..6c70d1f2edb 100755 --- a/ctdb/config/events.d/41.httpd +++ b/ctdb/config/events.d/41.httpd @@ -2,9 +2,9 @@ # event script to manage httpd in a cluster environment [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") -. $CTDB_BASE/functions +. "${CTDB_BASE}/functions" detect_init_style diff --git a/ctdb/config/events.d/49.winbind b/ctdb/config/events.d/49.winbind index 33d47c84b6e..da04546b1f4 100755 --- a/ctdb/config/events.d/49.winbind +++ b/ctdb/config/events.d/49.winbind @@ -2,9 +2,9 @@ # ctdb event script for winbind [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") -. $CTDB_BASE/functions +. "${CTDB_BASE}/functions" CTDB_SERVICE_WINBIND=${CTDB_SERVICE_WINBIND:-winbind} diff --git a/ctdb/config/events.d/50.samba b/ctdb/config/events.d/50.samba index 1742ff19249..3fae7f81613 100755 --- a/ctdb/config/events.d/50.samba +++ b/ctdb/config/events.d/50.samba @@ -2,9 +2,9 @@ # ctdb event script for Samba [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") -. $CTDB_BASE/functions +. "${CTDB_BASE}/functions" detect_init_style diff --git a/ctdb/config/events.d/60.nfs b/ctdb/config/events.d/60.nfs index 07b4edf732d..36ef980971c 100755 --- a/ctdb/config/events.d/60.nfs +++ b/ctdb/config/events.d/60.nfs @@ -2,9 +2,9 @@ # script to manage nfs in a clustered environment [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") -. $CTDB_BASE/functions +. "${CTDB_BASE}/functions" service_name="nfs" loadconfig diff --git a/ctdb/config/events.d/70.iscsi b/ctdb/config/events.d/70.iscsi index 9e75214e7e3..7e27a539564 100755 --- a/ctdb/config/events.d/70.iscsi +++ b/ctdb/config/events.d/70.iscsi @@ -3,9 +3,9 @@ # CTDB event script for TGTD based iSCSI [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") -. $CTDB_BASE/functions +. "${CTDB_BASE}/functions" service_name="iscsi" diff --git a/ctdb/config/events.d/91.lvs b/ctdb/config/events.d/91.lvs index 434bd2b6c98..1d3f7331fd6 100755 --- a/ctdb/config/events.d/91.lvs +++ b/ctdb/config/events.d/91.lvs @@ -2,9 +2,9 @@ # script to manage the lvs ip multiplexer for a single public address cluster [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") -. $CTDB_BASE/functions +. "${CTDB_BASE}/functions" loadconfig ctdb diff --git a/ctdb/config/events.d/99.timeout b/ctdb/config/events.d/99.timeout index c18475fec64..7c226d6566b 100755 --- a/ctdb/config/events.d/99.timeout +++ b/ctdb/config/events.d/99.timeout @@ -5,9 +5,10 @@ # the event timeout mechanism. [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") + +. "${CTDB_BASE}/functions" -. $CTDB_BASE/functions loadconfig ctdb [ "$CTDB_RUN_TIMEOUT_MONITOR" = "yes" ] || exit 0 diff --git a/ctdb/config/statd-callout b/ctdb/config/statd-callout index 1cbe6532f98..4e8ae9a1e88 100755 --- a/ctdb/config/statd-callout +++ b/ctdb/config/statd-callout @@ -9,9 +9,9 @@ # STATD_HOSTNAME="myhostname -H /etc/ctdb/statd-callout" [ -n "$CTDB_BASE" ] || \ - export CTDB_BASE=$(cd -P $(dirname "$0") ; echo "$PWD") + CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD") -. $CTDB_BASE/functions +. "${CTDB_BASE}/functions" # Overwrite this so we get some logging die ()