summaryrefslogtreecommitdiffstats
path: root/hooks/net
blob: 86535bb3eb74b16776aba8286985c6214a242fb5 (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
74
75
76
77
78
79
80
81
82
83
84
85
# vim: set ft=sh:
run_hook ()
{
    local line i address netmask gateway dns0 dns1 rootserver rootpath defaultrootpath defaultserver

    : > /ip_opts

    if [ -n "${ip}" ]; then
        # setup network and save some values
        ipconfig "${ip}" | while read line; do
            # echo ":: ${line}"
            if [ "${line#"IP-Config:"}" != "${line}" ]; then
                continue
            fi
            line="$(echo ${line} | sed -e 's/ :/:/g;s/: /=/g')"
            for i in ${line}; do
                case "${i}" in
                    address=*)
                        echo "${i}" >> /ip_opts
                        ;;
                    netmask=*)
                        echo "${i}" >> /ip_opts
                        ;;
                    gateway=*)
                        echo "${i}" >> /ip_opts
                        ;;
                    dns0=*)
                        echo "${i}" >> /ip_opts
                        ;;
                    dns1=*)
                        echo "${i}" >> /ip_opts
                        ;;
                    rootserver=*)
                        echo "${i}" >> /ip_opts
                        ;;
                    rootpath=*)
                        echo "${i}" >> /ip_opts
                        ;;
                esac
            done
        done

        . /ip_opts

        echo "IP-Config: ${address}/${netmask}"
        echo "IP-Config: gw: ${gateway}    dns0: ${dns0}    dns1: ${dns1}"

        # 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/${address}"
                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-root: ${nfs_server}:${nfs_path}"
        fi
    fi
}