summaryrefslogtreecommitdiff
path: root/indra/viewer_components/updater/scripts/linux/xmenity
diff options
context:
space:
mode:
Diffstat (limited to 'indra/viewer_components/updater/scripts/linux/xmenity')
-rwxr-xr-xindra/viewer_components/updater/scripts/linux/xmenity55
1 files changed, 55 insertions, 0 deletions
diff --git a/indra/viewer_components/updater/scripts/linux/xmenity b/indra/viewer_components/updater/scripts/linux/xmenity
new file mode 100755
index 0000000000..c0c033904c
--- /dev/null
+++ b/indra/viewer_components/updater/scripts/linux/xmenity
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+# @file xmenity
+# @author Nat Goodspeed
+# @date 2013-01-09
+# @brief Provide progress UI for bash scripts (e.g. update_install) using
+# zenity if available, xmessage if not.
+#
+# $LicenseInfo:firstyear=2013&license=viewerlgpl$
+# Copyright (c) 2013, Linden Research, Inc.
+# $/LicenseInfo$
+
+# This script invokes either zenity --progress or, if zenity is unavailable,
+# wraps xmessage in a zenity-like interface. That is its mutant power.
+# Pass $1 as the title for your zenity box. It is ignored by xmessage.
+# Send updates on stdin:
+# A line containing only a decimal integer from 0 - 100 sets that progress.
+# End with 100 to tell zenity to terminate.
+# A line starting with '#' replaces the progress text.
+# All other stdin lines are ignored.
+
+zenpath="$(which zenity)"
+if [ -n "$zenpath" -a -x "$zenpath" ]
+then # if executable zenity is on PATH, run that instead of this.
+ exec "$zenpath" --progress --title="$1" --auto-close --width=320 --height=120
+fi
+
+# Arriving here means we don't have zenity available. The remainder of this
+# script is the xmessage wrapper.
+
+# We operate by leaving one background xmessage process running. This is the
+# pid of that process.
+xmpid=""
+
+function clear_message {
+ [ -n "$xmpid" ] && kill $xmpid
+ xmpid=""
+}
+
+# Cancel any pending xmessage, regardless of how we exit.
+trap 'clear_message' EXIT
+
+while read line
+do # terminate like zenity --progress
+ [ "$line" == "100" ] && break
+ # ignore everything but replacement text
+ nohash="${line#'#'}"
+ # if stripping leading hash doesn't change line, it doesn't have one
+ [ "$nohash" == "$line" ] && continue
+ # clear any previous message
+ clear_message
+ # put up a new xmessage and capture its pid
+ xmessage -buttons OK:2 -center "$nohash" &
+ xmpid=$!
+done