Replace external waitfor script with a function
authorMartin Schwenke <martin@meltin.net>
Fri, 27 Jun 2014 01:45:49 +0000 (11:45 +1000)
committerMartin Schwenke <martin@meltin.net>
Wed, 2 Jul 2014 04:17:17 +0000 (14:17 +1000)
Signed-off-by: Martin Schwenke <martin@meltin.net>
Makefile
README
autocluster
autocluster.spec.in
base/all/usr/bin/waitfor [deleted file]
waitfor [deleted file]

index 45dff4084069e0773c36c45d78c19d30e27793ac..f39cb5cf6fa05bf9b226be78a2a5d916c6dc88eb 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,7 @@ install:      all
        mkdir -p $(DESTDIR)$(datadir)
        cp -a $(datas) $(DESTDIR)$(datadir)/
        mkdir -p $(DESTDIR)$(bindir)
-       install -m 755 vircmd waitfor $(DESTDIR)$(bindir) 
+       install -m 755 vircmd $(DESTDIR)$(bindir) 
        install -m 755 autocluster.hack $(DESTDIR)$(bindir)/autocluster
 
 debian/changelog:      debian/changelog.in Makefile .git/refs/heads/master
diff --git a/README b/README
index 9c229c50813df8ae3a49e74caf86d70344ab6b37..142d9a0d762b2edce2091a84318bc4356762c166 100644 (file)
--- a/README
+++ b/README
@@ -59,8 +59,8 @@ clusters generated by autocluster.
 
     Autocluster creates virtual machines that use libvirt to run under
     KVM.  This means that you will need to install both KVM and
-    libvirt on your host machine.  Expect is used by the "waitfor"
-    script and should be available for installation form your
+    libvirt on your host machine.  Expect is used by the waitfor()
+    function and should be available for installation from your
     distribution.
 
     For various distros:
index f742848dd38cf2bb32bc24a7b3b7836c5ec4e51e..3c8219f150cc338d394da426d31690e207a94449 100755 (executable)
@@ -96,6 +96,31 @@ announce ()
     echo ""
 }
 
+waitfor ()
+{
+    local file="$1"
+    local msg="$2"
+    local timeout="$3"
+
+    local tmpfile=$(mktemp)
+
+    cat <<EOF >"$tmpfile"
+spawn tail -n 10000 -f $file
+expect -timeout $timeout -re "$msg"
+EOF
+
+    export LANG=C
+    expect "$tmpfile"
+    rm -f "$tmpfile"
+
+    if ! grep -E "$msg" "$file" > /dev/null; then
+       echo "Failed to find \"$msg\" in \"$file\""
+       return 1
+    fi
+
+    return 0
+}
+
 ###############################
 
 # Indirectly call a function named by ${1}_${2}
index 777792bcf294ffc99fc771cde75ca2067845e5d0..5ff3b0b864c1ebac5e88de8015ce3aba8af6d875 100644 (file)
@@ -47,4 +47,3 @@ rm -rf $RPM_BUILD_ROOT
 %{_prefix}/share/autocluster/*
 %{_bindir}/autocluster
 %{_bindir}/vircmd
-%{_bindir}/waitfor
diff --git a/base/all/usr/bin/waitfor b/base/all/usr/bin/waitfor
deleted file mode 100755 (executable)
index cb296d3..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/bash
-# wait for a string to appear at the end of file
-# tridge@samba.org July 2008
-
-[ $# -lt 3 ] && {
-    cat <<EOF
-Usage: waitfor FILE MESSAGE TIMEOUT
-EOF
-exit 1
-}
-
-file="$1"
-msg="$2"
-timeout="$3"
-
-tmpfile=`mktemp`
-
-cat <<EOF > $tmpfile
-spawn tail -n 10000 -f $file
-expect -timeout $timeout "$msg"
-EOF
-
-expect $tmpfile
-rm -f $tmpfile
-
-if ! grep "$msg" $file > /dev/null; then
- echo "Failed to find \"$msg\" in $file"
- exit 1
-fi
-exit 0
diff --git a/waitfor b/waitfor
deleted file mode 100755 (executable)
index 7077c67..0000000
--- a/waitfor
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/bin/bash
-# wait for a string to appear at the end of file
-# tridge@samba.org July 2008
-
-[ $# -lt 3 ] && {
-    cat <<EOF
-Usage: waitfor FILE MESSAGE TIMEOUT
-EOF
-exit 1
-}
-
-file="$1"
-msg="$2"
-timeout="$3"
-
-tmpfile=`mktemp`
-
-cat <<EOF > $tmpfile
-spawn tail -n 10000 -f $file
-expect -timeout $timeout -re "$msg"
-EOF
-
-export LANG=C
-expect $tmpfile
-rm -f $tmpfile
-
-if ! grep -E "$msg" $file > /dev/null; then
- echo "Failed to find \"$msg\" in $file"
- exit 1
-fi
-exit 0