ifplugd.action 1.38 KB
Newer Older
1
#! /bin/bash
2
#
3
# ifplugd.action script for netctl
4

5
. /usr/lib/netctl/globals
6

Jouke Witteveen's avatar
Jouke Witteveen committed
7
PROFILE_FILE="$STATE_DIR/ifplugd-$1.profile"
8
9
10

case "$2" in
  up)
11
    while IFS= read -r profile; do
Jouke Witteveen's avatar
Jouke Witteveen committed
12
13
        if ForceConnect=yes "$SUBR_DIR/network" start "$profile"; then
            mkdir -p "$(dirname "$PROFILE_FILE")"
14
            printf '%s' "$profile" > "$PROFILE_FILE"
Jouke Witteveen's avatar
Jouke Witteveen committed
15
16
            exit 0
        fi
17
    done < <(filter_profiles "$1" ethernet | while IFS= read -r profile; do
18
19
        report_debug "Examining profile '$profile'"
        (
20
          load_profile "$profile" > /dev/null
21
22
23
24
25
26
27
          # Prioritize dhcp based profiles as they can outright fail, whereas
          # it is difficult to tell if a profile with a static address fails
          if [[ $IP == "dhcp" || $IP6 == dhcp* ]]; then
              : ${ExcludeAuto:=no}
              : ${Priority:=1}
          fi
          is_yes "${ExcludeAuto:-yes}" && exit
28
          printf '%i\t%s\n' "${Priority:-0}" "$profile"
29
30
31
32
          report_debug "Included profile '$profile'"
        )
    done | sort -nrs -k 1,1 | cut -f 2-)
    report_error "Could not start any suitable profile"
33
34
  ;;
  down)
35
    if [[ -e "$PROFILE_FILE" ]]; then
36
37
38
39
        if ForceConnect=yes "$SUBR_DIR/network" stop "$(< "$PROFILE_FILE")"; then
            rm -f "$PROFILE_FILE"
            exit 0
        fi
40
41
42
    fi
  ;;
  *)
Jouke Witteveen's avatar
Jouke Witteveen committed
43
    echo "Wrong arguments" >&2
44
  ;;
Jouke Witteveen's avatar
Jouke Witteveen committed
45
esac
46
47

exit 1
Jouke Witteveen's avatar
Jouke Witteveen committed
48
49
50


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