Advertisement
tima_gt

trepo 2.1

Dec 14th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.22 KB | None | 0 0
  1. local resp = true
  2. args = {...}
  3. local function add_ons_toInt(number_of_addOns)
  4. if number_of_addOns == "0" then
  5. add_ons = 0
  6. elseif number_of_addOns == "1" then
  7. add_ons = 1
  8. elseif number_of_addOns == "2" then
  9. add_ons = 2
  10. elseif number_of_addOns == "3" then
  11. add_ons = 3
  12. elseif number_of_addOns == "4" then
  13. add_ons = 4
  14. elseif number_of_addOns == "5" then
  15. add_ons = 5
  16. elseif number_of_addOns == "6" then
  17. add_ons = 6
  18. elseif number_of_addOns == "7" then
  19. add_ons = 7
  20. elseif number_of_addOns == "8" then
  21. add_ons = 8
  22. elseif number_of_addOns == "9" then
  23. add_ons = 9
  24. elseif number_of_addOns == "10" then
  25. add_ons = 10
  26. elseif number_of_addOns == "11" then
  27. add_ons = 11
  28. else
  29. add_ons = 0
  30. end
  31. end
  32. if (args[1] == nil) or (args[1] == "") then
  33. print("tget initialized!")
  34. print("scanning for repository...")
  35. print("What you want to install?")
  36. write(">")
  37. program = read()
  38. print("searching for package...")
  39. else
  40. program = args[1]
  41. if args[2] == "--force" then
  42. force = true
  43. end
  44. progargs = true
  45. end
  46. informationFile = http.get("http://192.168.1.130/trepo/"..program.."/pkg_info")
  47. if informationFile then
  48. cache = informationFile.readLine()
  49. name2 = informationFile.readLine()
  50. if progargs ~= true then
  51. print("Full package name:")
  52. end
  53. if term.isColor() then
  54. term.setTextColor(colors.yellow) end
  55. print(name2)
  56. if term.isColor() then
  57. term.setTextColor(colors.white) end
  58. cache = informationFile.readLine()
  59. version = informationFile.readLine()
  60. if progargs ~= true then
  61. if fs.exists("."..program.."."..version) then
  62. error("You have nevest version", 0)
  63. end
  64. end
  65. cache = informationFile.readLine()
  66. add_ons_toInt(informationFile.readLine())
  67. if add_ons == 0 then
  68. os.sleep(0)
  69. else
  70. print("resolving dependens...")
  71. i = 1
  72. d = {}
  73. while i <= add_ons do
  74. d[i] = informationFile.readLine()
  75. dlist = i
  76. i = i + 1
  77. end
  78. i = 1
  79. print("dependences is:")
  80. while i <= add_ons do
  81. os.sleep(0.8)
  82. if term.isColor() then
  83. term.setTextColor(colors.red) end
  84. print(d[i])
  85. term.setTextColor(colors.white)
  86. i = i + 1
  87. end
  88. end
  89. informationFile.close()
  90. if force ~= true then
  91. print("would you like to install this package?")
  92. write("[Y/n]?")
  93. a = read()
  94. else
  95. a = "Y"
  96. end
  97. if (a == "") or (a == "Y") or (a == "y") then
  98. a = true
  99. if add_ons == 0 then
  100. print("installing...")
  101. programd = "http://192.168.1.130/trepo/"..program.."/program/"..version.."/"..program
  102. file = http.get(programd)
  103. program_code = file.readAll()
  104. file.close()
  105. file = fs.open(program, "w")
  106. file.write(program_code)
  107. file.close()
  108. else
  109. i = 1
  110. while i <= dlist do
  111. print("Installing "..d[i].."...")
  112. file = http.get("http://192.168.1.130/trepo/"..program.."/add-ons/"..d[i])
  113. add_on_code = file.readAll()
  114. file.close()
  115. file = fs.open(d[i], "w")
  116. file.write(add_on_code)
  117. file.close()
  118. print("OK.")
  119. i = i + 1
  120. end
  121. file = http.get("http://192.168.1.130/trepo/"..program.."/program/"..version.."/"..program)
  122. print("installing "..program.."...")
  123. program_code = file.readAll()
  124. file.close()
  125. file = fs.open(program, "w")
  126. file.write(program_code)
  127. file.close()
  128. print("Ok.")
  129. print("Setting up the package...")
  130. file = fs.open("."..program.."."..version, "w")
  131. file.writeLine("installed")
  132. file.close()
  133. print("Done!")
  134. end
  135. end
  136. else
  137. print("tget have some errors:")
  138. print("error IO Read: 404 page not found!")
  139. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement