2 export PATH
=${PATH}:/sbin
3 NETCFG
=/etc
/network
/interfaces
5 [ "$1" = "-v" ] && DEBUG
="printf" || DEBUG
="true"
12 if echo "${line}" |
grep -q "[ \t]*#"
15 elif echo "${line}" |
grep -q "^iface [^ ]* inet6 [^ ]*$"
17 echo "${line}" |
( IFS
=' ' read -r _ iface _ method
18 "${DEBUG}" "Found %s with method %s.\n" "${iface}" "${method}"
19 if [ "${method}" != "static" ]
21 "${DEBUG}" "Interface %s does not use static configuration. Ambiguous config, exiting.\n" "${iface}"
26 elif [ -n "${lastiface}" ]
28 if gateway
=$
(echo "${line}" |
grep -o "gateway *[0-9a-fA-F:]*:[0-9a-fA-F:]*")
30 if [ -z "${lastgateway}" ]
32 lastgateway
="${gateway}"
33 "${DEBUG}" "Found %s for %s.\n" "${lastgateway}" "${lastiface}"
35 "${DEBUG}" "A gateway was already defined for another interface. Ambiguous situation, exiting.\n"
42 if [ -z "${lastiface}" ]
44 "${DEBUG}" "No inet6 interface config found.\n"
47 iface
=$
(echo "${lastiface}" |
grep -oP "(?<=iface )[^ ]*(?= inet6)")
48 "${DEBUG}" "Checking if %s needs to be reconfigured...\n" "${iface}"
51 defroute
=$
(ip
-6 route |
grep "^default ")
52 if [ -z "${defroute}" ] ||
echo "${defroute}" |
grep -q " proto ra "
54 # If we get here, we will provide output of our actions. It is not affected by verbose mode.
55 printf "No default route, or it is RA-configured. Reconfiguring %s...\n" "${iface}"
57 ip link
set "${iface}" down
60 "${DEBUG}" "Found healthy default route: %s.\nNo action is necessary.\n" "${defroute}"