detachLicense: Add logic to retry if there're no available licenses now

If there's "too many users" error message from eclair_licman, sleep some
time and retry a few times. Specific numbers will be tweaked over time.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Change-Id: Iaefefe82b4485984c403eddd583ff3b84fb38536
diff --git a/eclair-linaro/bin/detachLicense b/eclair-linaro/bin/detachLicense
index 89be4e8..b473bc4 100755
--- a/eclair-linaro/bin/detachLicense
+++ b/eclair-linaro/bin/detachLicense
@@ -9,13 +9,27 @@
 
 seconds=$1
 
-sudo su "${ECLAIR_LICENSE_USER}" -c "\"${ECLAIR_TOP_DIR}/bin/eclair_licman\" -d 38199 -t \"${seconds}\" -s u" >/tmp/eclair_licman.out 2>&1
-rc=$?
-cat /tmp/eclair_licman.out
-echo rc: $rc
+iter=0
 
-if [ "$rc" -ne 0 ] && grep -q "too many users" /tmp/eclair_licman.out; then
-    echo "TODO: retry"
-fi
+while [ $iter -lt 5 ]; do
+    if [ $iter -ne 0 ]; then
+        echo "$0: retry #${iter}"
+        sleep 60
+    fi
+
+    sudo su "${ECLAIR_LICENSE_USER}" -c "\"${ECLAIR_TOP_DIR}/bin/eclair_licman\" -d 38199 -t \"${seconds}\" -s u" >/tmp/eclair_licman.out 2>&1
+    rc=$?
+    cat /tmp/eclair_licman.out
+    echo rc: $rc
+
+    if [ "$rc" -ne 0 ] && grep -q "too many users" /tmp/eclair_licman.out; then
+        # Will be retrying
+        :
+    else
+        break
+    fi
+
+    iter=$(( $iter + 1 ))
+done
 
 exit $rc