summarylogtreecommitdiffstats
path: root/add-autologin-group.script
blob: 164edb6344cef524c6a3c8f313c4c803f80c3260 (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
#!/bin/bash

##Bash script to add autologin group into /etc/group and after creation add all users present in /etc/paswd. Systemd service

#Collect users
_users=$(awk -F'[/:]' '{if ($3 >= 1000 && $3 != 65534) print $1}' /etc/passwd)

#Check if autologin group not exist and if not do the job 
install() {
grep "autologin" /etc/group
	if [ "$?" -eq 1 ]; then
		#Add autologin group
		groupadd -r autologin
		#Add users 
		for i in $_users; do 
		gpasswd -a $i autologin
		done
	fi
}	

#Check if a new user is created	
check-new-user() {
	for i in $_users ; do
		if groups $i | grep &>/dev/null '\bautologin\b'; then
			: #echo "User $i ok"
		else gpasswd -a $i autologin
		fi
	done
}

#Job
grep autologin /etc/group
	if [ "$?" -eq 1 ]; then
		install
	else check-new-user
	fi