summaryrefslogtreecommitdiffstats
path: root/rc.d/net-profiles
blob: ae9c00e92f479757972036ed52c080b61b3815d7 (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
#!/bin/bash
#
# This script utilizes netcfg-daemon.

. /etc/rc.conf
. /etc/rc.d/functions
. /usr/lib/network/globals

case "$1" in
    start)
        if ! ck_daemon net-profiles; then
            exit_stderr "net-profiles has already been started.  Try '/etc/rc.d/net-profiles restart'"
        fi

        # Ensure any device renaming has occurred as intended
        for daemon in "${DAEMONS[@]}"; do
            if [[ $daemon = net-rename ]]; then
                if ck_daemon net-rename; then
                    /etc/rc.d/net-rename start
                fi
          fi
        done

        # $NET env var is passed from the kernel boot line
        if [[ -n $NET ]]; then
            # Record the connected profile for net-profiles stop
            if [[ $NET = menu ]]; then
                /usr/bin/netcfg-menu || exit 1
                mv "$STATE_DIR"/{menu,netcfg-daemon}
            else
                /usr/bin/netcfg check-iface "$NET" || exit 1
                echo "$NET" > "$STATE_DIR/netcfg-daemon"
            fi
        elif ! /usr/bin/netcfg-daemon start; then
            exit_err "No profile started."
        fi
        add_daemon net-profiles
        ;;
    stop)
        if ck_daemon net-profiles; then
            exit_stderr "net-profiles is not running"
        fi
        /usr/bin/netcfg-daemon stop
        rm_daemon net-profiles
        ;;
    restart)
        "$0" stop
        sleep 1
        "$0" start
        ;;
    *)
        exit_stderr "Usage: $0 {start|stop|restart}"
esac

# vim: ft=sh ts=4 et sw=4: