设为首页 收藏本站
查看: 946|回复: 0

[经验分享] Mac OS X: 实用脚本程序(bash scripts)系列-8

[复制链接]

尚未签到

发表于 2016-5-16 09:43:40 | 显示全部楼层 |阅读模式
Mac OS X: 实用脚本程序(bash scripts)系列-8
AD Binding的一个脚本实例
  Active Directory在现实企业管理中已经成为了现实的标准,Open Directory, Active Directory,或者eDirectory等都是基于Directory原理实现的,都有各自的实现和扩展,各有优势。基于现实中PC机和AD服务在企业中应用的普及性,在企业中把Mac或者其它系统纳入AD管理,也就是AD集成可以说在企业中的应用很普遍。实际中要考虑系统版本号的兼容,自己企业AD的配置情况,管理特点,当然别忘了把客户计算机先加入到AD中,设置相应的GPO和管理环境所需的管理组等。

  
  下面的脚本就是一个实际企业环境中把Mac系统纳入到AD管理环境的实际例子. 谨和大家分享:
  

  #--------------------------------------------------------------------------------------
# Check for Valid Corp Network IP Address
CorpIP=""
check=20
Limit=check
X=0
while [ "$CorpIP" = "" ]
do
echo "Checking valid IP detected...$check times."
CorpIP=$(ifconfig| grep "inet 10.")
X=$((X+1))
if [ $X -ge $limit ]; then
CorpIP="NO_ValidIP"
break
fi
check=$((check-1))
sleep 2
done

echo "Detected IP: $CorpIP"

if [ "$CorpIP" = "NO_ValidIP" ]; then
echo "Binding failed! Valid Corp Network not detected!"
osascript -e 'set volume 4'
say "Binding failed! Valid Corp IP Address not detected!"
exit 1
fi

#--------------------------------------------------------------------------------------
# Host-specific parameters
#--------------------------------------------------------------------------------------
computerid=`/usr/sbin/scutil --get LocalHostName`

#--------------------------------------------------------------------------------------
# Standard Parameters used to Bind Workstation to AD
#--------------------------------------------------------------------------------------
domain="Corp.com"
udn="MacADIAdmin"
password="Mac1nt0SH"
ou="CN=Computers,DC=Corp,DC=com"

#--------------------------------------------------------------------------------------
# Advanced Options for AD Plugin
#--------------------------------------------------------------------------------------
alldomains="enable"
localhome="disable"
protocol="afp"
mobile="disable"
mobileconfirm="disable"
useuncpath="enable"
user_shell="/bin/bash"
preferred="-nopreferred"
admingroups="Corp/WSAdmins"
searchPathLDAP=`cat/Library/Preferences/DirectoryService/SearchNodeConfig.plist | grepLDAPv3 | sed -e 's!string>!!g' -e 's!<//!!g' | tr -d '/t'`

#--------------------------------------------------------------------------------------
# Synchronize Time with Corp Network Time Server
#--------------------------------------------------------------------------------------
echo "Setting the Network Time Server to 10.0.1.1 ... Please Wait"
"$1/Contents/Resources/systemsetup-tiger" -setusingnetworktime off >& /dev/null
"$1/Contents/Resources/systemsetup-tiger" -setnetworktimeserver 10.0.1.1 >& /dev/null
"$1/Contents/Resources/systemsetup-tiger" -setusingnetworktime on >& /dev/null

echo "Restarting Network Time Service... Please Wait"
SystemStarter -d restart "Network Time" >& /dev/null

#--------------------------------------------------------------------------------------
# Attempt to force unbind the workstation
#--------------------------------------------------------------------------------------
echo "Attempting a force unbind in case system is already bound to AD... Please Wait."
dsconfigad -r -f -u baduser -p badpass >& /dev/null

#--------------------------------------------------------------------------------------
# Disable Unused Protocols
#--------------------------------------------------------------------------------------
echo "Disable all unused protocols (AppleTalk, BSD, SMB, SLP)... Please Wait."
defaults write /Library/Preferences/DirectoryService/DirectoryService AppleTalk -string Inactive
defaults write /Library/Preferences/DirectoryService/DirectoryService BSD -string Inactive
defaults write /Library/Preferences/DirectoryService/DirectoryService SMB -string Inactive
defaults write /Library/Preferences/DirectoryService/DirectoryService SLP -string Inactive
plutil -convert xml1 /Library/Preferences/DirectoryService/DirectoryService.plist

#--------------------------------------------------------------------------------------
# Activate the AD plugin
#--------------------------------------------------------------------------------------
echo "Activating AD Plugin... Please Wait."
defaults write /Library/Preferences/DirectoryService/DirectoryService "Active Directory" "Active"
plutil -convert xml1 /Library/Preferences/DirectoryService/DirectoryService.plist

#--------------------------------------------------------------------------------------
# Bind to AD
#--------------------------------------------------------------------------------------
echo "Binding system to AD as '$computerid'... Please Wait."
bind_result=`dsconfigad -f -a $computerid -domain $domain -u $udn -p "$password" -ou "$ou"`

if [ "$bind_result" != "Computer was successfully Added to Active Directory." ]; then
echo "Binding failed! Check the Computer Name and ensure it has an account in Active Directory"
osascript -e 'set volume 4'
osascript -e 'say "I am sorry but Active Directory binding failed!Please check the computer name and ensure this system has an account inActive Directory." using "Vicki"'
exit 1
else
echo "$bind_result"
fi
  
  # Write value so workstation can be easily identified being bound to AD
defaults write /Library/Preferences/com.apple.RemoteDesktop "Text4" 'Bound to AD - OSXServer - v2.0'

#--------------------------------------------------------------------------------------
# Configure advanced AD plugin options
#--------------------------------------------------------------------------------------
echo "Configuring Advanced AD Plugins... Please Wait."
if [ "$admingroups" = "" ]; then
dsconfigad -nogroups
else
dsconfigad -groups "$admingroups"
fi

dsconfigad -alldomains $alldomains -localhome $localhome -protocol $protocol /
-mobile $mobile -mobileconfirm $mobileconfirm -useuncpath $useuncpath /
-shell $user_shell $preferred

#--------------------------------------------------------------------------------------
# Add the AD node to the search path
# Delay a bit to give the Directory Service a chance to catch its breath
#--------------------------------------------------------------------------------------
echo "Adding AD to Search Path... Please Wait."

if [ "$searchPathLDAP" = "" ] || [ `echo $searchPathLDAP| grep127.0.0.1` ] || [ `echo $searchPathLDAP| grep localhost` ]; then
echo "No existing LDAP path... Only writing AD. Please Wait."
defaults write/Library/Preferences/DirectoryService/SearchNodeConfig "Search NodeCustom Path Array" -array "/Active Directory/All Domains"
defaults write /Library/Preferences/DirectoryService/SearchNodeConfig "Search Policy" -int 3
plutil -convert xml1 /Library/Preferences/DirectoryService/SearchNodeConfig.plist

else
echo "LDAP path is /$searchPathLDAP... Writing AD as first search and LDAP second. Please Wait."
defaults write/Library/Preferences/DirectoryService/SearchNodeConfig "Search NodeCustom Path Array" -array "/Active Directory/All Domains""/$searchPathLDAP"
defaults write /Library/Preferences/DirectoryService/SearchNodeConfig "Search Policy" -int 3
plutil -convert xml1 /Library/Preferences/DirectoryService/SearchNodeConfig.plist
fi

#--------------------------------------------------------------------------------------
# Restart DirectoryService (necessary to reload AD plugin activation settings)
#--------------------------------------------------------------------------------------
echo "Restarting DirectoryService... Please Wait."
sleep 2
killall DirectoryService >& /dev/null
sleep 8

#--------------------------------------------------------------------------------------
# Disable autologin - If it's enabled
#--------------------------------------------------------------------------------------
echo "Disabling autologin if enabled... Please Wait."
defaults delete /Library/Preferences/com.apple.loginwindow autoLoginUser >& /dev/null
srm /etc/kcpassword >& /dev/null

#--------------------------------------------------------------------------------------
# Complete
#--------------------------------------------------------------------------------------
echo "Done. AD Bind Successful."
exit 0

  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-217586-1-1.html 上篇帖子: 提高 Mac OS X 速度的 52 个方法 下篇帖子: 转 Mac OS X 10.6 下 android 源码编译
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表