summaryrefslogtreecommitdiffstats
path: root/satellit_installer/includes/10-handle_users.inc
blob: 9063a40889169a42c958d16f36a42a121d732a27 (plain) (blame)
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
add_group() {
	echo -n "# Adding group: $1, gid $2..."
	groupadd -g "$2" "$1" 2>/dev/null || perror "Could not add group $1 / gid $2!"
	echo " ok."
}

add_user() {
	echo -n "# Adding user: $1, uid $2, prim. gid $3, optional: other group $4"
	
	if [ $# -eq 4 ]; then
		params=" -u $2 -m -d /home/$1 -s /bin/bash -g $3 -G $4 $1"
	else
		params=" -u $2 -m -d /home/$1 -s /bin/bash -g $3 $1"
	fi

	useradd ${params} 2>/dev/null || perror "Could not add user ${1}/${2} / gid $3 $4"

	echo " ok."
}

add_user_nohome() {
	echo -n "# Adding homeless user: $1, uid $2, to gid $3..."
	useradd -u "$2" --no-create-home -d /nonexistent --shell /bin/false -g "$3" "$1" 2>/dev/null \
		|| perror "Could not add homeless user ${1}/${2} / gid $3!"
	echo " ok."
}

kill_user() {
	echo "# Terminating user account id $1"
	userdel -r -f $( < /etc/passwd  awk -F: '$3 == 1000 {print $1}' ) || perror "# could not kill userid ${1}!"
}

check_users() {
	echo "#"
	echo "# Checking for users to kill with id>=1000: "
	for userid in $( < /etc/passwd  cut -f 3 -d ":" | sort -n ); do
		case $userid in
			65534)	echo "# Ignoring user 65534/sync."	;;
			*)	[ "$userid" -ge 1000 ] && kill_user "$userid"
		esac
	done
}