From efe4ab766a4c092d3b035e77427be7e6d67c6d23 Mon Sep 17 00:00:00 2001 From: Wouter R Date: Wed, 19 Feb 2014 12:35:34 +0100 Subject: [PATCH] Finish index file fetching and parsing. Add function to collect information on current version. --- updater-ng/d3d-update-mgr.lua | 37 ++++++++++++++++- updater-ng/release-ng.lua | 75 +++++++++++++++++++++++++++++++++-- 2 files changed, 106 insertions(+), 6 deletions(-) diff --git a/updater-ng/d3d-update-mgr.lua b/updater-ng/d3d-update-mgr.lua index f7f9ec3..8f14014 100644 --- a/updater-ng/d3d-update-mgr.lua +++ b/updater-ng/d3d-update-mgr.lua @@ -264,7 +264,7 @@ end -- @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. local function runCommand(command, dryRun) - D("about to run: '" .. command .. "'") + --D("about to run: '" .. command .. "'") if dryRun then return -1 end return compatexecute(command) end @@ -284,6 +284,7 @@ end local function downloadFile(url, saveDir, filename) 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 '' + D("Downloading file '" .. url .. "'") if filename:len() > 0 then return runCommand('wget ' .. M.WGET_OPTIONS .. ' -O ' .. saveDir .. '/' .. filename .. ' ' .. url .. ' 2> /dev/null') else @@ -590,7 +591,7 @@ local function fetchIndexTable(indexFile, cachePath) for line in idxLines do local k,v = line:match('^(.-):(.*)$') k,v = trim(k), trim(v) - if not log then D("#" .. lineno .. ": considering '" .. line .. "' (" .. (k or '') .. " / " .. (v or '') .. ")") end + --if not log then D("#" .. lineno .. ": considering '" .. line .. "' (" .. (k or '') .. " / " .. (v or '') .. ")") 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 @@ -622,6 +623,13 @@ local function fetchIndexTable(indexFile, cachePath) sSum,fSum = trim(sSum), trim(fSum) if sSum then entry.sysupgradeMD5 = sSum 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 P(-1, "ignoring unrecognized field in index file '" .. k .. "' (line " .. lineno .. ")") end @@ -638,6 +646,31 @@ local function fetchIndexTable(indexFile, cachePath) return result 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. -- @tparam table versionEntry A version information table. -- @string[opt] devType Image device type, see @{constructImageFilename}. diff --git a/updater-ng/release-ng.lua b/updater-ng/release-ng.lua index 5e17886..9e4787a 100755 --- a/updater-ng/release-ng.lua +++ b/updater-ng/release-ng.lua @@ -12,6 +12,8 @@ pl = pl() local lfs = require('lfs') -- assume this exists since it's required by penlight as well +local serpent = require('util.serpent') + local argStash = arg arg = nil 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_CLIENT_NAME = 'doodle3d-client' local D3D_REPO_PRINT3D_NAME = 'print3d' +local IMAGE_BASENAME = 'doodle3d-wifibox' +local deviceType = 'tl-mr3020' -- or 'tl-wr703' local paths = {} + local function detectOpenWrtRoot() local f = io.open('Makefile', 'r') local line = f and f:read('*line') @@ -75,6 +80,43 @@ 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() print("Doodle3D release script") @@ -87,7 +129,8 @@ local function main() io.stdout:write("Checking if working directory is the OpenWrt root... ") local isOpenWrtRoot = detectOpenWrtRoot() if isOpenWrtRoot then - print("ok") + paths.wrt = pl.path.currentdir() + print("found (" .. paths.wrt .. ")") else print("unrecognized directory, try changing directories or using -wrt-root") os.exit(1) @@ -122,16 +165,40 @@ local function main() print("could not obtain directory lock (" .. msg .. ").") os.exit(1) else - print("OK.") + print("ok") end - -- ... -- + local newVersion = collectVersionInfo() + print(serpent.block(newVersion)) + + upmgr.setUseCache(false) upmgr.setVerbosity(1) 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() os.exit(0)