Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --CCPT - ComputerCraft Packaging Tool
- if not http then
- error("HTTP API MUST be enabled to use this program")
- end
- ---UTILITIES
- local function CGetS(file,name)
- local _cfg = fs.open(file,"r")
- if not cfg then
- error("Could not open configuration file: "..file)
- end
- local x = true;
- while x do
- local line = _cfg.readLine()
- if line == nil then
- x = false;
- else
- local side = false
- local prop = ""
- local val = ""
- for a=1,#line do
- if line:sub(a,a) == '=' then
- side = true
- elseif side then
- val = val .. line:sub(a,a)
- else
- prop = prop .. line:sub(a,a)
- end
- end
- end
- if prop == name then
- _cfg.close()
- return val
- end
- end
- _cfg.close()
- end
- local function CGetN(file,name)
- return tonumber(GetS(file,name))
- end
- local function download(file, url)
- local res = http.get(url)
- if res then
- local fhnd = fs.open(file, "w");
- if fhnd then
- fhnd.write(res.readAll())
- fhnd.close()
- else
- res.close()
- error("Could not open "..file.." for writing")
- end
- else
- error("Download failed for: "..url)
- end
- res.close()
- end
- ---Intarnal functions
- local function update_list()
- local sync = CGetS("/etc/ccpt/config","master")
- if sync then
- download("/etc/ccpt/list",sync)
- else
- error("Update failed: master server not set!")
- end
- end
- ---MAIN CODE
- local argv = {...}
- if argv[1] == "init" then
- print("Installing directories")
- fs.makeDir("/etc/")
- fs.makeDir("/etc/ccpt")
- fs.makeDir("/bin/")
- fs.makeDir("/usr/")
- fs.makeDir("/usr/bin")
- fs.makeDir("/usr/lib")
- fs.makeDir("/usr/share")
- print("Downloading default config")
- download("/etc/ccpt/config","http://cc.nativehttp.org/fresh/config")
- print("Updating package list")
- update_list()
- elseif argv[1] == "update" then
- print("Updating database")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement