2022-03-13 21:19:04 -06:00
|
|
|
#! /usr/bin/lua
|
|
|
|
--[[
|
|
|
|
|
2024-05-29 01:45:25 -06:00
|
|
|
Part of AREDN® -- Used for creating Amateur Radio Emergency Data Networks
|
2022-03-13 21:19:04 -06:00
|
|
|
Copyright (C) 2021 Tim Wilkinson
|
|
|
|
See Contributors file for additional contributors
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation version 3 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Additional Terms:
|
|
|
|
|
2024-05-29 01:45:25 -06:00
|
|
|
Additional use restrictions exist on the AREDN® trademark and logo.
|
2022-03-13 21:19:04 -06:00
|
|
|
See AREDNLicense.txt for more info.
|
|
|
|
|
2024-05-29 01:45:25 -06:00
|
|
|
Attributions to the AREDN® Project must be retained in the source code.
|
2022-03-13 21:19:04 -06:00
|
|
|
If importing this code into a new or existing project attribution
|
2024-05-29 01:45:25 -06:00
|
|
|
to the AREDN® project must be added to the source code.
|
2022-03-13 21:19:04 -06:00
|
|
|
|
|
|
|
You must not misrepresent the origin of the material contained within.
|
|
|
|
|
|
|
|
Modified versions must be modified to attribute to the original source
|
|
|
|
and be marked in reasonable ways as differentiate it from the original
|
|
|
|
version
|
|
|
|
|
|
|
|
--]]
|
|
|
|
|
|
|
|
require("aredn.utils")
|
2024-04-01 23:15:45 -06:00
|
|
|
require("aredn.info")
|
2022-03-13 21:19:04 -06:00
|
|
|
require("aredn.hardware")
|
2022-08-11 01:19:33 -06:00
|
|
|
require("uci")
|
2022-03-13 21:19:04 -06:00
|
|
|
|
2024-04-01 23:15:45 -06:00
|
|
|
local needsrun = aredn.info.get_nvram("nodeupgraded")
|
2022-03-13 21:19:04 -06:00
|
|
|
if needsrun == "" or needsrun == "0" then
|
|
|
|
print "Node not upgraded, exiting"
|
|
|
|
os.exit(0)
|
|
|
|
end
|
|
|
|
|
2024-04-01 23:15:45 -06:00
|
|
|
local config = aredn.info.get_nvram("config")
|
2022-03-13 21:19:04 -06:00
|
|
|
if config ~= "mesh" then
|
|
|
|
print "This node was previously configured in non-mesh mode and is no longer implemented. Returning to 'firstboot'."
|
|
|
|
local f = io.popen("firstboot -y && reboot")
|
|
|
|
f:read("*a")
|
|
|
|
f:close()
|
|
|
|
os.exit(1)
|
|
|
|
end
|
|
|
|
|
2024-04-01 23:15:45 -06:00
|
|
|
local node = aredn.info.get_nvram("node")
|
2022-03-13 21:19:04 -06:00
|
|
|
local mac2 = mac_to_ip(aredn.hardware.get_interface_mac(aredn.hardware.get_iface_name("wifi")), 0)
|
|
|
|
local dtdmac = mac_to_ip(aredn.hardware.get_interface_mac(aredn.hardware.get_iface_name("lan")), 0)
|
|
|
|
|
|
|
|
local cfg = {}
|
|
|
|
local defaultcfg = {}
|
|
|
|
|
|
|
|
local tmp = io.open("/tmp/.mesh_setup", "w")
|
|
|
|
if not tmp then
|
|
|
|
print "Failed to create temp file"
|
|
|
|
os.exit(-1)
|
|
|
|
end
|
|
|
|
|
|
|
|
for line in io.lines("/etc/config.mesh/_setup")
|
|
|
|
do
|
|
|
|
if not (line:match("^%s*#") or line:match("^%s*$")) then
|
|
|
|
local k, v = line:match("^(%S+)%s*=%s*(.*)%s*$")
|
|
|
|
cfg[k] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for line in io.lines("/etc/config.mesh/_setup.default")
|
|
|
|
do
|
|
|
|
if not (line:match("^%s*#") or line:match("^%s*$")) then
|
|
|
|
line = line:gsub("<NODE>", node):gsub("<MAC2>", mac2):gsub("<DTDMAC>", dtdmac)
|
|
|
|
local k, v = line:match("^(%S+)%s*=%s*(.*)%s*$")
|
|
|
|
defaultcfg[k] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- set variables in special conditions
|
|
|
|
if cfg.dmz_mode == "0" or cfg.wan_proto == "disabled" then
|
2022-08-11 01:19:33 -06:00
|
|
|
local c = uci.cursor("/etc/config.mesh")
|
|
|
|
c:set("aredn", "@wan[0]", "olsrd_gw", "0")
|
|
|
|
c:commit("aredn")
|
2022-03-13 21:19:04 -06:00
|
|
|
end
|
|
|
|
-- end special condition overrides
|
|
|
|
|
|
|
|
local keys = {}
|
|
|
|
for k, v in pairs(defaultcfg)
|
|
|
|
do
|
|
|
|
keys[#keys + 1] = k
|
|
|
|
end
|
|
|
|
table.sort(keys)
|
|
|
|
for _, key in ipairs(keys)
|
|
|
|
do
|
|
|
|
local v = cfg[key]
|
|
|
|
if v then
|
|
|
|
tmp:write(key .. " = " .. v .. "\n")
|
|
|
|
else
|
|
|
|
tmp:write(key .. " = " .. defaultcfg[key] .. "\n")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- specific settings for variables that are not in the default config but are added by the system
|
2022-04-19 15:14:49 -06:00
|
|
|
for _, key in ipairs({ 'dmz_dhcp_end', 'dmz_dhcp_limit', 'dmz_dhcp_start', 'dmz_lan_ip', 'dmz_lan_mask', 'wifi_rxant', 'wifi_txant', 'wan_gw', 'wan_ip', 'wan_mask', 'wan_intf' })
|
2022-03-13 21:19:04 -06:00
|
|
|
do
|
|
|
|
local v = cfg[key]
|
|
|
|
if v then
|
|
|
|
tmp:write(key .. " = " .. v .. "\n")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
tmp:close()
|
|
|
|
|
|
|
|
filecopy("/tmp/.mesh_setup", "/etc/config.mesh/_setup")
|
|
|
|
os.remove("/tmp/.mesh_setup")
|
|
|
|
|
2023-12-12 21:01:23 -07:00
|
|
|
os.execute("/usr/local/bin/node-setup")
|
2022-03-13 21:19:04 -06:00
|
|
|
|
2024-04-01 23:15:45 -06:00
|
|
|
aredn.info.set_nvram("nodeupgraded", "0")
|
2022-03-13 21:19:04 -06:00
|
|
|
print "Rebooting node"
|
2022-12-22 13:22:49 -07:00
|
|
|
os.execute("reboot >/dev/null 2>&1")
|