xref: /freebsd/contrib/dialog/samples/inputmenu2 (revision 9a14aa017b21c292740c00ee098195cd46642730)
1#! /bin/sh
2# $Id: inputmenu2,v 1.8 2010/01/13 10:32:04 tom Exp $
3#
4# "inputmenu1" with defaultitem, help-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
18defaultitem="Username:"
19while test $returncode != 1 && test $returncode != 250
20do
21exec 3>&1
22value=`$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 \
28configuration purpose. Here is a possible piece of a configuration program." \
2920 60 10 \
30	"Username:"	"$user" \
31	"UID:"		"$uid"  \
32	"GID:"		"$gid"  \
33	"HOME:"		"$home" \
342>&1 1>&3`
35returncode=$?
36exec 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
97done
98