From 92726e3aa25313114db76968d37fa2099d840260 Mon Sep 17 00:00:00 2001 From: Kiritow <1362050620@qq.com> Date: Tue, 19 Jun 2018 19:58:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'tpm.lua'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tpm.lua | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/tpm.lua b/tpm.lua index a375d68..072f41a 100644 --- a/tpm.lua +++ b/tpm.lua @@ -309,10 +309,128 @@ local function tpm_install_github(url) return tpm_install_github_real(repo_fullname,branch) end + + +local function tpm_install_kgit_real(repo,branch) + local config_url=resolve_cngit(repo,"mainfest.txt",branch) + local ret,data,code=doRealDownload(config_url) + if(not ret) then + return false,"Failed to download mainfest from repo " .. repo .. ". Error: " .. data + end + if(code~=200) then + return false,"Got response code " .. code .. " while downloading mainfest from repo " .. repo + end + local flg,tb=tpm_mainfest_loader(data) + if(not flg) then + return false,"Invalid mainfest in repo " .. repo .. " Error: " .. tb + end + + -- Debug + tpm_mainfest_show(tb) + + -- Check + if(tpm_is_installed(tb.libname)) then + print("Package " .. tb.libname .. " is already installed.") + return true + end + + -- Depends + if(tb.depends~=nil) then + print("Analyzing dependency...") + local dependsz=#tb.depends + local cnt_now=1 + for k,v in pairs(tb.depends) do + print("[" .. cnt_now .. "/" .. dependsz .. "] Checking " .. v .. "...") + local ret,msg=tpm_install(v) + if(not ret) then + return false,"An error occurs while analyzing dependency: " .. v .. ". Error: " .. msg + end + cnt_now=cnt_now+1 + end + end + + -- Make directories + if(tb.dirs~=nil) then + for k,v in pairs(tb.dirs) do + print("Making directory " .. v) + filesystem.makeDirectory(v) + end + end + + -- Download + for k,v in pairs(tb.files) do + io.write("Downloading file " .. k .. "...") + local xret,xdata,xcode=doRealDownload(resolve_cngit(repo,k,branch)) + if(not xret) then + print("[Failed]") + return false,"Failed to download " .. k + elseif(xcode~=200) then + print("[Failed]") + return false,"Response code is " .. xcode .. " while downloading " .. k + else + local xret,xmsg=WriteStringToFile(xdata,v) + if(not xret) then + print("[Write Failed]") + return false,"Failed to write to file " .. v .. " while downloading " .. k + end + + -- OK here + print("[OK]") + end + end + + -- Run Setup + if(tb.setup~=nil) then + print("Running setup...") + local setup_file=tb.files[tb.setup] + local setup_fn,err=loadfile(setup_file) + if(setup_fn==nil) then + print("Failed to start setup program. Error: " .. err) + end + local ret,msg=pcall(setup_fn) + if(not ret) then + printf("Failed to run setup program. Error: " .. msg) + end + end + + -- Update software list + print("Updating software info...") + local flg,installed_lst=tpm_get_installed_list() + table.insert(installed_lst,tb) + tpm_set_installed_list(installed_lst) + print("Software info updated.") + return true +end +local function tpm_install_kgit(url) + local a=string.find(url,"/") + if(a==nil) then + return false,"Unknown format of kgit url" + end + + local author=string.sub(url,1,a-1) + local reponame='' + local b=string.find(url,"/",a+1) + + -- Branch set to master by default + local branch="master" + if(b~=nil) then + reponame=string.sub(url,a+1,b-1) + branch=string.sub(url,b+1) + else + reponame=string.sub(url,a+1) + end + + local repo_fullname=author .. "/" .. reponame + print("Checking kgit repo " .. repo_fullname .. " at branch " .. branch .." ...") + + return tpm_install_kgit_real(repo_fullname,branch) +end local function tpm_install(install_url) print("tpm_install: ",install_url) if(beginWith(install_url,"github+")) then return tpm_install_github(string.sub(install_url,string.len("github+")+1)) + elseif(beginWith(install_url,"kgit+")) then + return tpm_install_kgit(string.sub(install_url,string.len("kgit+")+1)) elseif(beginWith(install_url,"http+")) then return tpm_install_http(string.sub(install_url,string.len("http+")+1)) else