summaryrefslogtreecommitdiffstats
path: root/contrib/dialog/samples/inputmenu2
blob: f560aba3d21162a2d318bd8b98f8a7f6f47798e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#! /bin/sh
# $Id: inputmenu2,v 1.8 2010/01/13 10:32:04 tom Exp $
#
# "inputmenu1" with defaultitem, help-button.

. ./setup-vars

backtitle="An Example for the use of --inputmenu:"

ids=`id|sed -e 's/([^)]*)//g'`
uid=`echo "$ids" | sed -e 's/^uid=//' -e 's/ .*//'`
gid=`echo "$ids" | sed -e 's/^.* gid=//' -e 's/ .*//'`

user="$USER"
home="$HOME"

returncode=0
defaultitem="Username:"
while test $returncode != 1 && test $returncode != 250
do
exec 3>&1
value=`$DIALOG --clear --ok-label "Create" \
	  --backtitle "$backtitle" \
	  --help-button \
	  --help-label "Script" \
	  --default-item "$defaultitem" "$@" \
	  --inputmenu "Originally I designed --inputmenu for a \
configuration purpose. Here is a possible piece of a configuration program." \
20 60 10 \
	"Username:"	"$user" \
	"UID:"		"$uid"  \
	"GID:"		"$gid"  \
	"HOME:"		"$home" \
2>&1 1>&3`
returncode=$?
exec 3>&-

	case $returncode in
	$DIALOG_HELP)
		"$DIALOG" \
		--textbox "$0" 0 0
		;;
	$DIALOG_CANCEL)
		"$DIALOG" \
		--clear \
		--backtitle "$backtitle" \
		--yesno "Really quit?" 10 30
		case $? in
		$DIALOG_OK)
			break
			;;
		$DIALOG_CANCEL)
			returncode=99
			;;
		esac
		;;
	$DIALOG_OK)
		"$DIALOG" \
		--clear \
		--backtitle "$backtitle" \
		--msgbox "useradd \n\
			-d $home \n\
			-u $uid \n\
			-g $gid \n\
			$user" 10 40
		;;
	$DIALOG_EXTRA)
		tag=`echo "$value" |sed -e 's/^RENAMED //' -e 's/:.*/:/'`
		item=`echo "$value" |sed -e 's/^.*:[ ]*//' -e 's/[ ]*$//'`

		case "$tag" in
		Username:)
			user="$item"
			;;
		UID:)
			uid="$item"
			;;
		GID:)
			gid="$item"
			;;
		HOME:)
			home="$item"
			;;
		*)
			tag=
			;;
		esac
		test -n "$tag" && defaultitem="$tag"
		;;

	$DIALOG_ESC)
                echo "ESC pressed."
                break
                ;;

	esac
done
OpenPOWER on IntegriCloud