-
Notifications
You must be signed in to change notification settings - Fork 0
/
group.sh
executable file
·54 lines (39 loc) · 915 Bytes
/
group.sh
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
#!/bin/bash
echo "LDAP Group Membership Sync Script"
# Check that this distribution is Ubuntu
if grep -qvi ubuntu <<< `uname -v`
then
echo "This script is meant for Ubuntu distributions only."
exit 1
fi
# Check if root
if [ $UID != 0 ]
then
echo "You are not root. This script must be run with root permissions."
exit 1
fi
# Filepath
root=$(dirname $(readlink -f $0))
# Read config file and assign values
for file in $root/group.d/*
do
source $file
echo $file
echo $ADGROUP
echo $LOCALGROUP
echo $DEFAULTUSERS
USERS=`lw-enum-members $ADGROUP | awk -vORS=',' '/SAM account name:/ {print $4}' | sed '$s/.$//'`
if [ -n $DEFAULTUSERS ]
then
if [ -n $USERS ]
then
USERS="$DEFAULTUSERS,$USERS"
else
USERS="$DEFAULTUSERS"
fi
fi
echo $USERS
sudo sed -i 's/^\('$LOCALGROUP':[^:]*:[0-9][0-9]*:\).*$/\1'$USERS'/' /etc/group
done
echo
echo "LDAP Group Membership Sync Complete."