-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathset-desktop-name-and-bind.sh
70 lines (62 loc) · 2.03 KB
/
set-desktop-name-and-bind.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
#!/bin/bash
# Log file location
LOGFILE="/Library/Logs/desktop-name-and-bind.log"
# Jamf binary location
JAMF_BINARY=/usr/local/jamf/bin/jamf
# Function for obtaining timestamp
timestamp() {
while read -r line
do
TIMESTAMP=$(date)
echo "[$TIMESTAMP] $line"
done
}
# Get model of device
get_mobility() {
# Get the prodcut name
PRODUCT_NAME=$(ioreg -l | awk '/product-name/ { split($0, line, "\""); printf("%s\n", line[4]); }')
# if "macbook" exists in the name, then it's a laptop.
if echo "${PRODUCT_NAME}" | grep -qi "macbook"
then
MOBILITY=mobile
else
MOBILITY=desktop
fi
# Return mobility
echo ${MOBILITY}
}
# Wait for dock befor executing the rest of the script
# This prevents the script from executing before the
# setup assistant is finished
while true; do
# Get current logged in user
CURRENT_USER=$(echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }')
DOCK_CHECK=$(ps -ef | grep [/]System/Library/CoreServices/Dock.app/Contents/MacOS/Dock)
echo "Waiting for file as: ${CURRENT_USER}" | timestamp 2>&1 | tee -a $LOGFILE
echo "regenerating dockcheck as ${DOCK_CHECK}." | timestamp 2>&1 | tee -a $LOGFILE
if [ -n "${DOCK_CHECK}" ]; then
echo "Dockcheck is ${DOCK_CHECK}, breaking." | timestamp 2>&1 | tee -a $LOGFILE
break
fi
sleep 5
done
# Get model of device
MOBILITY=$(get_mobility)
case $MOBILITY in
# If it's a laptop
mobile)
echo "Appears to be a laptop. Skip setting device name from DDI..." | timestamp 2>&1 | tee -a $LOGFILE
;;
# If it's a desktop, run the triggers
desktop)
echo "Appears to be a desktop. Running trigger Set-Desktop-Name..." | timestamp 2>&1 | tee -a $LOGFILE
$JAMF_BINARY policy -event Set-Desktop-Name
sleep 5
echo "Running trigger Bind-AD..."
$JAMF_BINARY policy -event Bind-AD
echo "Name and AD bind complete." | timestamp 2>&1 | tee -a $LOGFILE
;;
*)
esac
echo "Set desktop name and bind now complete." | timestamp 2>&1 | tee -a $LOGFILE
exit 0;