#!/bin/bash #Universal library for dialog and Xdialog. #This should work transparantly in textmode and grapical mode #(C)DatuX 2005 - all rights reserved if [ ! "$LANG" ]; then export LANG="en" fi source ./lang_$LANG.sh || exit 1 WAIT=1 TIMEOUT="" BUTTONS="" NEXTCANCEL="--ok-label '`_Next` >>' --cancel-label '`_Cancel`'" YESNO="--ok-label '`_Yes`' --cancel-label '`_No`'" showlicense() { #kill old stuff kill $PID &>/dev/null PID= BG="" if [ $WAIT == "0" ]; then BG='&'; fi if [ $DISPLAY ]; then eval Xdialog --cr-wrap --ok-label "'`_Accept` >>'" --no-close --cancel-label "'`_NotAccepted`'" --left --stdout --title "'$TITLE'" $BUTTONS "$@" $TIMEOUT $BG else BT="`_Installation`"; eval dialog --cr-wrap --ok-label "'`_Accept` >>'" --cancel-label "'`_NotAccepted`'" --yes-label "`_Yes`" --no-label "`_No`" --stdout --backtitle "'$BT'" "$DEF" --title "'$TITLE'" "$@" $BG fi RET=$? PID=$! return $RET } dialogrun() { #kill old stuff kill $PID &>/dev/null PID= BG="" if [ $WAIT == "0" ]; then BG='&'; fi if [ $DISPLAY ]; then eval Xdialog --cr-wrap --separator '\ ' --left --stdout --title "'$TITLE'" $BUTTONS "$@" $TIMEOUT $BG else BT="`_Installation`"; eval dialog --cr-wrap --yes-label "`_Yes`" --no-label "`_No`" --stdout --backtitle "'$BT'" "$DEF" --title "'$TITLE'" "$@" $BG fi RET=$? PID=$! return $RET } menu() { dialogrun $NEXTCANCEL --menu "'$QUERY'" 15 70 5 "$@" return $? } progress() { WAIT=0 BUTTONS="--no-buttons" TIMEOUT="999999" dialogrun $NEXTCANCEL --infobox "\"$@\"" 0 0 WAIT=1 BUTTONS="" TIMEOUT="" sleep 1; } msgbox() { dialogrun $NEXTCANCEL --msgbox "\"$@\"" 0 0 } inputbox() { dialogrun $NEXTCANCEL --no-cancel --inputbox "'$QUERY'" 0 0 $1 } accept() { showlicense $YESNO --yesno "\"$@\"" 0 0 } yesno() { dialogrun $YESNO --yesno "\"$@\"" 0 0 } nextcancel() { dialogrun $NEXTCANCEL --yesno "\"$@\"" 0 0 } abort() { dialogrun $NEXTCANCEL --msgbox "\"$@\n`_InstallationAborted`\"" 0 0 exit 1; } gauge() { dialogrun $NEXTCANCEL --gauge "\"$@\"" 10 70 } license() { showlicense $NEXTCANCEL --textbox "\"$@\"" 20 70 } showfile() { dialogrun $NEXTCANCEL --textbox "\"$@\"" 20 70 } checklist() { dialogrun $NEXTCANCEL --separate-output --checklist "'$QUERY'" 15 70 8 "$@" } #replace newlines with \n quote() { tr '\n' '#' <<<"$1" |sed 's/#/\\n/g' |sed "s/'//g" } #enter a temporary shell, with extra helptext for prompt shell() { if [ "$DISPLAY" ]; then PS1="$*\n# " xterm -e bash --noprofile -l else PS1="$*\n# " bash --noprofile -l fi } execute() { if [ "$DISPLAY" ]; then echo 1 > /tmp/exitcode xterm -T "`_Processing`" -e "$* ; echo \$? > /tmp/exitcode" EXITCODE=`cat /tmp/exitcode` return $EXITCODE else $* return $? fi }