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 env
odAdmin="" #enter your OD admin name between the quotes
odPassword=""  # Enter your OD admin password between the quotes
domain="od.school.edu" # FQDN of your OD domain
oldDomain="oldod.school.edu" # If moving from another OD, enter that FQDN here
oldODip="111.222.333.444" # Enter the IP of your old OD
ADdomain="ad.school.edu" # Enter your AD domain here
computerGroup=computers  # Add appropriate computer group you want machines to be added to, case sensitive 
 
# These variables probably don't need to be changed
computerName=`/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 already
if [ "${check4OD}" == "${domain}" ]; then
	echo "This machine is joined to ${domain} already."
	odSearchPath=`defaults read /Library/Preferences/DirectoryService/SearchNodeConfig "Search Node Custom Path Array" | grep $domain`
	if [ "${odSearchPath}" = "" ]; then
		echo "$domain not found in search path. Adding..."
		dscl /Search -append / CSPSearchPath /LDAPv3/$domain
		sleep 10
	fi
else if [ "${check4OD}" == "${oldDomain}" ]; then
	echo "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 $domain
	dscl /Search -create / SearchPolicy CSPSearchPath
	killall DirectoryService
else if [ "${check4OD}" == "${oldODip}" ]; then
	echo "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 $domain
		dscl /Search -create / SearchPolicy CSPSearchPath
		killall DirectoryService
else
	echo "No previous OD servers found, binding to $domain"
	dsconfigldap -v -a $domain -n $domain
	dscl /Search -create / SearchPolicy CSPSearchPath
	sleep 10
	dscl /Search -append / CSPSearchPath /LDAPV3/$domain
	echo "Killing DirectoryService"
	killall DirectoryService
	fi
fi
fi
 
if [ "${check4ODacct}" == "${computerName}" ]; then
	echo "This machine has a computer account on ${domain} already."
else
	echo "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 ComputerList
	dscl -u "${odAdmin}" -P "${odPassword}" /LDAPv3/${domain} -merge /ComputerLists/${computerGroup} apple-computers ${computerName}		
 
	# Set the GUID
	GUID="$(dscl /LDAPv3/${domain} -read /Computers/${computerName} GeneratedUID | awk '{ print $2 }')"
	# Add to computergroup
	dscl -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}
fi
 
sleep 25 # Give DS a chance to catch up
 
# Fix DS search order
echo "Checking DS search order..."
if [ "${check4AD}" == "${adDomain}" ]; then
	dsconfigad -alldomains enable
	dscl /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 ]; then
		echo "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/$domain
		dscl /Search/Contacts -append / CSPSearchPath "/Active Directory/All Domains"
	else if [[ ${osvers} -eq 5 || 6 ]]; then
		echo "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/$domain
		dscl /Search/Contacts -append / CSPSearchPath "/Active Directory/All Domains"
	fi
fi
	else if [ "${check4AD}" == "All Domains" ]; then
	dscl /Search -append / CSPSearchPath "/Active Directory/All Domains"
	sleep 15
		if [ $osvers -eq 4 ]; then
			echo "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/$domain
		else if [[ ${osvers} -eq 5 || 6 ]]; then
			echo "OS detected as ${osversionlong}"
			echo "Setting OD, then AD to search order..."
			dscl localhost changei /Search CSPSearchPath 2 /LDAPv3/$domain
			dscl localhost changei /Search CSPSearchPath 3 "/Active Directory/All Domains"
			dscl /Search/Contacts -append / CSPSearchPath "/Active Directory/All Domains"
		fi
	fi
fi
fi	
 
echo "Finished. Exiting..."
exit 0

 

From:


原文链接: http://blog.csdn.net/afatgoat/article/details/5975896

转载于:https://my.oschina.net/junwong/blog/46592

这是一个在 Android 中使用 View Binding 的代码行。它的作用是获取由 View Binding 生成的绑定类实例中的根视图,并将其存储在 `root` 变量中。 在使用 View Binding 时,你需要创建一个绑定类实例,它会在编译时自动生成。绑定类实例包含了布局文件中所有的视图对象,以及与之对应的 ID。你可以通过访问绑定类实例中的视图对象,来操作布局文件中的 UI。 例如,以下是一个使用 View Binding 的示例: ``` private lateinit var binding: FragmentHomeBinding override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { binding = FragmentHomeBinding.inflate(inflater, container, false) val textView = binding.textHome textView.text = "Hello World!" val root: View = binding.root return root } ``` 在这个例子中,我们首先创建了一个 `FragmentHomeBinding` 的实例,通过调用 `FragmentHomeBinding.inflate()` 方法来绑定布局文件。然后,我们使用 `binding.textHome` 来获取 `R.id.text_home` 视图对象,并将其存储在 `textView` 变量中。接下来,我们使用 `binding.root` 来获取由 View Binding 生成的根视图,并将其存储在 `root` 变量中。最后,我们将 `root` 返回即可。 通过使用 View Binding,你可以避免手动调用 `findViewById()` 方法来获取视图对象,从而提高代码的可读性和可维护性。同时,由于 View Binding 是在编译时生成的,因此也可以避免运行时出现的类型转换错误。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值