forked from boberito/jamfscripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFaculty Staff Set Department.sh
76 lines (57 loc) · 2.01 KB
/
Faculty Staff Set Department.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
67
68
69
70
71
72
73
74
75
76
#!/bin/sh
pashuapath="/usr/local/saes/Pashua.app/Contents/MacOS/Pashua"
pashua_run() {
# Write config file
local pashua_configfile=`/usr/bin/mktemp /tmp/pashua_XXXXXXXXX`
echo "$1" > "$pashua_configfile"
if [ "" = "$pashuapath" ]
then
>&2 echo "Error: Pashua could not be found"
exit 1
fi
# Get result
local result=$("$pashuapath" "$pashua_configfile")
# Remove config file
rm "$pashua_configfile"
oldIFS="$IFS"
IFS=$'\n'
# Parse result
for line in $result
do
local name=$(echo $line | sed 's/^\([^=]*\)=.*$/\1/')
local value=$(echo $line | sed 's/^[^=]*=\(.*\)$/\1/')
eval $name='$value'
done
IFS="$oldIFS"
}
#API login info
apiuser="JSS API USER"
apipass="JSS API USER PASSWORD"
jamfProURL="YOUR JAMF PRO SERVER"
#update via serial number
apiURL="JSSResource/computers/serialnumber"
MacSerial=$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformSerialNumber/{print $4}')
#XML header stuff
xmlHeader="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"
#Current User stuff
getUser=$(ls -l /dev/console | awk '{ print $3 }')
#getUser=$3
getRealName=$(id -F "$getUser")
#API data load
xmlresult=$(curl -k "$jamfProURL/JSSResource/departments" --user "$apiuser:$apipass" -H "Accept: application/xml" --silent | xmllint --format - | awk -F'>|<' '/<name>/{print $3","}')
#Cut last character
xmlresult=${xmlresult%?}
#Replace and cut the lines we don't need
tweaked=$(sed 's/,/ \\\npop.option =/g' <<< $xmlresult)
tweaked=$(echo $tweaked | grep -v "AppleTVs" | grep -v "iPads" | grep -v "Class" | grep -v "Cart" | grep -v "Video" | grep -v "Library" | grep -v "Macs")
#echo $tweaked
conf="#Set window title
*.title = Select Department
*.floating = 1
# Add a popup menu
pop.type = popup
pop.label = Please select your department
pop.width = 300
pop.option = $tweaked"
pashua_run "$conf"
jamf recon -endUsername $getUser -department "$pop" -building "Postoak" -realname "$getRealName" -email "$getUser@emailaddress"