module (..., package.seeall) -- Load libraries require("fs") require("processinfo") local packagename = "subversion" local svnurl = "svn://svn.alpinelinux.org/acf/" -- ################################################################################ -- LOCAL FUNCTIONS -- Make sure to escape special characters before calling this function local function querycmd ( cmdline ) local cmd = io.popen( cmdline ) local cmd_result = cmd:read("*a") or "unknown" cmd:close() return cmd_result end local function svndir(archive) local retval = "/usr/share/acf/" if archive == "skins/" then retval = retval.."www/skins/" elseif archive and archive ~= "core/" then retval = retval.."app/"..archive end return retval end local function determinerepository(repository) if not repository then -- try to determine the archive from svn local cmdresult = querycmd("/usr/bin/svn info "..svndir()) if string.find(cmdresult, "Repository Root:") then repository = string.match(cmdresult, "Repository Root:%s+(%S+)") -- or if not defined, use the default else repository = svnurl end end return repository end -- ################################################################################ -- PUBLIC FUNCTIONS function read(repository) repository = determinerepository(repository) local status = {} local value, errtxt = processinfo.package_version(packagename) status.version = cfe({ label="Program version", value=value, errtxt=errtxt, }) status.repository = cfe({ value=repository, label="SVN Repository" }) if "" == querycmd("/usr/bin/svn list "..format.escapespecialcharacters(repository)) then status.repository.errtxt = "Repository cannot be reached" end return cfe({ type="group", value=status, descr="ACF Update Info" }) end function update(repository, sessiondata) repository = determinerepository(repository) local cmdresult = {} local mustrestart function work(list) local dir = svndir(list) -- If we have the directory already, but not from archive, delete it if posix.stat(dir) and not posix.stat(dir..".svn") then fs.remove_directory(dir) if list == "core/" then -- We have to restart the web server because we've just deleted the mustrestart = true end end local updateresult = querycmd("/usr/bin/svn co "..format.escapespecialcharacters(repository).."/"..list.."trunk "..dir.." 2>&1") -- Hide projects without updates if (string.match(updateresult, "^Checked out revision.*")) then updateresult = "" end table.insert(cmdresult, {name=list, updates=updateresult}) end if "" ~= querycmd("/usr/bin/svn list "..format.escapespecialcharacters(repository)) then work("core/") for list in string.gmatch((querycmd("/usr/bin/svn list " .. format.escapespecialcharacters(repository) )), "%S+") do if list~="core/" and list~="sandbox/" then work(list) end end end -- Destroy the menu and permissions session data so it's recalculated if sessiondata then sessiondata.menu = nil end if sessiondata then sessiondata.permissions = nil end if mustrestart then -- FIXME --processinfo.daemoncontrol("mini_httpd", "restart") end return cfe({ type="structure", value=cmdresult, label="SVN update Result"}) end function diffs(repository) repository = determinerepository(repository) local cmdresult = {} for list in string.gmatch((querycmd("/usr/bin/svn list " .. format.escapespecialcharacters(repository) )), "%S+") do if (list ~= "sandbox/") then local updateresult = querycmd("/usr/bin/svn diff "..svndir(list).." 2>&1") if updateresult ~= "" then table.insert(cmdresult, {name=list, updates=updateresult}) end end end return cfe({ type="structure", value=cmdresult, label="SVN diff Result" }) end function status(repository) repository = determinerepository(repository) local cmdresult = {} for list in string.gmatch((querycmd("/usr/bin/svn list " .. format.escapespecialcharacters(repository) )), "%S+") do if (list ~= "sandbox/") then local updateresult = querycmd("/usr/bin/svn st -u "..svndir(list).." 2>&1") -- Hide projects without diffs if (string.match(updateresult, "^Status against revision.*")) then updateresult = "" end table.insert(cmdresult, {name=list, updates=updateresult}) end end return cfe({ type="structure", value=cmdresult, label="SVN status Result" }) end function log (repository) repository = determinerepository(repository) local enddate = tostring(os.date("%Y-%m-%d", (os.time() - (3600 * 24) * 7))) local svnresult = querycmd("/usr/bin/svn log -v -rHEAD:{".. enddate .. "} " .. format.escapespecialcharacters(repository) ) return cfe({ type="longtext", value=svnresult, label="SVN log Result" }) end