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