[PATCH] CTDB scripting clean-ups and shellcheck tests

Martin Schwenke martin at meltin.net
Mon Jul 18 21:21:14 UTC 2016


On Tue, 19 Jul 2016 06:42:13 +1000, Martin Schwenke <martin at meltin.net>
wrote:

> On Mon, 18 Jul 2016 22:03:45 +1000, Martin Schwenke <martin at meltin.net>
> wrote:
> 
> > On Mon, 18 Jul 2016 22:02:40 +1000, Martin Schwenke <martin at meltin.net>
> > wrote:
> > 
> > > A small bunch of shellcheck fixes to CTDB's scripts went in recently.
> > > Following that I did a few more clean-ups.  Then Amitay and I decided
> > > that we might as well go all the way, get rid of all shellcheck
> > > warnings and add some tests to make sure the scripts stay that way.
> > > 
> > > Attached are initial clean-ups.  This is part 1 - I'm splitting this to
> > > try to avoid message moderation limits.
> > > 
> > > 2 replies to follow:
> > > 
> > > * Part 2 - A series of commits to avoid shellcheck warnings
> > > * Part 3 - Addition of CTDB shellcheck test suite
> > > 
> > > These can be applied on top of master in order.
> > > 
> > > Please review and maybe push...  
> > 
> > Part 2.  Cleans up all warnings generated by shellcheck 0.3.7.
> 
> Please don't push.  Despite a lot of prior testing, I made a late change
> yesterday and introduced a bug here that only occurs in some
> shells.  :-(
> 
> Will repost.  

Attached.

The difference is in:

  [PATCH 20/23] ctdb-scripts: Avoid shellcheck warning SC2059 ($ in
  printf format)

This hunk:

diff --git a/ctdb/tools/ctdb_natgw b/ctdb/tools/ctdb_natgw
index 9661cae..448d005 100755
--- a/ctdb/tools/ctdb_natgw
+++ b/ctdb/tools/ctdb_natgw
@@ -148,7 +148,15 @@ nodes_list ()
        if [ "$_ip" = "$_master_ip" ] ; then
            _options="MASTER${_options:+,}${_options}"
        fi
-       printf "${_ip}${_options:+\t}${_options}\n"
+       # There is no other way to do this and keep shellcheck happy.
+       # The tab character must be in the format string and the
+       # format string must contain no variables.  Some shells will
+       # expand a tab if it is in an argument but others won't.
+       if [ -n "$_options" ] ; then
+               printf "%s\t%s\n" "$_ip" "$_options"
+       else
+               echo "$_ip"
+       fi
     done <<EOF
 $natgw_nodes
 EOF

Now with shiny comment explaining why it must be so!  :-)

This is essentially a revert to a previous version I had.

I am annoyed at myself because I was previously bitten by moving the
"\t" out of the format string and into an argument.  However, I didn't
remember this yesterday and broke it again...  :-(

peace & happiness,
martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ctdb-scripts-2.patch
Type: text/x-patch
Size: 82572 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20160719/6893acf9/ctdb-scripts-2-0001.bin>


More information about the samba-technical mailing list