summaryrefslogtreecommitdiffstats
path: root/contrib/common.hook
blob: 88066cfecbf9bec18b4b3672894ef4553ec40861 (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
86
87
88
89
90
91
### Sample netcfg hook script showing how to declare shared settings
#
### These functions and variables will be available to all profiles
### (They can be manually overridden by any profile.)
### To install, make this executable and put it in /etc/network.d/hooks

function RUNDAEMON {
    # "RUNDAEMON [options] daemon { start | stop }" will run the daemon
    # -d DEP: will only run if daemon DEP is registered as also started/stopped in /var/run/daemons
    #  will only stop if daemon is running (or option -f)
    #  will only start if daemon is in the DAEMONS array (or option -f)
    local force dep
    while true; do
        if [[ "$1" = "-f" ]]; then
            force=1
            shift
        elif [[ "$1" = "-d" ]]; then
            [[ -e "/var/run/daemons/$2" ]]
            if [ $? -eq 0 ]; then
                case "$dep" in
                    yes) ;;
                    no) dep=mixed;;
                    *) dep=yes;;
                esac
            else
                case "$dep" in
                    no) ;;
                    yes) dep=mixed;;
                    *) dep=no;;
                esac
            fi
            shift 2
        else
            break
        fi
    done
    local daemon="$1"
    shift
    if [[ ! -x "/etc/rc.d/$daemon" ]]; then
        echo "/etc/rc.d/$daemon isn't executable." >&2
        return 1
    fi
    case "$1" in
        start)
            if [[ "$dep" = no || "$dep" = mixed ]]; then
                force=0
            elif [[ "$force" -ne 1 ]]; then
                for f in "${DAEMONS[@]}"; do
                    if [[ "$f" = "$daemon" || "$f" = "@$daemon" ]]; then
                        force=1
                        break
                    fi
                done
            fi
            ;;
        stop)
            if [[ "$dep" = yes || "$dep" = mixed ]]; then
                force=0
            elif [[ "$force" -ne 1 ]]; then
                [[ ! -e "/var/run/$daemon" ]]
                force=$?
            fi
            ;;
        *)
            force=1
            ;;
    esac
    if [[ "$force" -eq 1 ]]; then
        "/etc/rc.d/$daemon" "$@"
        local result=$?
        stat_busy "Resuming netcfg $PROFILE..."     # else we'll get a [DONE] or [FAIL] at the end of a third blank line, after messages from $daemon
        return $result
    fi
    return 0    # $daemon doesn't satisfy conditions, fail quietly
                # returning 1 would make our POST_UP script, and hence our connection attempt, fail
}

# Example of some things you might do in your POST_UP/PRE_DOWN scripts
#   (In fact, I couldn't get awesome-client to work on its own in this context, I had to call a wrapper instead that
#   sources the file in ~/.dbus/session-bus and then exports DBUS_SESSION_BUS_ADDRESS, and then calls awesome-client.)
#
PRE_DOWN='RUNDAEMON -f netfs stop'
POST_DOWN='( sleep 3 && echo "mynetworkfun()" | sudo -Hu me /usr/bin/awesome-client 2>/dev/null) &'

POST_UP='( sleep 3 && echo "mynetworkfun()" | sudo -Hu me /usr/bin/awesome-client 2>/dev/null) & RUNDAEMON -f -d nfs-common netfs start'

# Quirks and other variables defined here will apply to all your profiles...
QUIRKS=()
WPA_GROUP="network"

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