ctdb-doc: Make example NFS Ganesha call-out almost pass shellcheck
authorMartin Schwenke <martin@meltin.net>
Wed, 22 Feb 2017 03:38:45 +0000 (14:38 +1100)
committerMartin Schwenke <martins@samba.org>
Fri, 24 Feb 2017 06:47:09 +0000 (07:47 +0100)
This call-out is referred to in the wiki as an example, so make it as
clean as possible.

All the changes here are trivial.  There is still one failure, which
is slightly non-trivial, so it can be fixed in a separate commit.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/doc/examples/nfs-ganesha-callout

index c03b99a800da8a7068d6da0e178b57e28175bb8e..ac966991a178cf69ea7a7fb86b0e706dfdbf7ce8 100755 (executable)
@@ -51,7 +51,7 @@ nfs_service="${CTDB_NFS_SERVICE:-nfs-ganesha}"
 ganesha_rec_subdir=${CTDB_GANESHA_REC_SUBDIR:-.ganesha}
 procfs=${PROCFS_PATH:-/proc}
 
-case $state_fs in
+case "$state_fs" in
 gpfs)
        GANRECDIR="/var/lib/nfs/ganesha"
        ;;
@@ -60,7 +60,7 @@ glusterfs)
                echo "CTDB_NFS_STATE_MNT not defined for GlusterFS"
                exit 1
        fi
-       host=`hostname`
+       host=$(hostname)
        NODESTATEDIR="$state_dir/nfs-ganesha/$host"
        GANSTATEDIR="$state_dir/nfs-ganesha/.noderefs"
        NODESTATELN="$GANSTATEDIR/$host"
@@ -72,7 +72,7 @@ esac
 
 usage ()
 {
-       _c=$(basename $0)
+       _c=$(basename "$0")
        cat <<EOF
 usage: $_c { shutdown | startup }
        $_c { stop | start | check } nfs
@@ -183,7 +183,7 @@ get_cluster_fs_state ()
 
 create_ganesha_recdirs ()
 {
-       if ! _mounts=$(mount | grep $state_fs); then
+       if ! _mounts=$(mount | grep "$state_fs"); then
                echo "Failed to find mounts of type $state_fs"
                exit 1
        fi
@@ -202,23 +202,23 @@ create_ganesha_recdirs ()
        glusterfs)
                [ -d /var/lib/nfs.backup ] || \
                        mv /var/lib/nfs /var/lib/nfs.backup
-               check_ln ${NODESTATEDIR} /var/lib/nfs
+               check_ln "$NODESTATEDIR" /var/lib/nfs
 
-               mkdir -p ${NODESTATEDIR}/ganesha/v4recov
-               mkdir -p ${NODESTATEDIR}/ganesha/v4old
-               mkdir -p ${NODESTATEDIR}/statd/sm
-               mkdir -p ${NODESTATEDIR}/statd/sm.bak
-               touch ${NODESTATEDIR}/state
-               touch ${NODESTATEDIR}/statd/state
+               mkdir -p "${NODESTATEDIR}/ganesha/v4recov"
+               mkdir -p "${NODESTATEDIR}/ganesha/v4old"
+               mkdir -p "${NODESTATEDIR}/statd/sm"
+               mkdir -p "${NODESTATEDIR}/statd/sm.bak"
+               touch "${NODESTATEDIR}/state"
+               touch "${NODESTATEDIR}/statd/state"
 
-               mkdir -p ${GANSTATEDIR}
-               check_ln ${NODESTATEDIR} ${NODESTATELN}
+               mkdir -p "$GANSTATEDIR"
+               check_ln "$NODESTATEDIR" "$NODESTATELN"
                for node in `ls ${GANSTATEDIR}`; do
                        if [ "${node}" != "${host}" ]; then
-                               check_ln ${GANSTATEDIR}/${node}/ganesha \
-                                        ${NODESTATEDIR}/ganesha/${node}
-                               check_ln ${GANSTATEDIR}/${node}/statd \
-                                        ${NODESTATEDIR}/statd/${node}
+                               check_ln "${GANSTATEDIR}/${node}/ganesha" \
+                                        "${NODESTATEDIR}/ganesha/${node}"
+                               check_ln "${GANSTATEDIR}/${node}/statd" \
+                                        "${NODESTATEDIR}/statd/${node}"
                        fi
                done
                ;;
@@ -231,14 +231,14 @@ service_check ()
 
        # Always succeed if cluster filesystem is not active
        _cluster_fs_state=$(get_cluster_fs_state)
-       if [ $_cluster_fs_state != "active" ] ; then
+       if [ "$_cluster_fs_state" != "active" ] ; then
                return 0
        fi
 
        # Check that NFS Ganesha is running, according to PID file
        _pidfile="/var/run/ganesha.pid"
        _ganesha="/usr/bin/ganesha.nfsd"
-       if ! { read _pid < "$_pidfile" && \
+       if ! { read -r _pid < "$_pidfile" && \
                grep "$_ganesha" "${procfs}/${_pid}/cmdline" ; } >/dev/null 2>&1
        then
 
@@ -266,7 +266,7 @@ nfs_takeip ()
 {
        case  $state_fs in
        glusterfs)
-               check_ln ${NODESTATEDIR} ${GANSTATEDIR}/${2}
+               check_ln "$NODESTATEDIR" "${GANSTATEDIR}/${2}"
                ;;
        esac
        if [ -x "/usr/bin/grace_period" ]; then
@@ -304,7 +304,7 @@ nfs_startup ()
 
 nfs_monitor_list_shares ()
 {
-       grep Path $nfs_exports_file |
+       grep Path "$nfs_exports_file" |
                cut -f2 -d\" |
                sort -u
 }