2014-02-04 13:41:13 +01:00
|
|
|
#!/usr/bin/env lua
|
2014-02-04 19:38:41 +01:00
|
|
|
--#!/usr/bin/env lua -l strict
|
2014-02-04 13:41:13 +01:00
|
|
|
|
|
|
|
local function ERR(msg) print(msg) end
|
|
|
|
|
2014-02-04 19:38:41 +01:00
|
|
|
local ok, pl = pcall(require, 'pl.import_into')
|
2014-02-04 13:41:13 +01:00
|
|
|
if not ok then
|
2014-02-04 19:38:41 +01:00
|
|
|
ERR('This script requires the Penlight library')
|
2014-02-04 13:41:13 +01:00
|
|
|
os.exit(1)
|
|
|
|
end
|
2014-02-04 19:38:41 +01:00
|
|
|
pl = pl()
|
|
|
|
|
|
|
|
local lfs = require('lfs') -- assume this exists since it's required by penlight as well
|
2014-02-04 13:41:13 +01:00
|
|
|
|
2014-02-19 11:50:25 +01:00
|
|
|
local argStash = arg
|
|
|
|
arg = nil
|
|
|
|
local upmgr = require('d3d-update-mgr') -- arg must be nil for the update manager to load as module
|
|
|
|
arg = argStash
|
|
|
|
|
|
|
|
|
2014-02-04 13:41:13 +01:00
|
|
|
local D3D_REPO_FIRMWARE_NAME = 'doodle3d-firmware'
|
|
|
|
local D3D_REPO_CLIENT_NAME = 'doodle3d-client'
|
|
|
|
local D3D_REPO_PRINT3D_NAME = 'print3d'
|
|
|
|
|
|
|
|
local paths = {}
|
|
|
|
|
|
|
|
|
|
|
|
local function detectOpenWrtRoot()
|
|
|
|
local f = io.open('Makefile', 'r')
|
|
|
|
local line = f and f:read('*line')
|
|
|
|
local rv = (line and line:find('# Makefile for OpenWrt') == 1) and true or false
|
|
|
|
|
|
|
|
if f then f:close() end
|
|
|
|
return rv
|
|
|
|
end
|
|
|
|
|
|
|
|
-- returns uri (file path) of the wifibox feed, nil if not found or nil+msg on error
|
|
|
|
-- recognized feed names are 'wifibox' and 'doodle3d' (case-insensitive)
|
|
|
|
local function getWifiboxFeedRoot(feedsFile)
|
|
|
|
local typ, nam, uri = nil, nil, nil
|
|
|
|
local lineNo = 1
|
|
|
|
local f = io.open(feedsFile, 'r')
|
|
|
|
|
|
|
|
if not f then return nil, "could not open '" .. feedsFile .. '"' end
|
|
|
|
|
|
|
|
for line in f:lines() do
|
|
|
|
typ, nam, uri = line:match('^([^%s]+)%s+([^%s]+)%s+([^%s]+)$')
|
|
|
|
|
|
|
|
if not (typ and nam and uri) then
|
|
|
|
f:close()
|
|
|
|
return uri or nil, "could not parse line " .. feedsFile .. "#" .. lineNo
|
|
|
|
end
|
|
|
|
|
|
|
|
local commented = (typ:find('#') == 1)
|
|
|
|
if not commented and (nam:lower() == 'wifibox' or nam:lower() == 'doodle3d') then
|
|
|
|
break
|
|
|
|
else
|
|
|
|
typ, nam, uri = nil, nil, nil
|
|
|
|
end
|
|
|
|
|
|
|
|
lineNo = lineNo + 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if uri and not (typ == 'src-link' or typ == 'src-cpy') then return nil, "d3d feed has wrong type '" .. typ .. "', use 'src-link' or 'src-cpy'" end
|
|
|
|
|
|
|
|
f:close()
|
|
|
|
return uri
|
|
|
|
end
|
|
|
|
|
|
|
|
-- TODO: pass table to functions to fill in? if they all return either true or nil+msg, that could be used for display of ok/msg
|
|
|
|
-- returns true on success, false on error, and displays meaningful messages
|
|
|
|
--local function runCheck(msg, processFunc)
|
|
|
|
-- io.stdout:write(msg .. "... ")
|
|
|
|
-- return processFunc(--[[ hmm ]]--)
|
|
|
|
--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
|
|
|
|
|
|
|
|
|
|
|
|
io.stdout:write("Checking if working directory is the OpenWrt root... ")
|
|
|
|
local isOpenWrtRoot = detectOpenWrtRoot()
|
|
|
|
if isOpenWrtRoot then
|
|
|
|
print("ok")
|
|
|
|
else
|
|
|
|
print("unrecognized directory, try changing directories or using -wrt-root")
|
|
|
|
os.exit(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
io.stdout:write("Looking for Doodle3D feed path... ")
|
|
|
|
local d3dFeed,msg = getWifiboxFeedRoot('feeds.conf')
|
|
|
|
if d3dFeed then
|
|
|
|
print("found " .. d3dFeed)
|
|
|
|
else
|
2014-02-04 19:38:41 +01:00
|
|
|
if msg then print("not found: " .. msg) else print("not found.") end
|
2014-02-04 13:41:13 +01:00
|
|
|
os.exit(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
paths.firmware = d3dFeed .. '/' .. D3D_REPO_FIRMWARE_NAME
|
|
|
|
paths.client = d3dFeed .. '/' .. D3D_REPO_CLIENT_NAME
|
|
|
|
paths.print3d = d3dFeed .. '/' .. D3D_REPO_PRINT3D_NAME
|
|
|
|
|
2014-02-04 19:38:41 +01:00
|
|
|
-- if empty, try to choose something sensible
|
2014-02-04 13:41:13 +01:00
|
|
|
if not paths.cache or paths.cache == '' then
|
2014-02-04 19:38:41 +01:00
|
|
|
paths.cache = '/tmp/d3d-release-dir/2ndpath'
|
|
|
|
end
|
|
|
|
io.stdout:write("Attempting to use " .. paths.cache .. " as cache dir... ")
|
|
|
|
local rv,msg = pl.dir.makepath(paths.cache)
|
|
|
|
if not rv then
|
|
|
|
print("could not create path (" .. msg .. ").")
|
|
|
|
os.exit(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
local lock,msg = lfs.lock_dir(paths.cache)
|
|
|
|
if not lock then
|
|
|
|
print("could not obtain directory lock (" .. msg .. ").")
|
|
|
|
os.exit(1)
|
|
|
|
else
|
|
|
|
print("OK.")
|
2014-02-04 13:41:13 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2014-02-04 19:38:41 +01:00
|
|
|
-- ... --
|
2014-02-19 11:50:25 +01:00
|
|
|
upmgr.setUseCache(false)
|
|
|
|
upmgr.setVerbosity(1)
|
|
|
|
upmgr.setCachePath(paths.cache)
|
2014-02-04 19:38:41 +01:00
|
|
|
--fetch index files and if requested also images and packages
|
|
|
|
|
2014-02-04 13:41:13 +01:00
|
|
|
|
2014-02-04 19:38:41 +01:00
|
|
|
lock:free()
|
|
|
|
os.exit(0)
|
|
|
|
end
|
2014-02-04 13:41:13 +01:00
|
|
|
|
|
|
|
|
2014-02-04 19:38:41 +01:00
|
|
|
main()
|