summaryrefslogtreecommitdiff
path: root/net-physical
blob: de167c1a7fc2fb91c012f0c2f8d8e4dcb33378ac (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
#!/bin/sh


links=`dladm show-phys -p -o link`

for link in $links; do
    if ipadm "create-if" $link; then # create-if is in quotes because ViM goes crazy
        timeout=30
        state=`dladm show-phys -p -o state $link`
        if [ "$state" == down ]; then
            # http://slackware.com/~alien/rc_scripts/rc.inet1
            timeout=7
        fi
        echo "Trying DHCP for $link ... " >/dev/msglog
        if ipadm create-addr -T dhcp -w $timeout $link/dhcp; then
            addrstate=`ipadm show-addr -p -o state $link/dhcp`
            if [ "$addrstate" = ok ]; then
                echo "Configured $link via DHCP" >/dev/msglog
                exit 0
            else
                ipadm delete-addr $link/dhcp
            fi
        fi
    fi
done

echo 'No network interfaces are configured via DHCP' >/dev/msglog