-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathcoreconfig-dsconfig-admin-groups.sh
66 lines (58 loc) · 1.55 KB
/
coreconfig-dsconfig-admin-groups.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
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
###################################################################
#
# Script to set the AD groups which have admin rights on a machine
# $4 should be a comma-separated list of groups, or an empty string
# to remove all admin groups.
#
# Last Changed: @@DATE
# Version: @@VERSION
# Origin: @@ORIGIN
# Released by JSS User: @@USER
#
##################################################################
set -eu
TOOL='/usr/sbin/dsconfigad'
# $4 should be a comma-separated list of groups
if [[ ! -z ${4-} ]]
then
GROUPLIST="${4}"
else
echo "USAGE: ${0} arg1 arg2 arg3 GROUPLIST"
echo ""
echo "GROUPLIST should be a comma-separated list of AD groups that will"
echo "be allowed admin rights on this machine, or the string NONE"
exit 255
fi
function current_value {
# Fragile but seems to work.
current_value="$(${TOOL} -show | grep "Allowed admin groups" | awk 'BEGIN {FS = "="};{print $2}' | sed 's/ //')"
echo "${current_value}"
}
if [[ "${4}" == "NONE" ]]
# We've been asked to disable admin groups
then
echo "Disabling admin groups"
GROUPLIST="not set"
command="${TOOL} -nogroups"
else
echo "Setting admin groups to '${GROUPLIST}'..."
command='${TOOL} -groups "${GROUPLIST}"'
fi
echo "Checking AD Admin Groups..."
if [[ "$(current_value)" == "${GROUPLIST}" ]]
then
echo "No change needed"
exit 0
else
# Do it.
eval ${command}
if [ $? -eq 0 ] && [[ "$(current_value)" == "${GROUPLIST}" ]]
then
echo "Succeeded"
exit 0
else
echo "Failed"
exit 1
fi
fi