#!/bin/bash # # Copyright (c) 2004 by Fabian Franz # (c) 2004 by Rick Stout # # 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