blob: 42d1c5aa6c82df63b33328bef43960994dd6a013 (
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
|
#! /bin/bash
#
# ifplugd.action script for netctl
. /usr/lib/network/globals
PROFILE_FILE="$STATE_DIR/ifplugd_$1.profile"
case "$2" in
up)
while read -r profile; do
if ForceConnect=yes "$SUBR_DIR/network" start "$profile"; then
mkdir -p "$(dirname "$PROFILE_FILE")"
printf "%s" "$profile" > "$PROFILE_FILE"
exit 0
fi
done < <(list_profiles | while read -r profile; do
report_debug "Examining profile '$profile'"
(
source "$PROFILE_DIR/$profile" > /dev/null
[[ $Interface == "$1" && $Connection == "ethernet" ]] || exit
# 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
printf "%i\t%s\n" "${Priority:-0}" "$profile"
report_debug "Included profile '$profile'"
)
done | sort -nrs -k 1,1 | cut -f 2-)
report_error "Could not start any suitable profile"
;;
down)
if [[ -e "$PROFILE_FILE" ]]; then
if ForceConnect=yes "$SUBR_DIR/network" stop "$(< "$PROFILE_FILE")"; then
rm -f "$PROFILE_FILE"
exit 0
fi
fi
;;
*)
echo "Wrong arguments" >&2
;;
esac
exit 1
# vim: ft=sh ts=4 et sw=4:
|