ctdb-scripts: Update script boilerplate to avoid shellcheck warnings
authorMartin Schwenke <martin@meltin.net>
Wed, 29 Jun 2016 07:36:05 +0000 (17:36 +1000)
committerAmitay Isaacs <amitay@samba.org>
Wed, 6 Jul 2016 02:28:09 +0000 (04:28 +0200)
* 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 <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
23 files changed:
ctdb/config/ctdb-crash-cleanup.sh
ctdb/config/debug-hung-script.sh
ctdb/config/debug_locks.sh
ctdb/config/events.d/00.ctdb
ctdb/config/events.d/01.reclock
ctdb/config/events.d/05.system
ctdb/config/events.d/06.nfs
ctdb/config/events.d/10.external
ctdb/config/events.d/10.interface
ctdb/config/events.d/11.natgw
ctdb/config/events.d/11.routing
ctdb/config/events.d/13.per_ip_routing
ctdb/config/events.d/20.multipathd
ctdb/config/events.d/31.clamd
ctdb/config/events.d/40.vsftpd
ctdb/config/events.d/41.httpd
ctdb/config/events.d/49.winbind
ctdb/config/events.d/50.samba
ctdb/config/events.d/60.nfs
ctdb/config/events.d/70.iscsi
ctdb/config/events.d/91.lvs
ctdb/config/events.d/99.timeout
ctdb/config/statd-callout

index 78eaa9326549fb48413f3ad78a343a5d4039402a..bcecbfeb5643de6a0deab6491085e786f89943ff 100755 (executable)
@@ -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
index cef004b5046992a778cb590c3c5ba077f1a427fb..921683c4669e1a689278c6161db1eda67d0bbbc0 100755 (executable)
@@ -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
 
index 8e337518aff5cff449f2aedab95739293a7ae250..c0bbfcc2e57f1bba6a0177ec0d7b6206ee84a2c9 100755 (executable)
@@ -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
index bb150acce0a9eebba938042ea94fb3b7fb7e5978..4feea8530c9b7fdbfe46df1c12e022fc69cb099b 100755 (executable)
@@ -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"
index da37cf8835d99dab6c6ea2aa55a5e361fcbe009f..f2bf2d743341a12c72bf741c4710f8a4e52830d5 100755 (executable)
@@ -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
index bfa8e7b4c4e7f97ddf272fbc61e3a0adcfb181f4..13f8837a17cebe8a44bf67def54f819d3fe05964 100755 (executable)
@@ -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"
index 2a069f33033277067cbf938cc8650a85be9ccaf4..d0611a59ea7f8a9df809da1c751a40ba057d4bc3 100755 (executable)
@@ -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
index 40f4680e63cf15d8c3f0df1ceb088b3dc8dfc452..4b22dc7681b0720139da77eac62d08ef2cf84ed1 100644 (file)
@@ -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
index 204f4c650bdd7b66aa13ec3106b22c2638d28393..1d5aaa4d3aad52780a83b22c570c332cc08dd22a 100755 (executable)
@@ -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" ] && {
index d6f8161efd9b138e122932d01a235d7ed264730a..980c4c43deb21d4d69b6c33910611f29eb0b32f4 100755 (executable)
@@ -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
 
index 2fe560f73f1a14996470465056b45eb184503b60..20b99730b0ce8b3cdd7c3f62b1b5c60ab3dbd749 100755 (executable)
 # 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 ] || {
index cfcd484a8c85ddc0e9c4960cffb2ab1bff5c398e..5085f37c88ad1bc9bf60c7a4ac64b23603bcc58c 100755 (executable)
@@ -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
index 64748dae61c71eee2867d71951fc789f409e2dc0..b5f71e55630a58c81d0e4ec42621d569f0cf8e4f 100755 (executable)
@@ -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
 
index 15751a9c60104f4352ab0fd4410a402951e18d52..2e5eefea2518a1c548c87bf353d4758df64be977 100755 (executable)
@@ -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
 
index 92a0e9955e904c88762f20bc712881231b9527ca..c1f193bcf8ebfbb6ce888383ff16e5a5f401ef94 100755 (executable)
@@ -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
index ac0c9419c6ca6d128720fed943e86de1257b3ebf..6c70d1f2edbe9442013d88b82aaec2e9d418ed8f 100755 (executable)
@@ -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
 
index 33d47c84b6eccdbbad8d472d0301c769e07ce203..da04546b1f4209aaf84dfbca9ae1104979fde023 100755 (executable)
@@ -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}
 
index 1742ff19249f4ad5ef5461ec299b1ece031dbb1f..3fae7f81613458574deca647e14bd01c16fce233 100755 (executable)
@@ -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
 
index 07b4edf732da66b4bceaf399eea2b3ea2ed9b44c..36ef980971c21365b01c4e98a37b27256e1fd773 100755 (executable)
@@ -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
index 9e75214e7e32a3abd5b6212874029e17f3227667..7e27a53956461e45b53b40a711e45a26470e8e3c 100755 (executable)
@@ -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"
 
index 434bd2b6c98a899edf8bdc53be4b613827b79997..1d3f7331fd685d17cff21931ee14dd2809a6b78d 100755 (executable)
@@ -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
 
index c18475fec64bef8d443eadd7d3c464e825225380..7c226d6566b0d8e9d88be7d41f272320b0677ec2 100755 (executable)
@@ -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
index 1cbe6532f984bbb2a4c72bad54cbe4cfec6acc05..4e8ae9a1e88d0632f9a2ac78a853187ef2801690 100755 (executable)
@@ -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 ()