summaryrefslogtreecommitdiffstats
path: root/hooks/net
blob: b964d13d369dceb20693af9174b04a9a3a2eba7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# vim: set ft=sh:
run_hook ()
{
    local line defaultrootpath defaultserver
    # These variables will be parsed from /tmp/net-*.conf generated by ipconfig
    local DEVICE
    local IPV4ADDR IPV4BROADCAST IPV4NETMASK IPV4GATEWAY IPV4DNS0 IPV4DNS1
    local HOSTNAME DNSDOMAIN NISDOMAIN ROOTSERVER ROOTPATH
    local filename
    # /tmp/net-*.conf

    if [ -z "${ip}" -a -n "${nfsaddrs}" ]; then
        ip="${nfsaddrs}"
    fi

    if [ -n "${ip}" ]; then
        # setup network and save some values
        ipconfig "ip=${ip}"

        . /tmp/net-*.conf

        # calculate nfs_server, nfs_path and nfs_option for later nfs mount
        if [ "${root}" = "/dev/nfs" -o "${nfsroot}" != "" ]; then
            # parse ROOTPATH if defined by dhcp server
            if [ -n "${ROOTPATH}" ]; then
                line="${ROOTPATH}"
                nfs_server="${line%%:*}"
                [ "${nfs_server}" = "${line}" ] && nfs_server="${ROOTSERVER}"
                defaultserver="${nfs_server}"
                line="${line#*:}"
                nfs_path="${line}"
                defaultrootpath="${nfs_path}"
            else
                # define a default ROOTPATH
                if [ "${ROOTPATH}" = "" ]; then
                    defaultrootpath="/tftpboot/${IPV4ADDR}"
                fi
            fi

            # parse nfsroot if present (overrides ROOTPATH)
            if [ -n "${nfsroot}" ]; then
                line="${nfsroot}"
                nfs_server="${line%%:*}"
                [ -z "${nfs_server}" ] && nfs_server="${defaultserver}"
                line="${line#*:}"
                nfs_path="${line%%,*}"
                line="${line#"${nfs_path}"}"
                [ -z "${nfs_path}" ] && nfs_path="${defaultrootpath}"
                nfs_option="${line#","}"
            fi

            # ensure root and filesystem type are set proper for nfs boot
            root="/dev/nfs"
            rootfstype="nfs"

            echo "NFS-Mount: ${nfs_server}:${nfs_path}"

            # set mount handler for NFS
            mount_handler="nfs_mount_handler"
        fi
    fi
}

nfs_mount_handler() {
    if [ -z "$nfs_server" -o -z "$nfs_path" ]; then
        err "Unable to mount root filesystem over NFS: wrong parameters."
        echo "You are being dropped to a recovery shell"
        echo "    Type 'exit' to try and continue booting"
        launch_interactive_shell
        msg "Trying to continue (this will most likely fail) ..."
    fi
    nfsmount ${nfs_option:+-o ${nfs_option}} "${nfs_server}:${nfs_path}" "$1"
}