1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-02-15 03:51:51 +00:00
openmptcprouter-feeds/omr-6in4/files/etc/init.d/omr-6in4
2018-06-08 16:48:15 +02:00

27 lines
No EOL
1 KiB
Bash
Executable file

#!/bin/sh /etc/rc.common
# Copyright (C) 2018 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
START=99
USE_PROCD=1
service_triggers() {
procd_add_interface_trigger "omrvpn"
}
reload_service() {
iface=$(uci -q get glorytun.vpn.dev)
addr=$(ubus call network.interface.omrvpn status | jsonfilter -e '@["ipv4-address"][0].address | tr -d "\n")
[ -z "$addr" ] && [ -n "$iface" ] && addr=$(ip -4 addr show dev $iface | grep inet | awk '{print $2}' | cut -d/ -f1 | grep -v / | tr -d "\n")
peer=$(ubus call network.interface.omrvpn status | jsonfilter -e '@.route[0].nexthop' | tr -d "\n")
[ -z "$peer" ] && [ -n "$iface" ] && peer=$(ip -4 r list dev $iface | grep kernel | awk '/proto kernel/ {print $1}' | grep -v / | tr -d "\n")
[ -z "$addr" ] && exit 0
[ -z "$peer" ] && exit 0
if [ "$addr" != "$(uci -q get network.omr6in4.ipaddr)" ] || [ "$peer" != "$(uci -q get network.omr6in4.peeraddr)" ]; then
uci -q batch <<-EOF
set network.omr6in4.ipaddr=$addr
set network.omr6in4.peeraddr=$peer
EOF
uci -q commit network
ifup omr6in4
fi
}