mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 19:13:49 +01:00
Fix bug in findVersion().
Tidy up a bit.
This commit is contained in:
parent
efe4ab766a
commit
64abe081e9
@ -504,7 +504,7 @@ function M.findVersion(version, verTable, timestamp)
|
|||||||
if not verTable then return nil,msg end
|
if not verTable then return nil,msg end
|
||||||
|
|
||||||
for _,ent in pairs(verTable) do
|
for _,ent in pairs(verTable) do
|
||||||
if M.versionsEqual(ent.version, version, ent.timestamp, timestamp) == 0 then return ent end
|
if M.versionsEqual(ent.version, version, ent.timestamp, timestamp) == true then return ent end
|
||||||
end
|
end
|
||||||
return nil,"no such version"
|
return nil,"no such version"
|
||||||
end
|
end
|
||||||
|
@ -6,30 +6,49 @@ local function ERR(msg) print(msg) end
|
|||||||
local ok, pl = pcall(require, 'pl.import_into')
|
local ok, pl = pcall(require, 'pl.import_into')
|
||||||
if not ok then
|
if not ok then
|
||||||
ERR('This script requires the Penlight library')
|
ERR('This script requires the Penlight library')
|
||||||
os.exit(1)
|
os.exit(2)
|
||||||
end
|
end
|
||||||
pl = pl()
|
pl = pl()
|
||||||
|
|
||||||
local lfs = require('lfs') -- assume this exists since it's required by penlight as well
|
local lfs = require('lfs') -- assume this exists since it's required by penlight as well
|
||||||
|
|
||||||
local serpent = require('util.serpent')
|
|
||||||
|
|
||||||
local argStash = arg
|
local argStash = arg
|
||||||
arg = nil
|
arg = nil
|
||||||
local upmgr = require('d3d-update-mgr') -- arg must be nil for the update manager to load as module
|
local upmgr = require('d3d-update-mgr') -- arg must be nil for the update manager to load as module
|
||||||
arg = argStash
|
arg = argStash
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-----------------------------
|
||||||
|
-- CONSTANTS AND VARIABLES --
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
local D3D_REPO_FIRMWARE_NAME = 'doodle3d-firmware'
|
local D3D_REPO_FIRMWARE_NAME = 'doodle3d-firmware'
|
||||||
local D3D_REPO_CLIENT_NAME = 'doodle3d-client'
|
local D3D_REPO_CLIENT_NAME = 'doodle3d-client'
|
||||||
local D3D_REPO_PRINT3D_NAME = 'print3d'
|
local D3D_REPO_PRINT3D_NAME = 'print3d'
|
||||||
local IMAGE_BASENAME = 'doodle3d-wifibox'
|
local IMAGE_BASENAME = 'doodle3d-wifibox'
|
||||||
|
|
||||||
local deviceType = 'tl-mr3020' -- or 'tl-wr703'
|
local deviceType = 'tl-mr3020' -- or 'tl-wr703'
|
||||||
|
local lock = nil
|
||||||
local paths = {}
|
local paths = {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-----------------------
|
||||||
|
-- UTILITY FUNCTIONS --
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
local function quit(ev)
|
||||||
|
if lock then lock:free() end
|
||||||
|
os.exit(ev or 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function md5sum(file)
|
||||||
|
local rv,_,sum = pl.utils.executeex('md5 -q "' .. file .. '"')
|
||||||
|
|
||||||
|
return rv and sum:sub(1, -2) or nil
|
||||||
|
end
|
||||||
|
|
||||||
local function detectOpenWrtRoot()
|
local function detectOpenWrtRoot()
|
||||||
local f = io.open('Makefile', 'r')
|
local f = io.open('Makefile', 'r')
|
||||||
local line = f and f:read('*line')
|
local line = f and f:read('*line')
|
||||||
@ -84,13 +103,8 @@ local function constructImageName(version, devType, sysupOrFactory)
|
|||||||
return IMAGE_BASENAME .. '-' .. upmgr.formatVersion(version) .. '-' .. devType .. '-' .. sysupOrFactory .. '.bin'
|
return IMAGE_BASENAME .. '-' .. upmgr.formatVersion(version) .. '-' .. devType .. '-' .. sysupOrFactory .. '.bin'
|
||||||
end
|
end
|
||||||
|
|
||||||
local function md5sum(file)
|
|
||||||
local rv,_,sum = pl.utils.executeex('md5 -q "' .. file .. '"')
|
|
||||||
|
|
||||||
return rv and sum:sub(1, -2) or nil
|
local function collectLocalInfo()
|
||||||
end
|
|
||||||
|
|
||||||
local function collectVersionInfo()
|
|
||||||
local info = {}
|
local info = {}
|
||||||
|
|
||||||
-- temporary fields required for copying image files
|
-- temporary fields required for copying image files
|
||||||
@ -118,13 +132,13 @@ local function collectVersionInfo()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function main()
|
|
||||||
print("Doodle3D release script")
|
|
||||||
-- local opts = parseOptions(arg)
|
|
||||||
--
|
|
||||||
-- if opts['wrt-root'] then changedir(opts['wrt-root']) end
|
|
||||||
-- if opts['cache-dir'] then paths.cache = opts['cache-dir'] end
|
|
||||||
|
|
||||||
|
--------------------
|
||||||
|
-- MAIN FUNCTIONS --
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
local function prepare()
|
||||||
|
local msg = nil
|
||||||
|
|
||||||
io.stdout:write("Checking if working directory is the OpenWrt root... ")
|
io.stdout:write("Checking if working directory is the OpenWrt root... ")
|
||||||
local isOpenWrtRoot = detectOpenWrtRoot()
|
local isOpenWrtRoot = detectOpenWrtRoot()
|
||||||
@ -133,7 +147,7 @@ local function main()
|
|||||||
print("found (" .. paths.wrt .. ")")
|
print("found (" .. paths.wrt .. ")")
|
||||||
else
|
else
|
||||||
print("unrecognized directory, try changing directories or using -wrt-root")
|
print("unrecognized directory, try changing directories or using -wrt-root")
|
||||||
os.exit(1)
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
io.stdout:write("Looking for Doodle3D feed path... ")
|
io.stdout:write("Looking for Doodle3D feed path... ")
|
||||||
@ -142,7 +156,7 @@ local function main()
|
|||||||
print("found " .. d3dFeed)
|
print("found " .. d3dFeed)
|
||||||
else
|
else
|
||||||
if msg then print("not found: " .. msg) else print("not found.") end
|
if msg then print("not found: " .. msg) else print("not found.") end
|
||||||
os.exit(1)
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
paths.firmware = d3dFeed .. '/' .. D3D_REPO_FIRMWARE_NAME
|
paths.firmware = d3dFeed .. '/' .. D3D_REPO_FIRMWARE_NAME
|
||||||
@ -157,42 +171,87 @@ local function main()
|
|||||||
local rv,msg = pl.dir.makepath(paths.cache)
|
local rv,msg = pl.dir.makepath(paths.cache)
|
||||||
if not rv then
|
if not rv then
|
||||||
print("could not create path (" .. msg .. ").")
|
print("could not create path (" .. msg .. ").")
|
||||||
os.exit(1)
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local lock,msg = lfs.lock_dir(paths.cache)
|
lock,msg = lfs.lock_dir(paths.cache)
|
||||||
if not lock then
|
if not lock then
|
||||||
print("could not obtain directory lock (" .. msg .. ").")
|
print("could not obtain directory lock (" .. msg .. ").")
|
||||||
os.exit(1)
|
return nil
|
||||||
else
|
else
|
||||||
print("ok")
|
print("ok")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
local newVersion = collectVersionInfo()
|
local function fetchVersionInfo()
|
||||||
print(serpent.block(newVersion))
|
local msg,stables,betas = nil,nil,nil
|
||||||
|
|
||||||
|
stables,msg = upmgr.getAvailableVersions('stables')
|
||||||
|
if not stables then return nil,msg end
|
||||||
|
|
||||||
|
betas,msg = upmgr.getAvailableVersions('betas')
|
||||||
|
if not betas then return nil,msg end
|
||||||
|
|
||||||
|
return stables, betas
|
||||||
|
end
|
||||||
|
|
||||||
|
local function generateIndex(newVersion, versionTable, isStable)
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
local function copyImages(newVersion)
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
local function main()
|
||||||
|
print("Doodle3D release script")
|
||||||
|
-- local opts = parseOptions(arg)
|
||||||
|
--
|
||||||
|
-- if opts['wrt-root'] then changedir(opts['wrt-root']) end
|
||||||
|
-- if opts['cache-dir'] then paths.cache = opts['cache-dir'] end
|
||||||
|
|
||||||
|
if not prepare() then quit(1) end
|
||||||
|
|
||||||
|
-- initialize update manager script
|
||||||
upmgr.setUseCache(false)
|
upmgr.setUseCache(false)
|
||||||
upmgr.setVerbosity(1)
|
upmgr.setVerbosity(1)
|
||||||
upmgr.setCachePath(paths.cache)
|
upmgr.setCachePath(paths.cache)
|
||||||
|
|
||||||
local stables,msg1 = upmgr.getAvailableVersions('stables')
|
local newVersion = collectLocalInfo()
|
||||||
local betas,msg2 = upmgr.getAvailableVersions('betas')
|
|
||||||
|
|
||||||
if stables then
|
local stables,betas = fetchVersionInfo()
|
||||||
-- print("stables: " .. serpent.block(stables))
|
if not stables then
|
||||||
else
|
print("Error: could not get version information (" .. betas .. ")")
|
||||||
print("error getting stables (" .. msg1 .. ")")
|
quit(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- print("===========================");
|
local isStable = (newVersion.version.suffix == nil)
|
||||||
if betas then
|
print("Rolling release for firmware version " .. upmgr.formatVersion(newVersion.version) .. " (type: " .. (isStable and "stable" or "beta") .. ").")
|
||||||
-- print("betas: " .. serpent.block(betas))
|
|
||||||
else
|
if upmgr.findVersion(newVersion.version, stables) or upmgr.findVersion(newVersion.version, betas) then
|
||||||
print("error getting betas (" .. msg2 .. ")")
|
print("Error: firmware version " .. upmgr.formatVersion(newVersion.version) .. " already exists")
|
||||||
|
quit(3)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not generateIndex(newVersion, isStable and stables or betas, isStable) then
|
||||||
|
print("Error: could not generate index")
|
||||||
|
quit(4)
|
||||||
|
end
|
||||||
|
|
||||||
|
if not copyImages(newVersion) then
|
||||||
|
print("Error: could not copy images")
|
||||||
|
quit(4)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
print(pl.pretty.dump(newVersion))
|
||||||
|
print("stables: " .. pl.pretty.dump(stables))
|
||||||
|
print("===========================");
|
||||||
|
print("betas: " .. pl.pretty.dump(betas))
|
||||||
|
|
||||||
|
|
||||||
--if requested, fetch images and packages (i.e., mirror whole directory)
|
--if requested, fetch images and packages (i.e., mirror whole directory)
|
||||||
|
|
||||||
--run sanity checks
|
--run sanity checks
|
||||||
@ -200,8 +259,7 @@ local function main()
|
|||||||
--check whether newVersion is not conflicting with or older than anything in corresponding table
|
--check whether newVersion is not conflicting with or older than anything in corresponding table
|
||||||
--add newVersion to correct table and generate updated index file
|
--add newVersion to correct table and generate updated index file
|
||||||
|
|
||||||
lock:free()
|
quit()
|
||||||
os.exit(0)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user