Advertisement
magik6000

Untitled

Nov 22nd, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. --CCPT - ComputerCraft Packaging Tool
  2.  
  3.  
  4. if not http then
  5. error("HTTP API MUST be enabled to use this program")
  6. end
  7.  
  8. ---UTILITIES
  9.  
  10. local function CGetS(file,name)
  11. local _cfg = fs.open(file,"r")
  12. local x = true;
  13.  
  14. while x do
  15. local line = _cfg.readLine()
  16. if line == nil then
  17. x = false;
  18. else
  19.  
  20. local side = false
  21. local prop = ""
  22. local val = ""
  23. for a=1,#line do
  24. if line:sub(a,a) == '=' then
  25. side = true
  26. elseif side then
  27. val = val .. line:sub(a,a)
  28. else
  29. prop = prop .. line:sub(a,a)
  30. end
  31. end
  32. end
  33.  
  34. if prop == name then
  35. _cfg.close()
  36. return val
  37. end
  38. end
  39. _cfg.close()
  40. end
  41.  
  42. local function CGetN(file,name)
  43. return tonumber(GetS(file,name))
  44. end
  45.  
  46. local function download(file, url)
  47. local res = http.get(url)
  48. if res then
  49. local fhnd = fs.open(file, "w");
  50. if fhnd then
  51. fhnd.write(res.readAll())
  52. fhnd.close()
  53. else
  54. res.close()
  55. error("Could not open "..file.." for writing")
  56. end
  57. else
  58. error("Download failed for: "..url)
  59. end
  60. res.close()
  61. end
  62.  
  63. ---Intarnal functions
  64.  
  65. local function update_list()
  66. local sync = CGetS("/etc/ccpt/config","master")
  67. if sync then
  68. download("/etc/ccpt/list",sync)
  69. else
  70. error("Update failed: master server not set!")
  71. end
  72. end
  73.  
  74. ---MAIN CODE
  75.  
  76. local argv = {...}
  77. if argv[1] == "init" then
  78. print("Installing directories")
  79. fs.makeDir("/etc/")
  80. fs.makeDir("/etc/ccpt")
  81. fs.makeDir("/bin/")
  82. fs.makeDir("/usr/")
  83. fs.makeDir("/usr/bin")
  84. fs.makeDir("/usr/lib")
  85. fs.makeDir("/usr/share")
  86. print("Downloading default config")
  87. download("/etc/ccpt/config","http://cc.nativehttp.org/fresh/config")
  88. print("Updating package list")
  89. update_list()
  90. elseif argv[1] == "update" then
  91.  
  92. print("Updating database")
  93.  
  94. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement