m3nne60764 发表于 2016-5-18 02:46:31

Mac: Another OD Binding scirpt

  
借鉴一下别人的脚本:
  
#!/bin/sh# Patrick Gallagher# http://www.macadmincorner.com# Updated 12/11/2009# These variables need to be configured for your envodAdmin="" #enter your OD admin name between the quotesodPassword=""# Enter your OD admin password between the quotesdomain="od.school.edu" # FQDN of your OD domainoldDomain="oldod.school.edu" # If moving from another OD, enter that FQDN hereoldODip="111.222.333.444" # Enter the IP of your old ODADdomain="ad.school.edu" # Enter your AD domain herecomputerGroup=computers# Add appropriate computer group you want machines to be added to, case sensitive # These variables probably don't need to be changedcomputerName=`/usr/sbin/scutil --get LocalHostName`nicAddress=`ifconfig en0 | grep ether | awk '{print $2}'`check4OD=`dscl localhost -list /LDAPv3`check4ODacct=`dscl /LDAPv3/${domain} -read Computers/${computerName} RealName | cut -c 11-`check4AD=`dscl localhost -list /Active/ Directory`osversionlong=`sw_vers -productVersion`osvers=${osversionlong:3:1}# Check if on OD alreadyif [ "${check4OD}" == "${domain}" ]; thenecho "This machine is joined to ${domain} already."odSearchPath=`defaults read /Library/Preferences/DirectoryService/SearchNodeConfig "Search Node Custom Path Array" | grep $domain`if [ "${odSearchPath}" = "" ]; thenecho "$domain not found in search path. Adding..."dscl /Search -append / CSPSearchPath /LDAPv3/$domainsleep 10fielse if [ "${check4OD}" == "${oldDomain}" ]; thenecho "Removing from ${oldDomain}"dsconfigldap -r "${oldDomain}"dscl /Search -delete / CSPSearchPath /LDAPv3/"${oldDomain}"dscl /Search/Contacts -delete / CSPSearchPath /LDAPv3/"${oldDomain}"echo "Binding to $domain"dsconfigldap -v -a $domain -n $domaindscl /Search -create / SearchPolicy CSPSearchPathkillall DirectoryServiceelse if [ "${check4OD}" == "${oldODip}" ]; thenecho "Removing from ${oldODip}"dsconfigldap -r "${oldODip}"dscl /Search -delete / CSPSearchPath /LDAPv3/"${oldODip}"dscl /Search/Contacts -delete / CSPSearchPath /LDAPv3/"${oldODip}"echo "Binding to $domain"dsconfigldap -v -a $domain -n $domaindscl /Search -create / SearchPolicy CSPSearchPathkillall DirectoryServiceelseecho "No previous OD servers found, binding to $domain"dsconfigldap -v -a $domain -n $domaindscl /Search -create / SearchPolicy CSPSearchPathsleep 10dscl /Search -append / CSPSearchPath /LDAPV3/$domainecho "Killing DirectoryService"killall DirectoryServicefififiif [ "${check4ODacct}" == "${computerName}" ]; thenecho "This machine has a computer account on ${domain} already."elseecho "Adding computer account to ${domain}"dscl -u "${odAdmin}" -P "${odPassword}" /LDAPv3/${domain} -create /Computers/${computerName} ENetAddress "$nicAddress"dscl -u "${odAdmin}" -P "${odPassword}" /LDAPv3/${domain} -merge /Computers/${computerName} RealName ${computerName}# Add computer to ComputerListdscl -u "${odAdmin}" -P "${odPassword}" /LDAPv3/${domain} -merge /ComputerLists/${computerGroup} apple-computers ${computerName}# Set the GUIDGUID="$(dscl /LDAPv3/${domain} -read /Computers/${computerName} GeneratedUID | awk '{ print $2 }')"# Add to computergroupdscl -u "${odAdmin}" -P "${odPassword}" /LDAPv3/${domain} -merge /ComputerGroups/${computerGroup} apple-group-memberguid "${GUID}"dscl -u "${odAdmin}" -P "${odPassword}" /LDAPv3/${domain} -merge /ComputerGroups/${computerGroup} memberUid ${computerName}fisleep 25 # Give DS a chance to catch up# Fix DS search orderecho "Checking DS search order..."if [ "${check4AD}" == "${adDomain}" ]; thendsconfigad -alldomains enabledscl /Search -delete / CSPSearchPath "/Active Directory/${adDomain}"dscl /Search/Contacts -delete / CSPSearchPath "/Active Directory/${adDomain}"dscl /Search -append / CSPSearchPath "/Active Directory/All Domains"if [ $osvers -eq 4 ]; thenecho "OS detected as ${osversionlong}"echo "Setting AD, then OD to search order..."dscl localhost changei /Search CSPSearchPath 2 "/Active Directory/All Domains"dscl localhost changei /Search CSPSearchPath 3 /LDAPv3/$domaindscl /Search/Contacts -append / CSPSearchPath "/Active Directory/All Domains"else if [[ ${osvers} -eq 5 || 6 ]]; thenecho "OS detected as ${osversionlong}"echo "Setting OD, then AD to search order..."dscl localhost changei /Search CSPSearchPath 3 "/Active Directory/All Domains"dscl localhost changei /Search CSPSearchPath 2 /LDAPv3/$domaindscl /Search/Contacts -append / CSPSearchPath "/Active Directory/All Domains"fifielse if [ "${check4AD}" == "All Domains" ]; thendscl /Search -append / CSPSearchPath "/Active Directory/All Domains"sleep 15if [ $osvers -eq 4 ]; thenecho "OS detected as ${osversionlong}"echo "Setting AD, then OD to search order..."dscl localhost changei /Search CSPSearchPath 1 "/Active Directory/All Domains"dscl localhost changei /Search CSPSearchPath 2 /LDAPv3/$domainelse if [[ ${osvers} -eq 5 || 6 ]]; thenecho "OS detected as ${osversionlong}"echo "Setting OD, then AD to search order..."dscl localhost changei /Search CSPSearchPath 2 /LDAPv3/$domaindscl localhost changei /Search CSPSearchPath 3 "/Active Directory/All Domains"dscl /Search/Contacts -append / CSPSearchPath "/Active Directory/All Domains"fifififiecho "Finished. Exiting..."exit 0
  
  From:
页: [1]
查看完整版本: Mac: Another OD Binding scirpt