Skip to content

Instantly share code, notes, and snippets.

@Ocawesome101
Created February 17, 2020 06:25
Show Gist options
  • Save Ocawesome101/b152c3870eb66a2b5a130ef224456c96 to your computer and use it in GitHub Desktop.
Save Ocawesome101/b152c3870eb66a2b5a130ef224456c96 to your computer and use it in GitHub Desktop.
-- A fairly simple installer base. Known to work in OpenOS and Open Kernel. --
-- Licensed under the MIT License
-- Copyright (c) 2020 Ocawesome101
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
-- The above copyright notice and this permission notice shall be included in all
-- copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
local args = {...}
-- Set these to the proper name and repo containing your files and a files.list
local USER = ""
local REPO = ""
local BRANCH = "master"
local term = term or require("term")
local read = read or io.read
local http = internet or require("component").internet
local fs = fs or require("filesystem")
local write = write or term.write
local path = args[1] or nil
local function install(path)
local url = "https://raw.githubusercontent.com/" .. USER .. "/" .. REPO .. "/" .. branch .. "/files.list"
local function download(URL)
local h
if http.request then
h = http.request(URL)
h.finishConnect()
else
h = http.get(URL)
end
return h
end
local handle = download(url)
local data = ""
repeat
local chunk = handle.read(0xFFFF)
data = data .. (chunk or "")
until not chunk
handle:close()
local lines = {}
local word = ""
-- Split the files list into lines
for char in string.gmatch(data, ".") do
if char == "\n" then
table.insert(lines, word)
word = ""
else
word = word .. char
end
end
-- Finally, download the files
local baseURL = "https://raw.githubusercontent.com/" .. USER .. "/" .. REPO .. "/" .. BRANCH .. "/"
for i=1, #lines, 1 do
if lines[i]:sub(-1) == "/" then
print("Creating " .. path .. "/" .. lines[i])
fs.makeDirectory(path .. lines[i])
else
print("Downloading " .. lines[i])
local handle = download(baseURL .. lines[i])
local data = ""
repeat
local chunk = handle.read(0xFFFF)
data = data .. (chunk or "")
until not chunk
handle:close()
print("Writing " .. lines[i])
local handle = fs.open(path .. "/" .. lines[i], "w")
if fs.proxy then
handle:write(data)
handle:close()
else
handle.write(data)
handle.close()
end
end
end
fs.setLabel(path, "Open Kernel")
end
local mounts = fs.list("/mnt")
local choice
while true do
print("Please select an install medium.")
if type(mounts) == "function" then
local m = {}
for mount in mounts do
print(i, "/mnt/" .. mount)
table.insert(m, mount)
end
mounts = m
else
for i=1, #mounts, 1 do
print(i, "/mnt/" .. mounts[i])
end
end
write("> ")
local input = read()
if not mounts[tonumber(input)] then
print("Invalid selection")
else
choice = tonumber(input)
break
end
end
local selection = path or "/mnt/" .. mounts[choice]
print("You have selected " .. selection .. ". Continue?")
write("[y/N]: ")
local input = read()
if input:lower() ~= "y" then
print("Answer was not yes, assuming no. Have a good day.")
return false
end
install(selection)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment