archrelease: copy trunk to staging-x86_64
[arch-packages.git] / mkinitcpio-nfs-utils / trunk / initcpio-hook-net
blob4d1ebb95605e1b0655dccde2ebab9446098f5986
1 # vim: set ft=sh:
2 run_hook() {
3     local line i net_mac bootif_mac bootif_dev defaultrootpath defaultserver
4     # These variables will be parsed from /tmp/net-*.conf generated by ipconfig
5     local DEVICE
6     local IPV4ADDR IPV4BROADCAST IPV4NETMASK IPV4GATEWAY IPV4DNS0 IPV4DNS1
7     local HOSTNAME DNSDOMAIN NISDOMAIN ROOTSERVER ROOTPATH
8     local filename
9     # /tmp/net-*.conf
11     if [ -z "${ip}" -a -n "${nfsaddrs}" ]; then
12         ip="${nfsaddrs}"
13     fi
15     if [ -n "${ip}" ]; then
16         if [ -n "${BOOTIF}" ]; then
17             bootif_mac=${BOOTIF#01-}
18             bootif_mac=${bootif_mac//-/:}
19             for i in /sys/class/net/*/address; do
20                 read net_mac < ${i}
21                 if [ "${bootif_mac}" == "${net_mac}" ]; then
22                     bootif_dev=${i#/sys/class/net/}
23                     bootif_dev=${bootif_dev%/address}
24                     break
25                 fi
26             done
27             ip="${ip}::${bootif_dev}"
28         fi
30         # setup network and save some values
31         ipconfig "ip=${ip}"
33         for conf in /tmp/net-*.conf; do
34             [ -f "$conf" ] && . "$conf"
35         done
37         # calculate nfs_server, nfs_path and nfs_option for later nfs mount
38         if [ "${root}" = "/dev/nfs" -o "${nfsroot}" != "" ]; then
39             # parse ROOTPATH if defined by dhcp server
40             if [ -n "${ROOTPATH}" ]; then
41                 line="${ROOTPATH}"
42                 nfs_server="${line%%:*}"
43                 [ "${nfs_server}" = "${line}" ] && nfs_server="${ROOTSERVER}"
44                 defaultserver="${nfs_server}"
45                 line="${line#*:}"
46                 nfs_path="${line}"
47                 defaultrootpath="${nfs_path}"
48             else
49                 # define a default ROOTPATH
50                 if [ "${ROOTPATH}" = "" ]; then
51                     defaultrootpath="/tftpboot/${IPV4ADDR}"
52                 fi
53             fi
55             # parse nfsroot if present (overrides ROOTPATH)
56             if [ -n "${nfsroot}" ]; then
57                 line="${nfsroot}"
58                 nfs_server="${line%%:*}"
59                 [ -z "${nfs_server}" ] && nfs_server="${defaultserver}"
60                 line="${line#*:}"
61                 nfs_path="${line%%,*}"
62                 line="${line#"${nfs_path}"}"
63                 [ -z "${nfs_path}" ] && nfs_path="${defaultrootpath}"
64                 nfs_option="${line#","}"
65             fi
67             # ensure root and filesystem type are set proper for nfs boot
68             root="/dev/nfs"
69             rootfstype="nfs"
71             echo "NFS-Mount: ${nfs_server}:${nfs_path}"
73             # set mount handler for NFS
74             mount_handler="nfs_mount_handler"
75         fi
76     fi
79 nfs_mount_handler() {
80     if [ -z "$nfs_server" -o -z "$nfs_path" ]; then
81         err "Unable to mount root filesystem over NFS: wrong parameters."
82         echo "You are being dropped to a recovery shell"
83         echo "    Type 'exit' to try and continue booting"
84         launch_interactive_shell
85         msg "Trying to continue (this will most likely fail) ..."
86     fi
87     nfsmount ${nfs_option:+-o ${nfs_option}} "${nfs_server}:${nfs_path}" "$1"
90 # vim: set ft=sh ts=4 sw=4 et: