aredn/files/etc/init.d/local

76 lines
2.6 KiB
Bash
Executable File

#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org
START=99
boot() {
[ -x /usr/local/bin/aredn_postupgrade ] && /usr/local/bin/aredn_postupgrade
# setup nvram variables
[ -x /usr/local/bin/nvram-setup ] && /usr/local/bin/nvram-setup
# run mode specific setup
[ -x /etc/config/local ] && /etc/config/local
[ -x /etc/local/services ] && /etc/local/services
# set POE passthrough if available
local poevalue=$(uci -q get aredn.@poe[0].passthrough)
if [ -z "$poevalue" ]; then
local dpval=$(jsonfilter -e '@.gpioswitch.poe_passthrough.default' < /etc/board.json)
if [ ! -z "$dpval" ]; then
uci -q add aredn poe
uci -q set aredn.@poe[0].passthrough="$dpval"
uci -q commit aredn
poevalue=$dpval
fi
fi
/usr/local/bin/poe_passthrough "${poevalue}"
# set USB passthrough if available
local usbvalue=$(uci -q get aredn.@usb[0].passthrough)
if [ -z "$usbvalue" ]; then
local duval=$(jsonfilter -e '@.gpioswitch.usb_power_switch.default' < /etc/board.json)
uci -q add aredn usb
uci -q set aredn.@usb[0].passthrough="$duval"
uci -q commit aredn
usbvalue=$duval
fi
/usr/local/bin/usb_passthrough "${usbvalue}"
# package repositories
local repos="core base arednpackages packages luci routing telephony"
set -- $repos
while [ -n "$1" ]; do
local ucirepo=$(uci -q get aredn.@downloads[0].pkgs_$1)
local distrepo=$(grep aredn_$1 /etc/opkg/distfeeds.conf | cut -d' ' -f3)
# get the URLs from distfeeds.conf and set the initial UCI values if not present
if [ -z $ucirepo ]; then
uci set aredn.@downloads[0].pkgs_$1=$distrepo
uci commit aredn
uci -c /etc/config.mesh set aredn.@downloads[0].pkgs_$1=$distrepo
uci -c /etc/config.mesh commit aredn
# check values in distfeeds.conf against UCI settings
# and change distfeeds.conf if needed (upgrades?)
elif [ $ucirepo != $distrepo ]; then
sed -i "s|$distrepo|$ucirepo|g" /etc/opkg/distfeeds.conf
fi
shift
done
# did the ethernet come up? we get one reboot to try to fix it.
pkt_lan=$(ifconfig br-lan | grep "RX packets" | sed "s/^.*RX packets:\(\d*\).*$/\1/")
pkt_dtd=$(ifconfig br-dtdlink | grep "RX packets" | sed "s/^.*RX packets:\(\d*\).*$/\1/")
pkt_wan=$(ifconfig br-wan | grep "RX packets" | sed "s/^.*RX packets:\(\d*\).*$/\1/")
if [ ! -f /did_ether_reboot -a "$pkt_lan" = "0" -a "$pkt_dtd" = "0" -a "$pkt_wan" = "0" ]; then
touch /did_ether_reboot
reboot
exit
fi
rm -f /did_ether_reboot
if [ -z "$(uci -q get aredn.@alerts[0])" ]; then
uci -q add aredn alerts
uci -q commit aredn
fi
}