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