scripts: Provide mktemp function for platforms without mktemp command
authorMartin Schwenke <martin@meltin.net>
Sat, 25 May 2013 09:57:24 +0000 (19:57 +1000)
committerMartin Schwenke <martin@meltin.net>
Mon, 27 May 2013 05:14:33 +0000 (15:14 +1000)
This is needed for AIX and possibly others.

Also provide a cheaper mktemp function is needed in the run_tests
script.

Signed-off-by: Martin Schwenke <martin@meltin.net>
config/functions
tests/scripts/run_tests

index 5778420f08a350e744c2e406579f40461e659573..498c94e5b7c732fd5e1ffc66cf24180fe434da1f 100755 (executable)
@@ -1425,6 +1425,32 @@ iptables()
        flock -w 30 $CTDB_VARDIR/iptables-ctdb.flock /sbin/iptables "$@"
 }
 
+# AIX (and perhaps others?) doesn't have mktemp
+if ! which mktemp >/dev/null 2>&1 ; then
+    mktemp ()
+    {
+       _dir=false
+       if [ "$1" = "-d" ] ; then
+           _dir=true
+           shift
+       fi
+       _d="${TMPDIR:-/tmp}"
+       _hex10=$(dd if=/dev/urandom count=20 2>/dev/null | \
+           md5sum | \
+           sed -e 's@\(..........\).*@\1@')
+       _t="${_d}/tmp.${_hex10}"
+       (
+           umask 077
+           if $_dir ; then
+               mkdir "$_t"
+           else
+               >"$_t"
+           fi
+       )
+       echo "$_t"
+    }
+fi
+
 ########################################################
 # tickle handling
 ########################################################
index 35db1963615d20ad7b514ceca5a1aac22b114f3f..13d211a7f0963475ada710a5c5b3ee139ce2f3df 100755 (executable)
@@ -143,6 +143,27 @@ summary=""
 rows=$(if tty -s ; then stty size ; else echo x 80 ; fi | sed -e 's@.* @@' -e 's@^0$@80@')
 ww=$((rows - 7))
 
+if ! which mktemp >/dev/null 2>&1 ; then
+    # Not perfect, but it will do...
+    mktemp ()
+    {
+       _dir=false
+       if [ "$1" = "-d" ] ; then
+           _dir=true
+       fi
+       _t="${TMPDIR:-/tmp}/tmp.$$.$RANDOM"
+       (
+           umask 077
+           if $_dir ; then
+               mkdir "$_t"
+           else
+               >"$_t"
+           fi
+       )
+       echo "$_t"
+    }
+fi
+
 tf=$(mktemp)
 sf=$(mktemp)