]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/dialog/samples/inputmenu1
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / dialog / samples / inputmenu1
1 #! /bin/sh
2 # $Id: inputmenu1,v 1.9 2012/07/01 00:59:54 tom Exp $
3 #
4 # "inputmenu" rewritten into Bourne shell.
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 while test $returncode != 1 && test $returncode != 250
19 do
20 exec 3>&1
21 value=`$DIALOG --clear --ok-label "Create" \
22           --backtitle "$backtitle" "$@" \
23           --inputmenu "Originally I designed --inputmenu for a \
24 configuration purpose. Here is a possible piece of a configuration program." \
25 20 50 10 \
26         "Username:"     "$user" \
27         "UID:"          "$uid" \
28         "GID:"          "$gid" \
29         "HOME:"         "$home" \
30 2>&1 1>&3`
31 returncode=$?
32 exec 3>&-
33
34         case $returncode in
35         $DIALOG_CANCEL)
36                 "$DIALOG" \
37                 --clear \
38                 --backtitle "$backtitle" \
39                 --yesno "Really quit?" 10 30
40                 case $? in
41                 $DIALOG_OK)
42                         break
43                         ;;
44                 $DIALOG_CANCEL)
45                         returncode=99
46                         ;;
47                 esac
48                 ;;
49         $DIALOG_OK)
50                 "$DIALOG" \
51                 --clear \
52                 --backtitle "$backtitle" \
53                 --msgbox "useradd \n\
54                         -d $home \n\
55                         -u $uid \n\
56                         -g $gid \n\
57                         $user" 10 40
58                 ;;
59         $DIALOG_EXTRA)
60                 tag=`echo "$value" |sed -e 's/^RENAMED //' -e 's/:.*//'`
61                 item=`echo "$value" |sed -e 's/^[^:]*:[ ]*//' -e 's/[ ]*$//'`
62
63                 case "$tag" in
64                 Username)
65                         user="$item"
66                         ;;
67                 UID)
68                         uid="$item"
69                         ;;
70                 GID)
71                         gid="$item"
72                         ;;
73                 HOME)
74                         home="$item"
75                         ;;
76                 esac
77                 ;;
78
79         $DIALOG_ESC)
80                 echo "ESC pressed."
81                 break
82                 ;;
83
84         esac
85 done