How to add an Open Directory server via a script

imagingmac-osxmac-osx-serverosx-leopardscripting

What is the best method to add an Open Directory server via a shell script on a brandly new imaged computer?

I've created a new image with InstaDMG and I'd like to add the Open Directory Server via a shell script rather than having to do it manually by hand using Directory Utility.

The computer does not have to bind the Open Directory. (Client: 10.5.7, Server: 10.4.11)

Best Answer

I discovered the method (Deploy Studio) I was deploying my images had scripts already to do the Open Directory binding - I've modified the scripts slightly to give the crux of the script for here to answer my question. This example only uses anonymous binding (not explicitly bound to the OD server)

#!/bin/sh

# Used ds_open_directory_binding.sh (v1.6) from Deploy Studio as a base for the explicit question.
# I recommend downloading Deploy Studio (http://deploystudio.com) to see other methods but the crux
# of how it is done can be read here. (eg. no error checking here)

#Enable LDAPv3 Plugin
defaults write /Library/Preferences/DirectoryService/DirectoryService "LDAPv3" Active 2>&1
chmod 600 /Library/Preferences/DirectoryService/DirectoryService.plist 2>&1

/usr/sbin/ipconfig waitall

#Configure LDAP
dsconfigldap -a 'server.example.com' 2>&1

#Restart DS
killall DirectoryService
sleep 5

#Create Search Policy
dscl localhost -create /Search SearchPolicy CSPSearchPath 2>&1

#Create Contacts
dscl localhost -create /Contact SearchPolicy CSPSearchPath 2>&1

#Add OD Server to the search path
dscl localhost -append /Search CSPSearchPath '/LDAPv3/server.example.com' 2>&1

#Add OD Server to Contact Search Policy
dscl localhost -append /Contact CSPSearchPath '/LDAPv3/server.example.com' 2>&1
Related Topic