forked from jamf/API_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PromptUserForEmailAddress.sh
38 lines (27 loc) · 1.33 KB
/
PromptUserForEmailAddress.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
#!/bin/bash -x
jssurl="" # example: https://example.com:8443
username=""
password=""
###############################
# Do not edit below this line #
###############################
# Grab our serial number so we can edit the right computer record
serialnumber=`ioreg -l | awk '/IOPlatformSerialNumber/ { print $4;}' | sed 's/"//' | sed 's/"//'`
# Make our temp files
touch /tmp/setemail.xml
touch /tmp/setemail2.xml
# Set our email address by prompting the user for input with applescript
email=`/usr/bin/osascript <<EOT
tell application "System Events"
activate
set email to text returned of (display dialog "Please Input Your Organization Email Address" default answer "" with icon 2)
end tell
EOT`
# Get our current user and location information from the JSS
curl -k -u $username:$password $jssurl/JSSResource/computers/serialnumber/$serialnumber/subset/location -X GET | tidy -xml -utf8 -i > /tmp/setemail.xml
# Set the email address
cat /tmp/setemail.xml | sed 's/<email_address>.*<\/email_address>/<email_address \/>/' | sed "s/<email_address \/>/<email_address>$email<\/email_address>/g" > /tmp/setemail2.xml
# Submit our new user and location information to the JSS
curl -k -u $username:$password $jssurl/JSSResource/computers/serialnumber/$serialnumber/subset/location -T "/tmp/setemail2.xml" -X PUT
rm /tmp/setemail.xml
rm /tmp/setemail2.xml