Advertisement
Ocawesome101

OC-DOS installer

Feb 17th, 2020
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. -- Licensed under the MIT License
  2.  
  3. -- Copyright (c) 2020 Ocawesome101
  4.  
  5. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  6. -- of this software and associated documentation files (the "Software"), to deal
  7. -- in the Software without restriction, including without limitation the rights
  8. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. -- copies of the Software, and to permit persons to whom the Software is
  10. -- furnished to do so, subject to the following conditions:
  11.  
  12. -- The above copyright notice and this permission notice shall be included in all
  13. -- copies or substantial portions of the Software.
  14.  
  15. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. -- SOFTWARE.
  22.  
  23. local args = {...}
  24.  
  25. -- Set these to the proper name and repo containing your files and a files.list
  26. local USER = "ocawesome101"
  27. local REPO = "oc-dos"
  28. local BRANCH = "master"
  29.  
  30. local term = term or require("term")
  31. local read = read or io.read
  32. local http = internet or require("component").internet
  33. local fs = fs or require("filesystem")
  34.  
  35. local write = write or term.write
  36.  
  37. local path = args[1] or nil
  38.  
  39. local function install(path)
  40. local url = "https://raw.githubusercontent.com/" .. USER .. "/" .. REPO .. "/" .. branch .. "/files.list"
  41. local function download(URL)
  42. local h
  43. if http.request then
  44. h = http.request(URL)
  45. h.finishConnect()
  46. else
  47. h = http.get(URL)
  48. end
  49. return h
  50. end
  51. local handle = download(url)
  52. local data = ""
  53. repeat
  54. local chunk = handle.read(0xFFFF)
  55. data = data .. (chunk or "")
  56. until not chunk
  57.  
  58. handle:close()
  59.  
  60. local lines = {}
  61. local word = ""
  62. -- Split the files list into lines
  63. for char in string.gmatch(data, ".") do
  64. if char == "\n" then
  65. table.insert(lines, word)
  66. word = ""
  67. else
  68. word = word .. char
  69. end
  70. end
  71. -- Finally, download the files
  72. local baseURL = "https://raw.githubusercontent.com/" .. USER .. "/" .. REPO .. "/" .. BRANCH .. "/"
  73. for i=1, #lines, 1 do
  74. if lines[i]:sub(-1) == "/" then
  75. print("Creating " .. path .. "/" .. lines[i])
  76. fs.makeDirectory(path .. lines[i])
  77. else
  78. print("Downloading " .. lines[i])
  79. local handle = download(baseURL .. lines[i])
  80. local data = ""
  81. repeat
  82. local chunk = handle.read(0xFFFF)
  83. data = data .. (chunk or "")
  84. until not chunk
  85.  
  86. handle:close()
  87.  
  88. print("Writing " .. lines[i])
  89. local handle = fs.open(path .. "/" .. lines[i], "w")
  90. if fs.proxy then
  91. handle:write(data)
  92. handle:close()
  93. else
  94. handle.write(data)
  95. handle.close()
  96. end
  97. end
  98. end
  99. fs.setLabel(path, "Open Kernel")
  100. end
  101.  
  102. local mounts = fs.list("/mnt")
  103. local choice
  104. while true do
  105. print("Please select an install medium.")
  106. if type(mounts) == "function" then
  107. local m = {}
  108. for mount in mounts do
  109. print(i, "/mnt/" .. mount)
  110. table.insert(m, mount)
  111. end
  112. mounts = m
  113. else
  114. for i=1, #mounts, 1 do
  115. print(i, "/mnt/" .. mounts[i])
  116. end
  117. end
  118.  
  119. write("> ")
  120.  
  121. local input = read()
  122. if not mounts[tonumber(input)] then
  123. print("Invalid selection")
  124. else
  125. choice = tonumber(input)
  126. break
  127. end
  128. end
  129.  
  130. local selection = path or "/mnt/" .. mounts[choice]
  131.  
  132. print("You have selected " .. selection .. ". Continue?")
  133. write("[y/N]: ")
  134.  
  135. local input = read()
  136.  
  137. if input:lower() ~= "y" then
  138. print("Answer was not yes, assuming no. Have a good day.")
  139. return false
  140. end
  141.  
  142. install(selection)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement