blob: c0c033904c11f626b93b612d1d0b0a095b586a79 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
|