Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local param = {...}
- local modem = peripheral.wrap("back")
- modem.open(40)
- function get(filename)
- print("requesting "..filename)
- modem.transmit(41,40,"get "..filename)
- local code = getMsg()
- if code ~= "200" then
- print("Error "..code)
- return
- else
- print("OK "..code .. " downloading ...")
- data = getMsg()
- if not fs.exists("apt-files") then fs.makeDir("apt-files") end
- file = fs.open("apt-files/"..filename,"w")
- file.write(data)
- file.close()
- print(" done")
- end
- end
- function update()
- print("update started")
- local list = fs.list("apt-files")
- for i=1,#list do
- if not fs.isDir(list[i]) then
- get(fs.getName(list[i]))
- end
- end
- print("update finished")
- end
- function getMsg()
- local e,s,ch1,ch2,msg,d =os.pullEvent("modem_message")
- return msg
- end
- function printUsage()
- print("Usage: apt-get install <filename>")
- print(" apt-get update")
- end
- if #param < 1 then
- printUsage()
- else
- if param[1]=="install" then get(param[1]) end
- if param[1]=="update" then update() end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement