-
Notifications
You must be signed in to change notification settings - Fork 0
/
bindToActiveDirectory.sh
executable file
·104 lines (74 loc) · 2.52 KB
/
bindToActiveDirectory.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
ADPASS=*******
ADMINPASS=*******
HOSTNAME=$(scutil --get LocalHostName)
JH=/Library/Application\ Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper
#serialNumber=$(system_profiler | grep "Serial Number (system)" | cut -d : -f2)
#Preps DirectoryService.plist to enable Active Directory binding
function bindToActiveDirectory()
{
while [[ -z "$dialog" ]];
do
defaults write /Library/Preferences/DirectoryService/DirectoryService "Active Directory" Active 2&>1
dialog=$(osascript -e 'display dialog "Enter a Machine Name" default Answer ""
set theAnswer to (text returned of result)')
if [[ $? -eq 1 ]]; then #If "cancel" is selected, close script.
exit 1
fi
if [[ -z "$dialog" ]]; then #If "hostname (theAnswer)" is zero-length (blank), do the following...
buttonPress=$("$JH" -windowType utility -description "Hostname is blank. Please try again..." -button1 "Cancel" -button2 "Retry")
$buttonPress
if [[ "$buttonPress" -eq 2 ]]; then
bindToActiveDirectory #Re-loop through script if hostname is still blank
else [[ "$buttonPress" -eq 0 ]] #Exit script if user clicks "Cancel"
exit 1
fi
if [[ $? -eq 130 ]]; then
killall jamfHelper
rejoin=$("$JH" -windowType utility -description "Machine Already Bound to Active Directory. Please check record before proceeding." -button1 "Close" -button2 "Unbind")
else
echo "Test"
fi
else
"$JH" -windowType fs -description "Binding "$dialog" to Active Directory... " &
dsconfigad -a "$dialog" -domain janesville.k12.wi.us -u bind_account -p $ADPASS -lu cadmin -lp cadmin
if [[ $? -eq 78 ]]; then
$rejoin
if [[ "$rejoin" -eq 2 ]]; then
dsconfigad -force -remove -u bind_account -p $ADMINPASS
dialog=""
bindToActiveDirectory
else
[[ "$rejoin" -eq 0 ]]
exit 1
fi
dsconfigad -mobile enable
dsconfigad -mobileconfirm disable
defaults read /Library/Preferences/com.apple.loginwindow SHOWFULLNAME -bool true
sleep 5
killall jamfHelper
fi
fi
function enableRoot()
{
if [[ $? -eq 0 ]]; then
"$JH" -windowType fs -description "Enabling Root User..." &
dsenableroot -u admin -p $ADMINPASS -r $ADMINPASS 2&>1
killall jamfHelper
if [[ $? -eq 0 ]]; then
"$JH" -windowType utility -description "Initial Setup Complete" -button1 "Close" &
sleep 5
exit 1
else
"$JH" -windowType utility -description "Root User NOT enabled" -button1 "Close" &
sleep 5
exit 1
fi
else
exit 1
fi
}
enableRoot
done
}
bindToActiveDirectory