aboutsummaryrefslogtreecommitdiff
path: root/scripts/system-setup
blob: 6e2bebe20ad50e02620c54c812c4dcdc43019f14 (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
#!/bin/bash

#interactive systen setup

AUTHKEY_FILE_URL="https://jonasgunz.de/authorized_keys"

if [ $(id -u) -ne 0 ]; then
	echo Supposed to run as root.
	return 1
fi

yes_no()
{
	read -p "$1 (y/[n])" inp
	case $inp in
		[yY]* ) return 0;;
		* ) 	return 1;;
	esac
}

selector()
{
	local cnt=0
	local regex="^-?[0-9]+\$"
	for selection in "$@"
	do
		echo "$cnt) $selection"
		((cnt=$cnt + 1))
	done

	read -p "(default=0) >" inp
	if [[ "$inp" =~ $regex ]] && [ $inp -ge 0 -a $inp -le $# ]
	then
		return $inp
	elif [ -z $inp ]
	then
		return 0
	else
		return -1
	fi
}

function user_setup() {
	while true; do
		read -p "Name for new User: " username
		if [ ! -z $username ]; then
			break;
		fi
	done
}

echo "Interactive system setup"

while true ; do
	selector "User setup" "Exit"
	case $? in
		0)
			user_setup;;
		1)
			exit 0;;
		*)
			echo Wrong input;;
	esac
done