small-package/luci-app-wizard/root/etc/init.d/wizard

140 lines
4.1 KiB
Plaintext
Raw Normal View History

2021-11-20 16:02:04 +08:00
#!/bin/sh /etc/rc.common
START=19
2021-11-22 07:27:41 +08:00
extra_command "reconfig" ""
2021-11-20 16:02:04 +08:00
boot() {
XBOOT=1 start
}
add_wizard() {
[ "x$XBOOT" = "x1" ] && return 0
local cfg="$1"
2021-11-23 09:01:26 +08:00
local wan_proto wan_pppoe_user wan_pppoe_pass
2021-11-20 16:02:04 +08:00
local lan_ipaddr lan_netmask lan_dns lan_gateway dhcp
2021-11-22 15:48:16 +08:00
local device ipv6 old_ipv6
2021-11-20 16:02:04 +08:00
config_get wan_proto "$cfg" wan_proto
device=$(uci get network.wan.device 2>/dev/null)
case "${wan_proto}" in
dhcp)
uci delete network.wan
uci set network.wan=interface
uci set network.wan.device="$device"
uci set network.wan.proto='dhcp'
;;
pppoe)
config_get wan_pppoe_user "$cfg" wan_pppoe_user
config_get wan_pppoe_pass "$cfg" wan_pppoe_pass
2021-11-22 15:48:16 +08:00
[[ -n "${wan_pppoe_user} != $(uci -q get network.wan.username)" || -n "${wan_pppoe_pass} != $(uci -q get network.wan.password)" ]] && {
2021-11-21 20:29:32 +08:00
uci delete network.wan
uci set network.wan=interface
uci set network.wan.proto='pppoe'
uci set network.wan.device="$device"
uci set network.wan.username="${wan_pppoe_user}"
uci set network.wan.password="${wan_pppoe_pass}"
2021-11-20 16:02:04 +08:00
}
;;
esac
config_get lan_ipaddr "$cfg" lan_ipaddr
config_get lan_netmask "$cfg" lan_netmask
test -n "${lan_ipaddr}" && test -n "${lan_netmask}" && {
uci set network.lan.ipaddr="${lan_ipaddr}"
uci set network.lan.netmask="${lan_netmask}"
}
config_get siderouter "$cfg" siderouter
2021-11-21 20:29:32 +08:00
config_get old_siderouter "$cfg" old_siderouter
2021-11-20 16:02:04 +08:00
config_get lan_gateway "$cfg" lan_gateway
config_get dhcp "$cfg" dhcp
config_get lan_dns "$cfg" lan_dns
2022-01-09 20:32:26 +08:00
config_get ipv6 "$cfg" ipv6
config_get old_ipv6 "$cfg" old_ipv6
config_get autoupgrade_pkg "$cfg" autoupgrade_pkg
2021-11-22 15:48:16 +08:00
[ "$dhcp" == "0" ] && dhcp="1"
2022-01-20 09:14:17 +08:00
if [[ "${lan_gateway}" != "$(uci -q get network.lan.gateway)" || "${dhcp}" != "$(uci -q get dhcp.lan.ignore)" ]]; then
2021-11-22 20:31:55 +08:00
if [ "${siderouter}" == "1" ]; then
2021-11-20 16:02:04 +08:00
uci -q set network.lan.gateway="${lan_gateway}"
2022-01-20 09:14:17 +08:00
[ -n "$lan_dns" ] || lan_dns="${lan_gateway}"
2021-11-20 16:02:04 +08:00
[ -n "$dhcp" ] && uci -q set dhcp.lan.ignore="1" || uci -q del dhcp.lan.ignore
2021-11-22 20:31:55 +08:00
elif [ "${siderouter}" == "0" ]; then
2021-11-20 16:02:04 +08:00
uci -q del network.lan.gateway
uci -q del dhcp.lan.ignore
2022-01-20 09:14:17 +08:00
2021-11-21 20:29:32 +08:00
fi
2021-11-20 16:02:04 +08:00
fi
2022-01-08 09:08:25 +08:00
[ -n "$lan_dns" ] && {
[ "$(uci -q get dhcp.@dnsmasq[0].noresolv)" == 1 ] && {
uci -q del dhcp.@dnsmasq[0].noresolv
}
uci -q set network.wan.peerdns='0'
uci -q set network.lan.dns="${lan_dns}"
} || {
uci -q del network.wan.peerdns
uci -q del network.lan.dns
}
2021-11-21 20:29:32 +08:00
2021-11-22 09:35:50 +08:00
if [ "${ipv6}" != "${old_ipv6}" ]; then
2021-11-21 20:29:32 +08:00
if [ -n "${ipv6}" ]; then
2021-11-20 16:02:04 +08:00
uci -q delete dhcp.lan.ra
uci -q delete dhcp.lan.dhcpv6
uci -q set network.lan.delegate='0'
uci -q set network.wan.ipv6='0'
uci -q delete network.globals.ula_prefix
/etc/init.d/odhcpd disable
/etc/init.d/odhcpd stop
2021-11-21 20:29:32 +08:00
else
2021-11-20 16:02:04 +08:00
uci -q set dhcp.lan.ra='hybrid'
uci -q set dhcp.lan.dhcpv6='hybrid'
uci -q del network.lan.delegate
uci -q set network.wan.ipv6='auto'
/etc/init.d/odhcpd enable
/etc/init.d/odhcpd start
2021-11-21 03:37:55 +08:00
fi
2021-11-21 20:29:32 +08:00
uci -q set wizard.default.old_ipv6="${ipv6}"
fi
uci commit wizard
2021-11-22 20:31:55 +08:00
uci commit dhcp
2021-11-20 16:02:04 +08:00
uci commit network
(
2021-11-22 20:31:55 +08:00
/etc/init.d/network restart
2021-11-20 16:02:04 +08:00
/etc/init.d/dnsmasq reload)&
2022-01-09 20:32:26 +08:00
if [ "${autoupgrade_pkg}" == "0" ]; then
2022-01-14 20:33:43 +08:00
sed -i '/opkg-upgrade/d' /etc/crontabs/root
2022-01-09 20:32:26 +08:00
else
2022-01-14 20:33:43 +08:00
grep -q "opkg-upgrade" /etc/crontabs/root || {
2022-01-09 20:32:26 +08:00
hour="$(grep -m1 -ao '[4-6]' /dev/urandom | head -n1)"
min="$(grep -m1 -ao '[0-5][0-9]' /dev/urandom | head -n1)"
2022-01-14 20:33:43 +08:00
echo "$min $hour * * * . /etc/hotplug.d/online/51-opkg-upgrade >/dev/null 2>&1" >> /etc/crontabs/root
2022-01-09 20:32:26 +08:00
}
fi
2021-11-20 16:02:04 +08:00
}
2021-11-22 07:27:41 +08:00
reconfig() {
uci -q set wizard.default.wan_proto="$(uci -q get network.wan.proto)"
uci -q set wizard.default.wan_pppoe_user="$(uci -q get network.wan.username)"
uci -q set wizard.default.wan_pppoe_pass="$(uci -q get network.wan.password)"
uci -q set wizard.default.lan_ipaddr="$(uci -q get network.lan.ipaddr)"
uci -q set wizard.default.lan_netmask="$(uci -q get network.lan.netmask)"
uci -q set wizard.default.lan_gateway="$(uci -q get network.lan.gateway)"
uci -q set wizard.default.lan_dns="$(uci -q get network.lan.dns)"
2021-11-22 15:48:16 +08:00
[ "$(uci -q get dhcp.lan.ignore)" ] && uci -q set wizard.default.dhcp="0" || uci -q del wizard.default.dhcp
2021-11-22 07:27:41 +08:00
uci commit wizard
}
2021-11-20 16:02:04 +08:00
start() {
config_load wizard
config_foreach add_wizard wizard
}
restart() {
XRELOAD=1 start
}