]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/dialog/samples/inputmenu2
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / dialog / samples / inputmenu2
1 #! /bin/sh
2 # $Id: inputmenu2,v 1.9 2012/07/01 01:00:34 tom Exp $
3 #
4 # "inputmenu1" with defaultitem, help-button.
5
6 . ./setup-vars
7
8 backtitle="An Example for the use of --inputmenu:"
9
10 ids=`id|sed -e 's/([^)]*)//g'`
11 uid=`echo "$ids" | sed -e 's/^uid=//' -e 's/ .*//'`
12 gid=`echo "$ids" | sed -e 's/^.* gid=//' -e 's/ .*//'`
13
14 user="$USER"
15 home="$HOME"
16
17 returncode=0
18 defaultitem="Username:"
19 while test $returncode != 1 && test $returncode != 250
20 do
21 exec 3>&1
22 value=`$DIALOG --clear --ok-label "Create" \
23           --backtitle "$backtitle" \
24           --help-button \
25           --help-label "Script" \
26           --default-item "$defaultitem" "$@" \
27           --inputmenu "Originally I designed --inputmenu for a \
28 configuration purpose. Here is a possible piece of a configuration program." \
29 20 60 10 \
30         "Username:"     "$user" \
31         "UID:"          "$uid"  \
32         "GID:"          "$gid"  \
33         "HOME:"         "$home" \
34 2>&1 1>&3`
35 returncode=$?
36 exec 3>&-
37
38         case $returncode in
39         $DIALOG_HELP)
40                 "$DIALOG" \
41                 --textbox "$0" 0 0
42                 ;;
43         $DIALOG_CANCEL)
44                 "$DIALOG" \
45                 --clear \
46                 --backtitle "$backtitle" \
47                 --yesno "Really quit?" 10 30
48                 case $? in
49                 $DIALOG_OK)
50                         break
51                         ;;
52                 $DIALOG_CANCEL)
53                         returncode=99
54                         ;;
55                 esac
56                 ;;
57         $DIALOG_OK)
58                 "$DIALOG" \
59                 --clear \
60                 --backtitle "$backtitle" \
61                 --msgbox "useradd \n\
62                         -d $home \n\
63                         -u $uid \n\
64                         -g $gid \n\
65                         $user" 10 40
66                 ;;
67         $DIALOG_EXTRA)
68                 tag=`echo "$value" |sed -e 's/^RENAMED //' -e 's/:.*/:/'`
69                 item=`echo "$value" |sed -e 's/^[^:]*:[ ]*//' -e 's/[ ]*$//'`
70
71                 case "$tag" in
72                 Username:)
73                         user="$item"
74                         ;;
75                 UID:)
76                         uid="$item"
77                         ;;
78                 GID:)
79                         gid="$item"
80                         ;;
81                 HOME:)
82                         home="$item"
83                         ;;
84                 *)
85                         tag=
86                         ;;
87                 esac
88                 test -n "$tag" && defaultitem="$tag"
89                 ;;
90
91         $DIALOG_ESC)
92                 echo "ESC pressed."
93                 break
94                 ;;
95
96         esac
97 done