0
0
mirror of https://github.com/Doodle3D/doodle3d-firmware.git synced 2025-01-22 00:55:09 +01:00

Finish index file fetching and parsing.

Add function to collect information on current version.
This commit is contained in:
Wouter R 2014-02-19 12:35:34 +01:00
parent 81f450aaf6
commit efe4ab766a
2 changed files with 106 additions and 6 deletions

View File

@ -264,7 +264,7 @@ end
-- @bool dryRun Only log a message if true, otherwise run the command and log a message. -- @bool dryRun Only log a message if true, otherwise run the command and log a message.
-- @treturn number Exit status of of command or -1 if dryRun is true. -- @treturn number Exit status of of command or -1 if dryRun is true.
local function runCommand(command, dryRun) local function runCommand(command, dryRun)
D("about to run: '" .. command .. "'") --D("about to run: '" .. command .. "'")
if dryRun then return -1 end if dryRun then return -1 end
return compatexecute(command) return compatexecute(command)
end end
@ -284,6 +284,7 @@ end
local function downloadFile(url, saveDir, filename) local function downloadFile(url, saveDir, filename)
if not saveDir or saveDir:len() == 0 then return nil, "saveDir must be non-empty" end if not saveDir or saveDir:len() == 0 then return nil, "saveDir must be non-empty" end
local outArg = (filename:len() > 0) and (' -O' .. filename) or '' local outArg = (filename:len() > 0) and (' -O' .. filename) or ''
D("Downloading file '" .. url .. "'")
if filename:len() > 0 then if filename:len() > 0 then
return runCommand('wget ' .. M.WGET_OPTIONS .. ' -O ' .. saveDir .. '/' .. filename .. ' ' .. url .. ' 2> /dev/null') return runCommand('wget ' .. M.WGET_OPTIONS .. ' -O ' .. saveDir .. '/' .. filename .. ' ' .. url .. ' 2> /dev/null')
else else
@ -590,7 +591,7 @@ local function fetchIndexTable(indexFile, cachePath)
for line in idxLines do for line in idxLines do
local k,v = line:match('^(.-):(.*)$') local k,v = line:match('^(.-):(.*)$')
k,v = trim(k), trim(v) k,v = trim(k), trim(v)
if not log then D("#" .. lineno .. ": considering '" .. line .. "' (" .. (k or '<nil>') .. " / " .. (v or '<nil>') .. ")") end --if not log then D("#" .. lineno .. ": considering '" .. line .. "' (" .. (k or '<nil>') .. " / " .. (v or '<nil>') .. ")") end
if not changelogMode and (not k or not v) then return nil,"incorrectly formatted line in index file (line " .. lineno .. ")" end if not changelogMode and (not k or not v) then return nil,"incorrectly formatted line in index file (line " .. lineno .. ")" end
if k == 'ChangelogEnd' then if k == 'ChangelogEnd' then
@ -622,6 +623,13 @@ local function fetchIndexTable(indexFile, cachePath)
sSum,fSum = trim(sSum), trim(fSum) sSum,fSum = trim(sSum), trim(fSum)
if sSum then entry.sysupgradeMD5 = sSum end if sSum then entry.sysupgradeMD5 = sSum end
if fSum then entry.factoryMD5 = fSum end if fSum then entry.factoryMD5 = fSum end
elseif k == 'ReleaseDate' then
local ts = M.parseDate(v)
if not ts then
P(0, "ignoring incorrectly formatted ReleaseDate field (line " .. lineno .. ")")
else
entry.timestamp = ts
end
else else
P(-1, "ignoring unrecognized field in index file '" .. k .. "' (line " .. lineno .. ")") P(-1, "ignoring unrecognized field in index file '" .. k .. "' (line " .. lineno .. ")")
end end
@ -638,6 +646,31 @@ local function fetchIndexTable(indexFile, cachePath)
return result return result
end end
--- Returns an indexed and sorted table containing version information tables.
-- The information is obtained from the either cached or downloaded image index (@{IMAGE_STABLE_INDEX_FILE}).
-- @tparam which[opt] Which type of versions to fetch, either 'stables' (default), 'betas' or both.
-- @treturn table A table with a collection of version information tables.
function M.getAvailableVersions(which)
local ccRv,ccMsg = createCacheDirectory()
if not ccRv then return nil,ccMsg end
local verTable, msg = {}, nil
if which == 'stables' or which == 'both' then
verTable,msg = fetchIndexTable(M.IMAGE_STABLE_INDEX_FILE, cachePath)
if not verTable then return nil,msg end
end
if which == 'betas' or which == 'both' then
local betas,msg = fetchIndexTable(M.IMAGE_BETA_INDEX_FILE, cachePath)
if not betas then return nil,msg end
for k,v in pairs(betas) do verTable[k] = v end
end
return verTable
end
--- Attempts to download an image file with the requested properties. --- Attempts to download an image file with the requested properties.
-- @tparam table versionEntry A version information table. -- @tparam table versionEntry A version information table.
-- @string[opt] devType Image device type, see @{constructImageFilename}. -- @string[opt] devType Image device type, see @{constructImageFilename}.

View File

@ -12,6 +12,8 @@ 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
@ -21,10 +23,13 @@ arg = argStash
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 deviceType = 'tl-mr3020' -- or 'tl-wr703'
local paths = {} local paths = {}
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')
@ -75,6 +80,43 @@ end
--end --end
local function constructImageName(version, devType, sysupOrFactory)
return IMAGE_BASENAME .. '-' .. upmgr.formatVersion(version) .. '-' .. devType .. '-' .. sysupOrFactory .. '.bin'
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 collectVersionInfo()
local info = {}
-- temporary fields required for copying image files
info.sysupImgPath = paths.wrt .. '/bin/ar71xx/openwrt-ar71xx-generic-' .. deviceType .. '-v1-squashfs-sysupgrade.bin'
info.factImgPath = paths.wrt .. '/bin/ar71xx/openwrt-ar71xx-generic-' .. deviceType .. '-v1-squashfs-factory.bin'
info.version = upmgr.parseVersion(pl.file.read(paths.firmware .. '/src/FIRMWARE-VERSION'))
if not info.version then return nil,"could not determine current firmware version" end
info.factoryFileSize = pl.path.getsize(info.factImgPath)
if not info.factoryFileSize then return nil,"could not determine size for factory image" end
info.sysupgradeFileSize = pl.path.getsize(info.sysupImgPath)
if not info.sysupgradeFileSize then return nil,"could not determine size for sysupgrade image" end
info.factoryMD5 = md5sum(info.factImgPath)
info.sysupgradeMD5 = md5sum(info.sysupImgPath)
if not info.factoryMD5 or not info.sysupgradeMD5 then return nil,"could not determine MD5 sum for image(s)" end
info.factoryFilename = constructImageName(info.version, deviceType, 'factory')
info.sysupgradeFilename = constructImageName(info.version, deviceType, 'sysupgrade')
info.timestamp = os.time()
return info
end
local function main() local function main()
print("Doodle3D release script") print("Doodle3D release script")
@ -87,7 +129,8 @@ local function main()
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()
if isOpenWrtRoot then if isOpenWrtRoot then
print("ok") paths.wrt = pl.path.currentdir()
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) os.exit(1)
@ -122,16 +165,40 @@ local function main()
print("could not obtain directory lock (" .. msg .. ").") print("could not obtain directory lock (" .. msg .. ").")
os.exit(1) os.exit(1)
else else
print("OK.") print("ok")
end end
-- ... -- local newVersion = collectVersionInfo()
print(serpent.block(newVersion))
upmgr.setUseCache(false) upmgr.setUseCache(false)
upmgr.setVerbosity(1) upmgr.setVerbosity(1)
upmgr.setCachePath(paths.cache) upmgr.setCachePath(paths.cache)
--fetch index files and if requested also images and packages
local stables,msg1 = upmgr.getAvailableVersions('stables')
local betas,msg2 = upmgr.getAvailableVersions('betas')
if stables then
-- print("stables: " .. serpent.block(stables))
else
print("error getting stables (" .. msg1 .. ")")
end
-- print("===========================");
if betas then
-- print("betas: " .. serpent.block(betas))
else
print("error getting betas (" .. msg2 .. ")")
end
--if requested, fetch images and packages (i.e., mirror whole directory)
--run sanity checks
--check whether newVersion is not conflicting with or older than anything in corresponding table
--add newVersion to correct table and generate updated index file
lock:free() lock:free()
os.exit(0) os.exit(0)