Advertisement
magik6000

Untitled

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