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

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

### 设置Mac OS X 10.4 Tiger打开NetBoot服务的脚本   <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 Tiger (Client) machine.</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;"># 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 Tiger (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.4" ]] || [[ "`sw_vers -productVersion`" &gt;"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 Tiger, 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 "This will now setup NetBooting on your machine. </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 FOLDERS AND SYMLINKS</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;"/><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;">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 </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;">nicl . -create /exports</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">nicl . -create '/exports///Library//NetBoot//NetBootSP0' opts ro</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">service com.apple.portmap start</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">mountd</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">nfsd -t -u</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;"># SETUP AFP SHAREPOINTS AND BSDP </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;"/><span style="font-family: Courier New; color: #660000;">nicl . -create /config/SharePoints/NetBootSP0</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">nicl . -create /config/SharePoints/NetBootSP0 afp_name NetBootSP0</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">nicl . -create /config/SharePoints/NetBootSP0 afp_shared 1</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">nicl . -create /config/SharePoints/NetBootSP0 afp_guest 0</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">nicl . -create /config/SharePoints/NetBootSP0 directory_path /Library/NetBoot/NetBootSP0</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;">nicl . -create /config/SharePoints/NetBootClients0</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">nicl . -create /config/SharePoints/NetBootClients0 afp_name NetBootClients0</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">nicl . -create /config/SharePoints/NetBootClients0 afp_shared 1</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">nicl . -create /config/SharePoints/NetBootClients0 afp_guest 0</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">nicl . -create /config/SharePoints/NetBootClients0 directory_path /Library/NetBoot/NetBootClients0</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;">nicl . -create /config/NetBootServer</span><br style="font-family: Courier New; color: #660000;"/><span style="font-family: Courier New; color: #660000;">nicl . -create /config/dhcp netboot_enabled en0</span><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;"/><span style="font-family: Courier New; color: #660000;"># SETUP TFTP SYMLINK</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;"/><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;">echo "NetBoot setup script complete."</span><br/></td></tr></tbody></table>      
';