[c5c522c] | 1 | #!/bin/bash |
---|
| 2 | #Universal library for dialog and Xdialog. |
---|
| 3 | #This should work transparantly in textmode and grapical mode |
---|
| 4 | #(C)DatuX 2005 - all rights reserved |
---|
| 5 | |
---|
| 6 | if [ ! "$LANG" ]; then |
---|
| 7 | export LANG="en" |
---|
| 8 | fi |
---|
| 9 | source ./lang_$LANG.sh || exit 1 |
---|
| 10 | |
---|
| 11 | WAIT=1 |
---|
| 12 | TIMEOUT="" |
---|
| 13 | BUTTONS="" |
---|
| 14 | NEXTCANCEL="--ok-label '`_Next` >>' --cancel-label '`_Cancel`'" |
---|
| 15 | YESNO="--ok-label '`_Yes`' --cancel-label '`_No`'" |
---|
| 16 | |
---|
| 17 | showlicense() |
---|
| 18 | { |
---|
| 19 | #kill old stuff |
---|
| 20 | kill $PID &>/dev/null |
---|
| 21 | PID= |
---|
| 22 | BG="" |
---|
| 23 | if [ $WAIT == "0" ]; then |
---|
| 24 | BG='&'; |
---|
| 25 | fi |
---|
| 26 | |
---|
| 27 | if [ $DISPLAY ]; then |
---|
| 28 | eval Xdialog --cr-wrap --ok-label "'`_Accept` >>'" --no-close --cancel-label "'`_NotAccepted`'" --left --stdout --title "'$TITLE'" $BUTTONS "$@" $TIMEOUT $BG |
---|
| 29 | else |
---|
| 30 | BT="`_Installation`"; |
---|
| 31 | eval dialog --cr-wrap --ok-label "'`_Accept` >>'" --cancel-label "'`_NotAccepted`'" --yes-label "`_Yes`" --no-label "`_No`" --stdout --backtitle "'$BT'" "$DEF" --title "'$TITLE'" "$@" $BG |
---|
| 32 | fi |
---|
| 33 | RET=$? |
---|
| 34 | PID=$! |
---|
| 35 | return $RET |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | dialogrun() |
---|
| 40 | { |
---|
| 41 | #kill old stuff |
---|
| 42 | kill $PID &>/dev/null |
---|
| 43 | PID= |
---|
| 44 | BG="" |
---|
| 45 | if [ $WAIT == "0" ]; then |
---|
| 46 | BG='&'; |
---|
| 47 | fi |
---|
| 48 | |
---|
| 49 | if [ $DISPLAY ]; then |
---|
| 50 | eval Xdialog --cr-wrap --separator '\ ' --left --stdout --title "'$TITLE'" $BUTTONS "$@" $TIMEOUT $BG |
---|
| 51 | else |
---|
| 52 | BT="`_Installation`"; |
---|
| 53 | eval dialog --cr-wrap --yes-label "`_Yes`" --no-label "`_No`" --stdout --backtitle "'$BT'" "$DEF" --title "'$TITLE'" "$@" $BG |
---|
| 54 | fi |
---|
| 55 | RET=$? |
---|
| 56 | PID=$! |
---|
| 57 | return $RET |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | menu() |
---|
| 61 | { |
---|
| 62 | dialogrun $NEXTCANCEL --menu "'$QUERY'" 15 70 5 "$@" |
---|
| 63 | return $? |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | progress() |
---|
| 67 | { |
---|
| 68 | WAIT=0 |
---|
| 69 | BUTTONS="--no-buttons" |
---|
| 70 | TIMEOUT="999999" |
---|
| 71 | dialogrun $NEXTCANCEL --infobox "\"$@\"" 0 0 |
---|
| 72 | WAIT=1 |
---|
| 73 | BUTTONS="" |
---|
| 74 | TIMEOUT="" |
---|
| 75 | sleep 1; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | msgbox() |
---|
| 79 | { |
---|
| 80 | dialogrun $NEXTCANCEL --msgbox "\"$@\"" 0 0 |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | inputbox() |
---|
| 84 | { |
---|
| 85 | dialogrun $NEXTCANCEL --no-cancel --inputbox "'$QUERY'" 0 0 $1 |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | accept() |
---|
| 89 | { |
---|
| 90 | showlicense $YESNO --yesno "\"$@\"" 0 0 |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | yesno() |
---|
| 94 | { |
---|
| 95 | dialogrun $YESNO --yesno "\"$@\"" 0 0 |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | nextcancel() |
---|
| 99 | { |
---|
| 100 | dialogrun $NEXTCANCEL --yesno "\"$@\"" 0 0 |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | abort() |
---|
| 104 | { |
---|
| 105 | dialogrun $NEXTCANCEL --msgbox "\"$@\n`_InstallationAborted`\"" 0 0 |
---|
| 106 | exit 1; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | gauge() |
---|
| 110 | { |
---|
| 111 | dialogrun $NEXTCANCEL --gauge "\"$@\"" 10 70 |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | license() |
---|
| 115 | { |
---|
| 116 | showlicense $NEXTCANCEL --textbox "\"$@\"" 20 70 |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | showfile() |
---|
| 120 | { |
---|
| 121 | dialogrun $NEXTCANCEL --textbox "\"$@\"" 20 70 |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | checklist() |
---|
| 125 | { |
---|
| 126 | dialogrun $NEXTCANCEL --separate-output --checklist "'$QUERY'" 15 70 8 "$@" |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | #replace newlines with \n |
---|
| 130 | quote() |
---|
| 131 | { |
---|
| 132 | tr '\n' '#' <<<"$1" |sed 's/#/\\n/g' |sed "s/'//g" |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | #enter a temporary shell, with extra helptext for prompt |
---|
| 136 | shell() |
---|
| 137 | { |
---|
| 138 | if [ "$DISPLAY" ]; then |
---|
| 139 | PS1="$*\n# " xterm -e bash --noprofile -l |
---|
| 140 | else |
---|
| 141 | PS1="$*\n# " bash --noprofile -l |
---|
| 142 | fi |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | execute() |
---|
| 146 | { |
---|
| 147 | if [ "$DISPLAY" ]; then |
---|
| 148 | echo 1 > /tmp/exitcode |
---|
| 149 | xterm -T "`_Processing`" -e "$* ; echo \$? > /tmp/exitcode" |
---|
| 150 | EXITCODE=`cat /tmp/exitcode` |
---|
| 151 | return $EXITCODE |
---|
| 152 | else |
---|
| 153 | $* |
---|
| 154 | return $? |
---|
| 155 | fi |
---|
| 156 | } |
---|
| 157 | |
---|