Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local server="https://www-user.tu-chemnitz.de/"
- local spath ="~jorot/cclib/"
- local headerpath="package/apt-get/header/"
- local libpath="package/"
- local arg = {...}
- os.loadAPI("package/log/log")
- if (log == nil) then
- log = {}
- log.i = print
- log.e = print
- log.w = print
- end
- function wget(name,path)
- local url = server..spath..name
- log.i("Downloading "..url.." ...")
- if(not http.checkURL(server)) then
- log.i("404 Server not reachable:"..server)
- return -1
- end
- h = http.get(url)
- if(h==nil) then
- log.i("404 couldn't open connection")
- return -1
- end
- local s = h.readAll()
- f =fs.open(path,"w")
- f.write(s)
- f.close()
- h.close()
- log.i("saved as "..path)
- end
- local function install()
- if #arg<2 then
- log.i("Usage: apt-get install <package>")
- return
- end
- local ln = arg[2]
- if(fs.exists(headerpath..ln)) then
- runheader(headerpath..ln)
- else
- log.i("Packageheaders not found! Try apt-get update")
- end
- end
- local function update() --downloads header files
- log.i("Update headerfiles ...")
- wget("package-list",".apt-temp")
- local file = fs.open(".apt-temp","r")
- local line = file.readLine()
- while(line) do
- log.i("Downloading header for "..line)
- wget(line.."/meta.phf",headerpath..line)
- line=file.readLine()
- end
- file.close()
- fs.delete(".apt-temp")
- log.i("apt-get: compleate")
- end
- local function runheader(ln)
- local file = fs.open(ln,"r")
- local pn
- local line=file.readLine()
- while line~=nil do
- if(str_starts(line,"PACKAGE")) then
- if pn~=nil then
- log.i("ERROR multible packages")
- return -1
- end
- pn=string.sub(line,9)
- log.i("package:"..string.sub(line,9))
- fs.makeDir(libpath..pn)
- elseif(str_starts(line,"VERSION")) then log.i("version:"..string.sub(line,9,9).."."..string.sub(line,10,11).."."..string.sub(line,12))
- elseif(str_starts(line,"AUTHOR")) then log.i("author :"..string.sub(line,8))
- elseif false then
- elseif str_starts(line,"GET") then
- local p = string.find(line," AS ")
- local sp = string.sub(line,5,p)
- local lp = string.sub(line,p+4)
- wget(pn.."/"..sp,libpath..pn.."/"..lp)
- elseif str_starts(line, "RUN") then
- log.i("running command")
- local sp = string.sub(line,5)
- shell.run(sp)
- elseif str_starts(line, "REQUIRE") then
- local sp = string.sub(line,9)
- log.i(string.sub(line,9))
- if str_starts(sp,"HARDWARE") then
- log.i("RHW")
- if(peripheral.find(string.sub(sp,10))==nil) then
- log.w("required Hardware (" .. string.sub(sp,10) .. ") not found")
- if(choice("ignore and continue")) then break else return end
- else
- log.i("required Hardware (" .. string.sub(sp,10) .. ") found")
- end
- end
- elseif str_starts(line,"STARTUP") then
- startup_add(string.sub(line,9))
- elseif str_starts(line,"--") then
- else log.i("error:"..line)
- end
- line=file.readLine()
- end
- file.close()
- end
- local function str_starts(str,pre)
- return string.sub(str,0,string.len(pre))==pre
- end
- local function startup_add(com)
- log.i("register startup:" .. com)
- sf = fs.open("startup","a")
- sf.write("shell.run(\""..com.."\") --apt-get")
- sf.close()
- end
- local function choice(str)
- write(str .." [Y/N]? ")
- c = read()
- if(c=="Y" or c == "y") then return true end
- return false
- end
- if(arg[1]=="install") then install()
- elseif(arg[1]=="update") then update()
- elseif(arg[1]=="upgrade") then upgrade()
- else print("Usage: apt-get update | install <name>")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement