Mac OS X: 实用脚本程序(bash scripts)系列-5

最后更新于:2022-04-01 10:54:22

### 设置Mac OS X 10.5 Leopard打开NetBoot服务 注: 无论是[Mac OS X: 实用脚本程序(bash scripts)系列-4](http://blog.csdn.net/afatgoat/archive/2009/07/04/4321379.aspx),还是这里的脚本,都是在默认的当前系统的根/下面设置NetBoot的,也就是在/Library/NetBoot目录里面,通过修改可以变更这个目录到其它的分区/盘的其它目录中。   简单介绍NetBoot服务,NetBoot/NetInstall服务用于网络启动Mac电脑/安装Mac系统的服务,它的启动功能如同无盘工作站,而安装可以即时网络更新客户端的Mac操作系统。   <table id="ep:e" style="width: 100%;" border="1" cellspacing="0" cellpadding="3" bordercolor="#000000"><tbody><tr><td width="100%"><span style="font-family: Courier New; color: #660000;">#!/bin/bash</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">#This script sets up netbooting on a Leopard (Client) machine.</span><br style="font-family: Courier New; color: #660000;"/><br style="font-family: Courier New; color: #660000;"/><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;"># START WITH SOME SANITY CHECKS</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;"># -----------------------------</span><br style="font-family: Courier New; color: #660000;"/><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;"># Make sure only root can run our script</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">if [ "$(id -u)" != "0" ]; then</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">        echo "You must run this script as the root user.  (Try /"sudo $0/")"</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">        exit 1</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">fi;</span><br style="font-family: Courier New; color: #660000;"/><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;"># check that this is Mac OS X Leopard (Client)</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">if [[ "`sw_vers -productName`" != "Mac OS X" ]] || [[ "`sw_vers -productVersion`" &lt; "10.5" ]]; then</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">        echo "The script is designed to be run on Mac OS X Leopard, on a non-server version."</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">        exit 2</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">fi;</span><br style="font-family: Courier New; color: #660000;"/><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">echo "Make sure Internet Sharing is turned OFF Before continuing! (System Preferences &gt; Sharing)</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">Press Enter to continue."</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">read junk</span><br style="font-family: Courier New; color: #660000;"/><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;"># CREATE DIRECTORIES AND SIMLINKS NEEDED FOR NETBOOTING</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;"># -----------------------------------------------------</span><br style="font-family: Courier New; color: #660000;"/><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">mkdir -p /Library/NetBoot/NetBootSP0</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">mkdir /Library/NetBoot/NetBootClients0</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">chown root:admin /Library/NetBoot/NetBoot*</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">chmod 775 /Library/NetBoot/NetBoot*</span><br style="font-family: Courier New; color: #660000;"/><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">cd /Library/NetBoot</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">ln -s NetBootSP0 /Library/NetBoot/.sharepoint</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">ln -s NetBootClients0 /Library/NetBoot/.clients</span><br style="font-family: Courier New; color: #660000;"/><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;"># EXPORT NETBOOTING FOLDERS OVER NFS (NETWORK FILE SYSTEM)</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;"># --------------------------------------------------------</span><br style="font-family: Courier New; color: #660000;"/><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">echo "/Library/NetBoot/NetBootSP0 -ro" &gt;&gt; /etc/exports</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;"># Note that as soon as the file changes, the OS restarts the NFS daemon</span><br style="font-family: Courier New; color: #660000;"/><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;"># CREATE DIRECTORIES AND SIMLINKS NEEDED FOR NETBOOTING</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;"># --------------------------------Boot</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">ln -s /Library/NetBoot /private/tftpboot/NetBoot</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">service tftp start</span><br style="font-family: Courier New; color: #660000;"/><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;"># SET UP BSDP (BOOT SERVICE DISCOVERY PROTOCOL)</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;"># ---------------------------------------------</span><br style="font-family: Courier New; color: #660000;"/><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;"># Create the /etc/bootpd.plist file.</span><br style="font-family: Courier New; color: #660000;"/><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;"># This file below is based on information from the bootpd man page.</span><br style="font-family: Courier New; color: #660000;"/><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">echo '&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">&lt;plist version="1.0"&gt;</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">&lt;dict&gt;</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">        &lt;key&gt;bootp_enabled&lt;/key&gt;</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">        &lt;string&gt;en0&lt;/string&gt;</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">        &lt;key&gt;netboot_enabled&lt;/key&gt;</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">        &lt;string&gt;en0&lt;/string&gt;</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">        &lt;key&gt;old_netboot_enabled&lt;/key&gt;</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">        &lt;string&gt;en0&lt;/string&gt;</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">&lt;/dict&gt;</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">&lt;/plist&gt;' &gt; /etc/bootpd.plist</span><br style="font-family: Courier New; color: #660000;"/><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">service bootps start</span><br style="font-family: Courier New; color: #660000;"/><br style="font-family: Courier New; color: #660000;"/><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;"># WE ARE FINISHED</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;"># ---------------</span><br style="font-family: Courier New; color: #660000;"/><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">echo"NetBoot setup script complete. Please make sure to add the NetBootSP0and NetBootClients0 folders to your Shared Folders (System Preferences&gt; Sharing &gt; File Sharing)."</span><br style="font-family: Courier New; color: #660000;"/><br/></td></tr></tbody></table>  
';