source: install/dialoglib.sh @ ab298e7

Last change on this file since ab298e7 was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100755
File size: 2.7 KB
Line 
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
6if [ ! "$LANG" ]; then
7        export LANG="en"
8fi
9source ./lang_$LANG.sh || exit 1
10
11WAIT=1
12TIMEOUT=""
13BUTTONS=""
14NEXTCANCEL="--ok-label '`_Next` >>' --cancel-label '`_Cancel`'"
15YESNO="--ok-label '`_Yes`' --cancel-label '`_No`'"
16
17showlicense()
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
39dialogrun()
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
60menu()
61{
62        dialogrun $NEXTCANCEL --menu "'$QUERY'" 15 70 5 "$@"
63        return $?
64}
65
66progress()
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
78msgbox()
79{
80        dialogrun $NEXTCANCEL --msgbox "\"$@\"" 0 0
81}
82
83inputbox()
84{
85        dialogrun $NEXTCANCEL --no-cancel --inputbox "'$QUERY'" 0 0 $1
86}
87
88accept()
89{       
90        showlicense $YESNO --yesno "\"$@\"" 0 0
91}
92       
93yesno()
94{
95        dialogrun $YESNO --yesno "\"$@\"" 0 0
96}
97
98nextcancel()
99{
100        dialogrun $NEXTCANCEL --yesno "\"$@\"" 0 0
101}
102
103abort()
104{
105        dialogrun $NEXTCANCEL --msgbox "\"$@\n`_InstallationAborted`\"" 0 0
106        exit 1;
107}
108
109gauge()
110{
111        dialogrun $NEXTCANCEL --gauge "\"$@\"" 10 70
112}
113
114license()
115{
116        showlicense $NEXTCANCEL --textbox "\"$@\"" 20 70
117}
118
119showfile()
120{
121        dialogrun $NEXTCANCEL --textbox "\"$@\"" 20 70
122}
123
124checklist()
125{
126        dialogrun $NEXTCANCEL --separate-output --checklist "'$QUERY'" 15 70 8 "$@"
127}
128
129#replace newlines with \n
130quote()
131{
132        tr '\n' '#' <<<"$1" |sed 's/#/\\n/g' |sed "s/'//g"
133}
134
135#enter a temporary shell, with extra helptext for prompt
136shell()
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
145execute()
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
Note: See TracBrowser for help on using the repository browser.