-
Notifications
You must be signed in to change notification settings - Fork 5
/
nxdialog.freenx
executable file
·298 lines (256 loc) · 7.26 KB
/
nxdialog.freenx
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/bin/bash
#
# Copyright (c) 2004 by Fabian Franz <[email protected]>
# (c) 2004 by Rick Stout <[email protected]>
#
# License: GPL, version 2
#
# Note: NX does not check the exit-code from nxclient,
# but we set it to a "good value" anyway in case
# it does check it someday.
#
# SVN: $Id: nxdialog 512 2008-03-10 23:01:03Z fabianx $
#
# ========================================================================
#JJK: borrowed from Aron Griffis
function requote {
declare arg
for arg; do
arg=$(printf '%q' "$arg")
printf '%s ' "${arg:-''}"
done
}
PARAMS=( "$@" )
INPUTS=$(requote "$@") #JJK: Save input parameter line...
TEMP=`getopt -a -o d: --long local,noautokill,dialog:,caption:,message:,display:,parent: -n $(basename $0) -- "$@"`
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"
DIALOG_TYPE="ok";
DIALOG_CAPTION=""
DIALOG_MESSAGE=""
DIALOG_LOCAL=""
DIALOG_NOAUTOKILL=""
DIALOG_PARENT="$PPID"
while true; do
case "$1" in
--dialog) DIALOG_TYPE="$2"; shift 2 ;;
--caption) DIALOG_CAPTION="$2"; shift 2 ;;
--message) DIALOG_MESSAGE="$2"; shift 2 ;;
--local) DIALOG_LOCAL="yes"; shift ;;
--noautokill) DIALOG_NOAUTOKILL="yes"; shift ;;
--display) DISPLAY="$2"; shift 2 ;;
--parent) DIALOG_PARENT="$2"; shift 2 ;;
--) shift ; break ;;
*) echo "Internal error!" ; exit 1; ;;
esac
done
export DISPLAY
# First check if the commercial nxclient is available and use it
# but check that it isn't this script to prevent a loop!
#
# Also check that not --printer was used, because the commercial
# client does not like large databases like used when ENABLE_FOOMATIC=1.
#
# This seems to be because the used sorting algorithm scales in O(n^2).
#
# This is now fixed in NXClient 3.0.0, but still people sometimes use
# older clients.
[ -x "/usr/bin/nxclient" ] && NXCLIENT="/usr/bin/nxclient"
[ -x "/usr/NX/bin/nxclient" ] && NXCLIENT="/usr/NX/bin/nxclient"
[ -z "$NXCLIENT" ] && NXCLIENT="/usr/NX/bin/nxclient"
[ -x "$NXCLIENT" ] && exec ${NXCLIENT} "${PARAMS[@]}"
if [ -x "/usr/bin/xvt" ] ; then
xterm_command="/usr/bin/xvt"
else
xterm_command=`which xterm`
fi
if [ -x /usr/bin/zenity ]; then
dialog_interface="zenity"
DIALOG=/usr/bin/zenity
# FIXME: This should be COMMAND_XDIALOG, ...
elif [ -x /usr/bin/Xdialog ]; then
dialog_interface="xdialog"
DIALOG=/usr/bin/Xdialog # just in case that we have no good path
elif [ -x /usr/bin/dialog ]; then
#JJK: Added 'dialog_interface=dialog' option because Xdialog not standard
#JJK: on some distros such as Fedora and xmessage won't handle long
#JJK: lists of ppd files while the combination of 'dialog' and 'xterm'
#JJK: should be present on most setups.
dialog_interface="dialog"
DIALOG=/usr/bin/dialog
if [ -z "$NXCLIENT_FIRST_TIME" ]; then
# Run only once in case of subdialogs. Capture result in tempfile
TMPFILE=$(mktemp /tmp/nxclient.XXXXX)
export NXCLIENT_FIRST_TIME=1
$xterm_command -geometry 120x24+100+100 +sb -title "NXclient" -e \
/bin/bash -c "$DIALOG --infobox 'Please wait...' 3 25; $0 $INPUTS | tee $TMPFILE" \
|| exit 1
#Need to recover the last line output (and not remove non-printing chars, because --stdout is used)
tail -1 $TMPFILE
rm -f $TMPFILE
exit 0
fi
else
dialog_interface="xmessage"
xmessage=$(which xmessage 2>/dev/null)
[ -z "$xmessage" ] && xmessage="/usr/X11R6/bin/xmessage"
fi
#
# xmessage dialog interface
#
xmessage_ok() {
$xmessage -buttons "Ok:0" -center "$DIALOG_MESSAGE"
return 0 # Give cancel on close ...
}
xmessage_yesno() {
$xmessage -buttons "Yes:2,No:0" -center "$DIALOG_MESSAGE"
}
xmessage_yesnosuspend() {
$xmessage -buttons "Suspend:3,Terminate:2,Cancel:0" -center "$DIALOG_MESSAGE"
}
xmessage_panic() {
$xmessage -buttons "Terminate:2,Cancel:0" -center "$DIALOG_MESSAGE"
}
xmessage_quit() {
$xmessage -buttons "Quit:0" -center "$DIALOG_MESSAGE"
return 0 # Give cancel on close ...
}
#
# zenity interface
#
zenity_ok() {
$DIALOG --info --title="$DIALOG_CAPTION" --text="$DIALOG_MESSAGE"
return 0 # Give cancel on close ...
}
zenity_yesno() {
$DIALOG --question --title="$DIALOG_CAPTION" --text="$DIALOG_MESSAGE"
RC=$?
[ $RC -eq 0 ] && return 2
[ $RC -eq 1 ] && return 0
}
zenity_yesnosuspend() {
Suspend="Disconnect (Suspend session)"
Terminate="Terminate (Log Out)"
ans=$($DIALOG --title="$DIALOG_CAPTION" \
--text="$DIALOG_MESSAGE Close this dialog to cancel." \
--list --radiolist --column "" --column "" \
TRUE "$Terminate" FALSE "$Suspend")
RC=$?
case $ans in
$Terminate)
return 2;
;;
$Suspend)
return 3;
esac
[ $RC -eq 1 ] && return 0
}
zenity_panic() {
$DIALOG --question --no-wrap --title="$DIALOG_CAPTION" \
--ok-label="Terminate" --cancel-label="Cancel" \
--text="$DIALOG_MESSAGE"
RC=$?
[ $RC -eq 0 ] && return 2
[ $RC -eq 1 ] && return 0
}
zenity_quit() {
$DIALOG --info --title="$DIALOG_CAPTION" --text="$DIALOG_MESSAGE"
return 0 # Give cancel on close ...
}
#"
# xdialog interface
#
xdialog_ok() {
$DIALOG --title "$DIALOG_CAPTION" --msgbox "$DIALOG_MESSAGE" 0 0
return 0 # Give cancel on close ...
}
xdialog_yesno() {
$DIALOG --title "$DIALOG_CAPTION" --yesno "$DIALOG_MESSAGE" 0 0
RC=$?
[ $RC -eq 0 ] && return 2
[ $RC -eq 1 ] && return 0
}
xdialog_yesnosuspend() {
$DIALOG --title "$DIALOG_CAPTION" --buttons-style text \
--ok-label "Suspend" --cancel-label "Terminate" \
--yesno "$DIALOG_MESSAGE Close this dialog to cancel." 400x150
RC=$?
[ $RC -eq 0 ] && return 3
[ $RC -eq 1 ] && return 2
}
xdialog_panic() {
$DIALOG --title "$DIALOG_CAPTION" --buttons-style text --default-no \
--ok-label "Terminate" --cancel-label "Cancel" \
--yesno "$DIALOG_MESSAGE" 0x0
RC=$?
[ $RC -eq 0 ] && return 2
[ $RC -eq 1 ] && return 0
}
xdialog_quit() {
$DIALOG --buttons-style text --ok-label "Quit" --title "$DIALOG_CAPTION" \
--msgbox "$DIALOG_MESSAGE" 0 0
return 0 # Give cancel on close ...
}
#JJK: dialog interface "
# These are analogous to the Xdialog functions with a few subtle
# syntax differences
#
dialog_ok() {
$DIALOG --stdout --title "$DIALOG_CAPTION" --msgbox "$DIALOG_MESSAGE" 0 0
return 0 # Give cancel on close ...
}
dialog_yesno() {
$DIALOG --stdout --title "$DIALOG_CAPTION" --yesno "$DIALOG_MESSAGE" 0 0
RC=$?
[ $RC -eq 0 ] && return 2
[ $RC -eq 1 ] && return 0
}
dialog_yesnosuspend() {
$DIALOG --stdout --title "$DIALOG_CAPTION" --yes-label "Suspend" \
--no-label "Terminate" \
--yesno "$DIALOG_MESSAGE\n\nPress 'Esc' to cancel." 8 60
RC=$?
[ $RC -eq 0 ] && return 3
[ $RC -eq 1 ] && return 2
}
dialog_panic() {
$DIALOG --stdout --title "$DIALOG_CAPTION" --defaultno \
--yes-label "Terminate" --no-label "Cancel" \
--yesno "$DIALOG_MESSAGE" 0 0
RC=$?
[ $RC -eq 0 ] && return 2
[ $RC -eq 1 ] && return 0
}
dialog_quit() {
$DIALOG --stdout --ok-label "Quit" --title "$DIALOG_CAPTION" \
--msgbox "$DIALOG_MESSAGE" 0 0
return 0 # Give cancel on close ...
}
#
# main case statement
#
case $DIALOG_TYPE in
ok)
${dialog_interface}_ok
;;
yesno)
${dialog_interface}_yesno
;;
yesnosuspend)
${dialog_interface}_yesnosuspend
;;
panic)
${dialog_interface}_panic
;;
quit)
${dialog_interface}_quit
;;
esac
#
# Time for exit code checks :)
#
RC=$?
[ $RC -eq 2 ] && kill -TERM $DIALOG_PARENT
[ $RC -eq 3 ] && kill -HUP $DIALOG_PARENT
exit 0