summaryrefslogtreecommitdiffstats
path: root/src/net-profiles
blob: d9cc4da7be226536dbb4b73f4b8c95e921169a9d (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
#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

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

        # Ensure any device renaming has occurred as intended
        for daemon in "${DAEMONS[@]}"; do
            if [ "$daemon" = "${daemon#!}" -a "$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
        [ ! "$NETWORKS_MENU_TIMEOUT" ] && NETWORKS_MENU_TIMEOUT=5 
        
        if [[ "$NET" = "menu" ]]; then
                /usr/bin/netcfg-menu $NETWORKS_MENU_TIMEOUT
        elif [[ "$NET" ]]; then
                /usr/bin/netcfg2 -c $NET
        else 
            # No NET= passed at boot, go to NETWORKS=()
            for network in ${NETWORKS[@]}; do
                case $network in
                    menu) # Pull up menu of networks
                        /usr/bin/netcfg-menu $NETWORKS_MENU_TIMEOUT
                        ;;
                    auto-*) # Automatic configuration, store type and get interface next
                        auto=$network
                        ;;
                    *) # Either interface or profile
                        if [[ "$auto" ]]; then # Auto set, so interface
                            /usr/bin/netcfg-$auto $network
                            unset auto 
                        elif [ "$network" = "${network#!}" ]; then # otherwise profile
                            /usr/bin/netcfg2 -c $network
                        fi
                        ;;
                esac
            done
        fi            

        add_daemon net-profiles
        ;;
    stop)
        # shutdown any profiles started by netcfg (or from NET_PROFILES in rc.conf)
        /usr/bin/netcfg2 -a
        rm_daemon net-profiles
        ;;
    restart)
        $0 stop; sleep 1; $0 start
        ;;
    *)
        echo "usage: $0 {start|stop|restart}"  
esac

# vim: set ts=4 et sw=4: