-
Notifications
You must be signed in to change notification settings - Fork 20
/
addMacToStaticGroupOnEnroll.bash
executable file
·77 lines (64 loc) · 2.89 KB
/
addMacToStaticGroupOnEnroll.bash
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
67
68
69
70
71
72
#!/bin/bash
# Variables from Policy Script
destinationJSSuser="$4"
destinationJSSpw="$5"
########################################################################
############################ README ####################################
########################################################################
# This script is designed to be uploaded to a new JSS and run once per
# computer on enrollment.
#
# Static groups must be created first in JSS, this does not actually create the group
#
# Be sure to set custom parameters under Options for $4 and $5 when creating this
# script in JSS, and then populating those values in your policy
#
# WARNING -- Strongly recommend to rename your static groups in the JSS
# to include no spaces.
#
# You can use "_" But special characters like quotes, spaces, colons,
# dashes, etc. can be tricky.
#
# Do NOT use commas in your static group name, or this will not work.
#
# See http://www.w3schools.com/tags/ref_urlencode.asp for more info
#
# Instructions :
# 1. Define variable "destinationJSS" - use example URL for reference
# 2. Edit the list "fullList"
# - Each line should contain one Mac serial number, a comma, and static group
# - Use examples as guidance
# - Recommend using script generateSaticGroupMembershipList.bash to
# generate the list from the source JSS
#
########################################################################
########################################################################
# Set Variable
destinationJSS="https://pretendjss02.fakedomain.whatever:8443/"
# Edit this list below with one serial number, a comma, and one static group per line
fullList="
FAK3APLS3RL1,StaticGroup01
FAK3APLS3RL2,StaticGroup01
FAK3APLS3RL1,StaticGroup02
FAK3APLS3RL3,StaticGroup02
FAK3APLS3RL1,StaticGroup03
"
########################################################################
########################################################################
############# Edit below this section at your own risk ! ###############
########################################################################
########################################################################
mySerial=`/usr/sbin/system_profiler SPHardwareDataType | grep "Serial Number" | awk -F ": " '{print $2}'`
echo -e "My Serial is $mySerial\n\n"
if [[ `echo $fullList | grep $mySerial` ]]
then
for groupToJoin in $(echo "$fullList" | grep "$mySerial" | awk -F "," '{print $2}')
do
echo -e "\n----------\n"
echo "This system -- $mySerial -- should be added to -- $groupToJoin"
curl -k "$destinationJSS"JSSResource/computergroups/name/$groupToJoin --user "$destinationJSSuser:$destinationJSSpw" -H "Content-Type: application/xml" -X PUT -d "<computer_group><computer_additions><computer><serial_number>$mySerial</serial_number></computer></computer_additions></computer_group>"
echo -e "\n----------\n"
done
else
echo "\n----------\nNo memberships\n----------\n"
fi