xref: /freebsd/contrib/dialog/samples/inputmenu1 (revision c6ec7d31830ab1c80edae95ad5e4b9dba10c47ac)
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
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	  --backtitle "$backtitle" "$@" \
23	  --inputmenu "Originally I designed --inputmenu for a \
24configuration purpose. Here is a possible piece of a configuration program." \
2520 50 10 \
26	"Username:"	"$user" \
27	"UID:"		"$uid" \
28	"GID:"		"$gid" \
29	"HOME:"		"$home" \
302>&1 1>&3`
31returncode=$?
32exec 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
85done
86