summaryrefslogtreecommitdiff
path: root/setup-user.in
blob: 8b9e6cf732d71e334fd8575474c6b2a0fd5e8360 (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
#!/bin/sh

PREFIX=@PREFIX@
: ${LIBDIR=$PREFIX/lib}
. "$LIBDIR/libalpine.sh"

usage() {
	cat <<-__EOF__
		usage: setup-user [-h] [-f FULLNAME] [USERNAME]

		Create user account

		options:
		 -h  Show this help
		 -f  Set full name for user

		If USERNAME is not specified user will be prompted.
	__EOF__
	exit $1
}

while getopts "f:h" opt; do
	case $opt in
		h) usage 0;;
		f) fullname="$OPTARG";;
		'?') usage "1" >&2;;
	esac
done
shift $(($OPTIND - 1))

if [ $# -gt 1 ]; then
	usage "1" >&2
elif [ $# -eq 1 ]; then
	username="$1"
	nopassword="-D"
else
	interactive=1
fi

if [ -n "$interactive" ] && [ -z "$fullname" ]; then
	ask "Enter full name for user account (or 'skip')"
	case "$resp" in
		skip) exit 0;;
		*) fullname="$resp";;
	esac
fi

if [ -n "$interactive" ] && [ -z "$username" ]; then
	while true; do
		ask "Enter username for $fullname:"
		username="$resp"
		if [ -n "$fullname" ]; then
			$MOCK adduser -g "$fullname" $nopassword "$username" && break
		else
			$MOCK adduser $nopassword "$username" && break
		fi
	done
else
	if [ -n "$fullname" ]; then
		$MOCK adduser -g "$fullname" $nopassword "$username"
	else
		$MOCK adduser $nopassword "$username"
	fi
fi