Add expect-file guest image script
authorReto Buerki <reet@codelabs.ch>
Thu, 24 Jan 2013 17:26:34 +0000 (18:26 +0100)
committerTobias Brunner <tobias@strongswan.org>
Tue, 19 Mar 2013 14:23:50 +0000 (15:23 +0100)
This script can be used in pretest.dat files to wait until a given file
appears.

testing/hosts/default/usr/local/bin/expect-file [new file with mode: 0755]

diff --git a/testing/hosts/default/usr/local/bin/expect-file b/testing/hosts/default/usr/local/bin/expect-file
new file mode 100755 (executable)
index 0000000..6921b66
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/bash
+#
+# Wait until a given file appears
+#
+# Params:
+# $1 - filename
+# $2 - maximum time to wait in seconds, default is 5 seconds
+
+if [[ $# -lt 1 || $# -gt 2 ]]
+then
+       echo "invalid arguments"
+       exit 1
+fi
+
+secs=$2
+[ ! $secs ] && secs=5
+
+let steps=$secs*10
+for i in `seq 1 $steps`
+do
+       # -f does not work for special files (e.g. UNIX domain sockets), use ls
+       # instead
+       ls $1 >/dev/null 2>&1
+       [ $? -eq 0 ] && exit 0
+       sleep 0.1
+done
+
+echo "File '$1' not available after $secs second(s)"
+exit 1