Changing the computername and joining Open Directory and Active Directory

From Wiki

Revision as of 13:08, 29 July 2009 by Ric-5 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to:navigation, search

OS X is a pain... the computer has three names and these all have to be changed individually. That's before you even start connecting to directory services!

This is my script (pretty quick and dirty) for changing the name and joining OD/AD after a Mac has been imaged.

This has been tested on Leopard and it should work on other versions of OS X (I hope it works on Tiger!!!)

<bash>#!/bin/bash

  1. This script is intended to change the computer name and (optionally) join
  2. the computer to Open Directory and Active Directory and enable AD
  3. authentication.
  4. This script must be run as root! It's not my fault if it b0rks your shiny
  5. new Mac either!
  6. Created by: Ric Charlton, 29/07/2009
  1. Check if root

if test $USER != 'root'; then echo You must be root to run this script!!! exit 666 fi

  1. Set variables

echo Enter new computer name: read NEWCOMPUTERNAME echo Enter new domain name: read NEWDOMAINNAME NEWHOSTNAME=$NEWCOMPUTERNAME.$NEWDOMAINNAME echo Do you want to join Open Directory? [y/n] read joinLDAP if test $joinLDAP = 'y'; then echo Enter LDAP server fqdn: read LDAPSERVER echo Enter LDAP directory admin username: read LDAPUSERNAME fi echo Do you want to join Active Directory? [y/n] read joinAD if test $joinAD = 'y'; then echo Enter AD directory admin username: read ADUSERNAME echo Enter local admin username: read LOCALUSERNAME echo Is this a mobile computer? [y/n] read isMobile if test $isMobile = 'y'; then MOBILEMAC=enable; else MOBILEMAC=disable; fi fi

  1. Change hostname

echo Configuring hostname... hostname $NEWHOSTNAME scutil --set HostName $NEWHOSTNAME echo Done configuring hostname

  1. Change computername (Bonjour and AppleTalk name)

echo Configuring computername... systemsetup -setcomputername $NEWCOMPUTERNAME echo Done configuring computername

if test $joinLDAP = 'y'; then # Bind to LDAP server echo "Binding to LDAP server (you will be prompted for the direcotry admin password)..." dsconfigldap -a $LDAPSERVER -n $LDAPSERVER -c $NEWCOMPUTERNAME -u $LDAPUSERNAME echo Done binding to LDAP server fi

if test $joinAD = 'y'; then # Bind to AD and enable AD authentication echo "Binding to Active Directory and enabling AD authentication (you will be prompted for the AD admin password)..." ## Modify DirectoryService.plist defaults write /Library/Preferences/DirectoryService/DirectoryService "Active Directory" Active

## Bind to AD dsconfigad -a $NEWCOMPUTERNAME -u $ADUSERNAME -domain $NEWDOMAINNAME -mobile $MOBILEMAC -useuncpath enable

## Add authentication search path dscl /Search -create / SearchPolicy CSPSearchPath dscl /Search -append / CSPSearchPath "Active Directory/All Domains"

## Add contacts search path dscl /Search/Contacts -create / SearchPolicy CSPSearchPath dscl /Search/Contacts -append / CSPSearchPath "Active Directory/All Domains"

echo Done configuring AD

# Kill DirectoryService - it restarts automatically killall DirectoryService fi </bash>