[1] | 1 | #########################################################################
|
---|
| 2 | #
|
---|
| 3 | # Interaction Subroutines
|
---|
| 4 | #
|
---|
| 5 | #########################################################################
|
---|
[27] | 6 | #
|
---|
| 7 | # Copyright Rainer Wichmann (2005)
|
---|
| 8 | #
|
---|
| 9 | # License Information:
|
---|
| 10 | # This program is free software; you can redistribute it and/or modify
|
---|
| 11 | # it under the terms of the GNU General Public License as published by
|
---|
| 12 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 | # (at your option) any later version.
|
---|
| 14 | #
|
---|
| 15 | # This program is distributed in the hope that it will be useful,
|
---|
| 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | # GNU General Public License for more details.
|
---|
| 19 | #
|
---|
| 20 | # You should have received a copy of the GNU General Public License
|
---|
| 21 | # along with this program; if not, write to the Free Software
|
---|
| 22 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 23 | #
|
---|
[1] | 24 |
|
---|
| 25 | # print without newline
|
---|
| 26 | #
|
---|
| 27 | printASK() {
|
---|
| 28 | echo $ECHO_N "$@ $ECHO_C"
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | # find a 'dialog' program
|
---|
| 32 | #
|
---|
| 33 | findDIALOG() {
|
---|
| 34 |
|
---|
| 35 | if test x"$DIALOG" = xno
|
---|
| 36 | then
|
---|
| 37 | DIALOG=""; return 0
|
---|
| 38 | elif test -n "$DIALOG"
|
---|
| 39 | then
|
---|
| 40 | return 0
|
---|
| 41 | fi
|
---|
| 42 |
|
---|
| 43 | PATH=/usr/local/bin:/usr/local/sbin:$PATH; export PATH
|
---|
| 44 | X="$PATH"
|
---|
| 45 | progs="dialog";
|
---|
| 46 | OLD_IFS=${IFS}
|
---|
| 47 | IFS=':'; export IFS
|
---|
| 48 | for dir in $X; do
|
---|
| 49 | for dia in $progs; do
|
---|
| 50 | dialog="$dir/$dia"
|
---|
| 51 | if (test -f "$dialog" || test -f "$dialog.exe")
|
---|
| 52 | then
|
---|
| 53 | if "$dialog" 2>&1 | grep tailbox >/dev/null 2>&1
|
---|
| 54 | then
|
---|
| 55 | IFS=${OLD_IFS}; export IFS
|
---|
| 56 | DIALOG="$dialog"; export DIALOG
|
---|
| 57 | return 0
|
---|
| 58 | fi
|
---|
| 59 | fi
|
---|
| 60 | done
|
---|
| 61 | done
|
---|
| 62 | IFS=${OLD_IFS}; export IFS
|
---|
| 63 | DIALOG=""; export DIALOG
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 |
|
---|
| 67 | # prompt user for yes/no
|
---|
| 68 | #
|
---|
| 69 | promptYESNO() {
|
---|
| 70 | if test $# -lt 1
|
---|
| 71 | then
|
---|
| 72 | printFATAL "promptYESNO: insufficient arguments"
|
---|
| 73 | fi
|
---|
| 74 |
|
---|
| 75 | if test $silent -gt 1
|
---|
| 76 | then
|
---|
| 77 | YESNO=y; export YESNO
|
---|
| 78 | return 0
|
---|
| 79 | fi
|
---|
| 80 |
|
---|
| 81 | DEFAULT=""
|
---|
| 82 | case "$2" in
|
---|
| 83 | [yY]|[yY][eE][sS])
|
---|
| 84 | DEFAULT=y ;;
|
---|
| 85 | [nN]|[nN][oO])
|
---|
| 86 | DEFAULT=n ;;
|
---|
| 87 | esac
|
---|
| 88 |
|
---|
| 89 | YESNO=""
|
---|
| 90 |
|
---|
| 91 | if test -n "$DIALOG"
|
---|
| 92 | then
|
---|
| 93 |
|
---|
| 94 | if test x"$assumeyes" = x1
|
---|
| 95 | then
|
---|
| 96 | YESNO="$DEFAULT"; export YESNO
|
---|
| 97 | return 0
|
---|
| 98 | fi
|
---|
| 99 |
|
---|
| 100 | "$DIALOG" --title "deploy.sh $version" --yesno "$1" 10 75 2>"$tmpF"
|
---|
| 101 | mtest=$?
|
---|
| 102 | if test x"$mtest" = "x-1"
|
---|
| 103 | then
|
---|
| 104 | printFATAL "promptYESNO: something went wrong"
|
---|
| 105 | elif test x"$mtest" = x0
|
---|
| 106 | then
|
---|
| 107 | YESNO=y
|
---|
| 108 | else
|
---|
| 109 | YESNO=n
|
---|
| 110 | fi
|
---|
| 111 | else
|
---|
| 112 | while :
|
---|
| 113 | do
|
---|
| 114 | if test x"$DEFAULT" = xy
|
---|
| 115 | then
|
---|
| 116 | printASK "$1 (Y/n) ?"
|
---|
| 117 | elif test x"$DEFAULT" = xn
|
---|
| 118 | then
|
---|
| 119 | printASK "$1 (N/y) ?"
|
---|
| 120 | else
|
---|
| 121 | printASK "$1 (y/n) ?"
|
---|
| 122 | fi
|
---|
| 123 |
|
---|
| 124 | if test x"$assumeyes" = x1
|
---|
| 125 | then
|
---|
| 126 | YESNO="$DEFAULT"; export YESNO
|
---|
| 127 | echo "$DEFAULT"
|
---|
| 128 | return 0
|
---|
| 129 | fi
|
---|
| 130 |
|
---|
| 131 | read YESNO
|
---|
| 132 | if test -z "$YESNO"
|
---|
| 133 | then
|
---|
| 134 | YESNO="$DEFAULT"
|
---|
| 135 | fi
|
---|
| 136 |
|
---|
| 137 | case "$YESNO" in
|
---|
| 138 | [yY]|[yY][eE][sS])
|
---|
| 139 | YESNO=y; break ;;
|
---|
| 140 | [nN]|[nN][oO])
|
---|
| 141 | YESNO=n; break ;;
|
---|
| 142 | *)
|
---|
| 143 | YESNO="" ;;
|
---|
| 144 | esac
|
---|
| 145 | done
|
---|
| 146 | fi
|
---|
| 147 | export YESNO
|
---|
| 148 | return 0
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | # get user input from tmp file
|
---|
| 152 | #
|
---|
| 153 | getINPUT() {
|
---|
| 154 | INPUT=`cat $tmpF`
|
---|
| 155 | export INPUT
|
---|
| 156 | return 0
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | # info box
|
---|
| 160 | #
|
---|
| 161 | promptINFO() {
|
---|
| 162 | if test $# -lt 1
|
---|
| 163 | then
|
---|
| 164 | printFATAL "promptINPUT: insufficient arguments"
|
---|
| 165 | fi
|
---|
| 166 |
|
---|
| 167 | if test x"$silent" != x0
|
---|
| 168 | then
|
---|
| 169 | return 0
|
---|
| 170 | fi
|
---|
| 171 |
|
---|
| 172 | if test -n "$DIALOG"
|
---|
| 173 | then
|
---|
| 174 | "$DIALOG" --title "deploy.sh $version" --sleep 2 --infobox "$1" 8 75
|
---|
| 175 | else
|
---|
| 176 | echo $1
|
---|
| 177 | fi
|
---|
| 178 | return 0
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | # prompt user for input
|
---|
| 182 | #
|
---|
| 183 | promptINPUT() {
|
---|
| 184 | if test $# -lt 1
|
---|
| 185 | then
|
---|
| 186 | printFATAL "promptINPUT: insufficient arguments"
|
---|
| 187 | fi
|
---|
| 188 |
|
---|
| 189 | if test $assumeyes -gt 0
|
---|
| 190 | then
|
---|
| 191 | printFATAL "promptINPUT: user interaction required"
|
---|
| 192 | fi
|
---|
| 193 |
|
---|
| 194 | INPUT=""
|
---|
| 195 | DEFAULT="$2"
|
---|
| 196 |
|
---|
| 197 | if test -n "$DIALOG"
|
---|
| 198 | then
|
---|
| 199 | "$DIALOG" --title "deploy.sh $version" --inputbox "$1" 16 75 "$2" 2>"$tmpF"
|
---|
| 200 | mtest=$?
|
---|
| 201 | if test x"$mtest" = "x1"
|
---|
| 202 | then
|
---|
| 203 | # cancel button
|
---|
| 204 | (exit 0); exit 0;
|
---|
| 205 | fi
|
---|
| 206 | if test x"$mtest" = "x-1"
|
---|
| 207 | then
|
---|
| 208 | printFATAL "promptINPUT: something went wrong"
|
---|
| 209 | else
|
---|
| 210 | getINPUT
|
---|
| 211 | fi
|
---|
| 212 | else
|
---|
| 213 |
|
---|
| 214 | while :
|
---|
| 215 | do
|
---|
| 216 | if test -z "$DEFAULT"
|
---|
| 217 | then
|
---|
| 218 | printASK "$1 ?"
|
---|
| 219 | else
|
---|
| 220 | printASK "$1 ? $DEFAULT"
|
---|
| 221 | fi
|
---|
| 222 |
|
---|
| 223 | read INPUT
|
---|
| 224 |
|
---|
| 225 | if test -z "$INPUT"
|
---|
| 226 | then
|
---|
| 227 | if test -n "$DEFAULT"
|
---|
| 228 | then
|
---|
| 229 | locINPUT="$DEFAULT"
|
---|
| 230 | break
|
---|
| 231 | fi
|
---|
| 232 | elif test -n "$INPUT"
|
---|
| 233 | then
|
---|
| 234 | break
|
---|
| 235 | fi
|
---|
| 236 | done
|
---|
| 237 | export INPUT
|
---|
| 238 | fi
|
---|
| 239 | return 0
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | # get MENU from tmp file
|
---|
| 243 | #
|
---|
| 244 | getMENU() {
|
---|
| 245 | MENU=`cat $tmpF`
|
---|
| 246 | export MENU
|
---|
| 247 | return 0
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 | # prompt user for options from menu
|
---|
| 251 | #
|
---|
| 252 | promptMENU() {
|
---|
| 253 | if test $# -lt 2
|
---|
| 254 | then
|
---|
| 255 | printFATAL "promptMENU: insufficient arguments"
|
---|
| 256 | fi
|
---|
| 257 |
|
---|
| 258 | if test $assumeyes -gt 0
|
---|
| 259 | then
|
---|
| 260 | printFATAL "promptMENU: user interaction required"
|
---|
| 261 | fi
|
---|
| 262 |
|
---|
| 263 | TITLE="$1"
|
---|
| 264 | shift
|
---|
| 265 |
|
---|
| 266 | if test -n "$DIALOG"
|
---|
| 267 | then
|
---|
| 268 | #command="'$DIALOG' '--title' \\'deploy.sh $version\\' '--backtitle'"
|
---|
| 269 | #command="$command \'$TITLE\' '--menu' \'$TITLE\' '16' '75' '$#'"
|
---|
| 270 |
|
---|
| 271 | argc=$#
|
---|
| 272 | if test $argc -gt 7
|
---|
| 273 | then
|
---|
| 274 | argc=7
|
---|
| 275 | fi
|
---|
| 276 |
|
---|
| 277 | command="'$1' '' 'on'"
|
---|
| 278 | shift
|
---|
| 279 |
|
---|
| 280 | for item
|
---|
| 281 | do
|
---|
| 282 | command="$command '$item' '' 'off'"
|
---|
| 283 | done
|
---|
| 284 |
|
---|
| 285 | command="$command "
|
---|
| 286 |
|
---|
| 287 | # printFATAL "$command"
|
---|
| 288 | eval $DIALOG '--title' \'deploy.sh $version\' '--backtitle' \'$TITLE\' '--radiolist' \'$TITLE\' '16' '75' $argc $command 2>"$tmpF"
|
---|
| 289 |
|
---|
| 290 | mtest=$?
|
---|
| 291 |
|
---|
| 292 | if test x"$mtest" = "x1"
|
---|
| 293 | then
|
---|
| 294 | # cancel button
|
---|
| 295 | (exit 0); exit 0;
|
---|
| 296 | fi
|
---|
| 297 | if test x"$mtest" = "x-1"; then
|
---|
| 298 | printFATAL "promptMENU: something went wrong"
|
---|
| 299 | else
|
---|
| 300 | getMENU
|
---|
| 301 | fi
|
---|
| 302 | else
|
---|
| 303 |
|
---|
| 304 | MENU=""
|
---|
| 305 | INPUT=""
|
---|
| 306 |
|
---|
| 307 | while :
|
---|
| 308 | do
|
---|
| 309 | clear
|
---|
| 310 | echo
|
---|
| 311 | echo "$TITLE"
|
---|
| 312 | echo
|
---|
| 313 | echo " 1) $1"
|
---|
| 314 | test -n "$2" && echo " 2) $2"
|
---|
| 315 | test -n "$3" && echo " 3) $3"
|
---|
| 316 | test -n "$4" && echo " 4) $4"
|
---|
| 317 | test -n "$5" && echo " 5) $5"
|
---|
| 318 | test -n "$6" && echo " 6) $6"
|
---|
| 319 | test -n "$7" && echo " 7) $7"
|
---|
| 320 | test -n "$8" && echo " 8) $8"
|
---|
| 321 | test -n "$9" && echo " 9) $9"
|
---|
| 322 | echo
|
---|
| 323 | printASK "Please enter your choice: "
|
---|
| 324 |
|
---|
| 325 | read INPUT
|
---|
| 326 |
|
---|
| 327 | if echo "$INPUT" | grep '[^0123456789]' >/dev/null 2>&1
|
---|
| 328 | then
|
---|
| 329 | :
|
---|
| 330 | elif test $INPUT -gt $#
|
---|
| 331 | then
|
---|
| 332 | :
|
---|
| 333 | else
|
---|
| 334 | break
|
---|
| 335 | fi
|
---|
| 336 | done
|
---|
| 337 |
|
---|
| 338 | case "$INPUT" in
|
---|
| 339 | 1) MENU="$1"; break ;;
|
---|
| 340 | 2) MENU="$2"; break ;;
|
---|
| 341 | 3) MENU="$3"; break ;;
|
---|
| 342 | 4) MENU="$4"; break ;;
|
---|
| 343 | 5) MENU="$5"; break ;;
|
---|
| 344 | 6) MENU="$6"; break ;;
|
---|
| 345 | 7) MENU="$7"; break ;;
|
---|
| 346 | 8) MENU="$8"; break ;;
|
---|
| 347 | 9) MENU="$9"; break ;;
|
---|
| 348 | esac
|
---|
| 349 |
|
---|
| 350 | export MENU
|
---|
| 351 | fi
|
---|
| 352 | return 0
|
---|
| 353 | }
|
---|
| 354 |
|
---|