]> git.saurik.com Git - apple/launchd.git/blobdiff - launchd/src/rc.netboot
launchd-328.tar.gz
[apple/launchd.git] / launchd / src / rc.netboot
index 248897632bccda0fb8302b9364ffd4d0145f1246..654ce4966a6c4c2a238f62a6021874453164b3be 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/sh
 ##
-# Copyright 2002 Apple Computer, Inc.
+# Copyright 2002-2009 Apple Inc.
 #
 # This script configures NetBoot
 ##
@@ -27,6 +27,8 @@ NETBOOT_SHADOW=${NETBOOT_SHADOW:-NETWORK-}
 Failed()
 {
        echo rc.netboot: $1
+       echo rc.netboot: $1 > /dev/console
+       sleep 5
        exit 1
 }
 
@@ -74,11 +76,24 @@ common_start()
 
 local_mount()
 {
-    volinfo=`autodiskmount -F 2>/dev/null`
-    if [ $? -ne 0 ]; then
-       echo "autodiskmount -F found no local drives"
-       return 1
-    fi
+    tries=0
+    limit=11
+    while [ $tries -lt $limit ]; do
+       tries=$(( tries + 1 ))
+       volinfo=`autodiskmount -F 2>/dev/null`
+       if [ $? -ne 0 ]; then
+           if [ $tries -lt $limit ]; then
+               echo "Waiting for local drives..."
+               echo "Waiting for local drives (retry ${tries}/$(( limit - 1 )))..." > /dev/console
+               sleep 5
+           else
+               echo "autodiskmount -F found no local drives"
+               return 1
+           fi
+       else
+           tries=$limit
+       fi
+    done
     set ${volinfo}
     devname=$1
     fstype=$2
@@ -105,15 +120,19 @@ network_mount()
        return 1
     fi
     case "${mount_from}" in
-       afp:*) fstype=afp;;
+       afp:*)
+               fstype=afp
+               kextutil -v 0 /System/Library/Filesystems/AppleShare/asp_tcp.kext
+               kextutil -v 0 /System/Library/Filesystems/AppleShare/afpfs.kext
+               ;;
        nfs:*) fstype=nfs;;
        *) echo "unknown network filesystem mount from ${mount_from}"
           return 1
           ;;
     esac
-    mount -t "${fstype}" "${mount_from}" "${NETBOOT_MOUNT}"
+    mount -t "${fstype}" -o nobrowse "${mount_from}" "${NETBOOT_MOUNT}"
     if [ $? -ne 0 ]; then
-       echo "mount -t ${fstype} ${mount_from} ${NETBOOT_MOUNT} failed"
+       echo "mount -t ${fstype} -o nobrowse ${mount_from} ${NETBOOT_MOUNT} failed"
        return 1
     fi
     common_start "${NETBOOT_MOUNT}" "${shadow_path}"
@@ -158,28 +177,24 @@ do_start()
 
 }
 
-do_computername()
+do_init()
 {
-    machine_name=$(ipconfig netbootoption machine_name 2>&1)
-    if [ $? -ne 0 ]; then
-       echo "no machine name option available"
-    else
-       echo "Setting ComputerName to ${machine_name}"
-       scutil --set ComputerName "${machine_name}"
-    fi
-}
+    # attach the shadow file to the root disk image
+    do_start
 
-do_vm()
-{
-    swapdir=${1:-/private/var/vm}
+    # make sure the root filesystem is clean
+    fsck -p || fsck -fy || Failed "Could not clean root filesystem"
 
-    mounted_from=$(mount | sed -n 's:\(.*\) on .*/var/netboot.*:\1:p')
+    # make it writable
+    mount -uw /
 
+    # adjust /private/var/vm to point to the writable area (if not diskless)
+    swapdir=/private/var/vm
+    mounted_from=$(mount | sed -n 's:\(.*\) on .*/var/netboot.*:\1:p')
     case "${mounted_from}" in
        /dev/*)
                netboot_dir="${NETBOOT_MOUNT}/.com.apple.NetBootX"
                if [ -d "${netboot_dir}" ]; then
-                       rm -rf "${netboot_dir}/app_profile"
                        rm -rf "${swapdir}"
                        ln -s "${netboot_dir}" "${swapdir}"
                fi
@@ -187,8 +202,18 @@ do_vm()
        *)
        ;;
     esac
+
+    # set the ComputerName based on what the NetBoot server told us it was
+    machine_name=$(ipconfig netbootoption machine_name 2>&1)
+    if [ $? -ne 0 ]; then
+       echo "no machine name option available"
+    else
+       echo "Setting ComputerName to ${machine_name}"
+       scutil --set ComputerName "${machine_name}"
+    fi
 }
 
+
 if [ $# -lt 1 ] ; then
     exit 0
 fi
@@ -198,14 +223,8 @@ command=$1
 shift
 
 case "${command}" in
-    start)
-       do_start $@
-       ;;
-    setup_vm)
-       do_vm $@
-       ;;
-    setup_computername)
-       do_computername $@
+    init)
+       do_init $@
        ;;
 esac