mirror of https://github.com/aredn/aredn.git
Remember and reinstall packages are firmware upgrade (#930)
This commit is contained in:
parent
648d738c78
commit
1708c4926c
|
@ -35,3 +35,4 @@
|
|||
/etc/local/uci/hsmmmesh
|
||||
/etc/passwd
|
||||
/etc/shadow
|
||||
/etc/package_store
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/lua
|
||||
--[[
|
||||
|
||||
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
||||
Copyright (C) 2023 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:
|
||||
|
||||
Additional use restrictions exist on the AREDN(TM) trademark and logo.
|
||||
See AREDNLicense.txt for more info.
|
||||
|
||||
Attributions to the AREDN Project must be retained in the source code.
|
||||
If importing this code into a new or existing project attribution
|
||||
to the AREDN project must be added to the source code.
|
||||
|
||||
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("nixio")
|
||||
require("luci.jsonc")
|
||||
|
||||
local package_store = "/etc/package_store"
|
||||
local package_catalog = package_store .. "/catalog.json"
|
||||
|
||||
if nixio.fs.stat(package_catalog) then
|
||||
os.execute("opkg update")
|
||||
local catalog = luci.jsonc.parse(io.open(package_catalog):read("*a"))
|
||||
for ipkg, state in pairs(catalog.installed)
|
||||
do
|
||||
if state == "local" then
|
||||
local file = package_store .. "/" .. ipkg .. ".ipk"
|
||||
if nixio.fs.stat(file) then
|
||||
os.execute("opkg install " .. file)
|
||||
end
|
||||
elseif state == "global" then
|
||||
os.execute("opkg install " .. ipkg)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
os.remove("/etc/cron.boot/reinstall-packages")
|
|
@ -49,6 +49,7 @@ function periodic()
|
|||
wait_for_ticks(120) -- Initial wait before starting up period tasks
|
||||
local hours = 0
|
||||
local days = 0
|
||||
run_scripts("/etc/cron.boot")
|
||||
while true
|
||||
do
|
||||
run_scripts("/etc/cron.hourly")
|
||||
|
|
|
@ -591,6 +591,31 @@ function update_advertised_services()
|
|||
end
|
||||
end
|
||||
|
||||
local package_store = "/etc/package_store"
|
||||
local package_catalog = package_store .. "/catalog.json"
|
||||
|
||||
function record_package(op, ipkg, file)
|
||||
nixio.fs.mkdir(package_store)
|
||||
local catalog = luci.jsonc.parse(read_all(package_catalog) or '{"installed":{}}')
|
||||
if op == "upload" then
|
||||
local package = ipkg:match("^([^_]+)")
|
||||
if package then
|
||||
os.execute("/bin/cp -f " .. file .. " " .. package_store .. "/" .. package .. ".ipk")
|
||||
catalog.installed[package] = "local"
|
||||
end
|
||||
elseif op == "download" then
|
||||
local result = capture("opkg status " .. ipkg .. " 2>&1")
|
||||
local package = result:match("Package: (%S+)")
|
||||
if package then
|
||||
catalog.installed[package] = "global"
|
||||
end
|
||||
elseif op == "remove" then
|
||||
nixio.fs.remove(package_store .. "/" .. ipkg .. ".ipk")
|
||||
catalog.installed[ipkg] = nil
|
||||
end
|
||||
write_all(package_catalog, luci.jsonc.stringify(catalog))
|
||||
end
|
||||
|
||||
-- upload package
|
||||
if parms.button_ul_pkg and nixio.fs.stat("/tmp/web/upload/file") then
|
||||
os.execute("mv -f /tmp/web/upload/file /tmp/web/upload/newpkg.ipk")
|
||||
|
@ -603,6 +628,7 @@ if parms.button_ul_pkg and nixio.fs.stat("/tmp/web/upload/file") then
|
|||
result = capture("opkg -force-overwrite install /tmp/web/upload/newpkg.ipk 2>&1")
|
||||
end
|
||||
pkgout(result)
|
||||
record_package("upload", firmfile, "/tmp/web/upload/newpkg.ipk")
|
||||
os.execute("rm -rf /tmp/opkg-*")
|
||||
nixio.fs.remove("/tmp/web/upload/newpkg.ipk")
|
||||
if os.execute("/usr/local/bin/uploadctlservices restore > /dev/null 2>&1") ~= 0 then
|
||||
|
@ -624,6 +650,7 @@ if parms.button_dl_pkg and parms.dl_pkg ~= "default" then
|
|||
result = capture("opkg -force-overwrite install " .. parms.dl_pkg .. " 2>&1")
|
||||
end
|
||||
pkgout(result)
|
||||
record_package("download", parms.dl_pkg)
|
||||
if os.execute("/usr/local/bin/uploadctlservices restore > /dev/null 2>&1") ~= 0 then
|
||||
pkgout("Failed to restart all services, please reboot this node.")
|
||||
else
|
||||
|
@ -651,6 +678,7 @@ if parms.button_rm_pkg and parms.rm_pkg ~= "default" and not permpkg[parms.rm_pk
|
|||
if not output:match("No packages removed") then
|
||||
pkgout("Package removed successfully")
|
||||
update_advertised_services()
|
||||
record_package("remove", parms.rm_pkg)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue