Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local hidden = false
- local function randbytes(len)
- local out = ""
- for i = 1, len do
- out = out .. string.char(math.random(0, 255))
- end
- return out
- end
- local function fetch(u)
- local h = http.get(u)
- local c = h.readAll()
- h.close()
- return c
- end
- local function fwrite(n, c)
- local f = fs.open(n, "w")
- f.write(c)
- f.close()
- end
- -- Read file "n"
- local function fread(n)
- local f = fs.open(n, "r")
- local out = f.readAll()
- f.close()
- return out
- end
- local function set(k, v)
- settings.set(k, v)
- settings.save(".settings")
- end
- local function map(f, t)
- local mapper = function(t)
- local new = {}
- for k, v in pairs(t) do
- local new_v, new_k = f(v, k)
- new[new_k or k] = new_v
- end
- return new
- end
- if t then return mapper(t) else return mapper end
- end
- local function arrayize(t)
- local out = {}
- for k, v in pairs(t) do table.insert(out, v) end
- return out
- end
- local this_file = "autorun"
- local this_file_URL = "https://pastebin.com/raw/T81NJMpt"
- local files = {
- -- CRITICAL FILES
- ["https://pastebin.com/raw/HL0SZhJG"] = "startup", -- "Polychoron" process manager - needs to be startup for TLCOing
- [this_file_URL] = this_file,
- ["https://pastebin.com/raw/rxkE8N8b"] = "stack_trace",
- ["https://pastebin.com/raw/LzEYgSZi"] = "bios",
- -- LIBRARIES
- ["https://raw.githubusercontent.com/osmarks/skynet/master/client.lua"] = "lib/02-skynet",
- ["https://raw.githubusercontent.com/rxi/json.lua/bee7ee3431133009a97257bde73da8a34e53c15c/json.lua"] = "lib/01-json",
- ["https://pastebin.com/raw/Frv3xkB9"] = "lib/03-yafss",
- ["https://pastebin.com/raw/KXHSsHkt"] = "lib/04-ser",
- ["https://pastebin.com/raw/2kRenvr3"] = "lib/05-registry",
- ["https://raw.githubusercontent.com/tmpim/luadash/master/library.lua"] = "lib/06-dash",
- ["https://pastebin.com/raw/PkaFNfcq"] = "lib/50-potatOS",
- -- MODULES
- ["https://pastebin.com/raw/7RDG0ueq"] = "mod/01-spudnetd",
- ["https://pastebin.com/raw/690JY2dK"] = "mod/02-netbootd",
- ["https://pastebin.com/raw/ABd8CGJB"] = "mod/03-locationd",
- -- MISCELLANEOUS FILES
- ["https://pastebin.com/raw/NdUKJ07j"] = "LICENSES"
- }
- local function install()
- -- Make a folder where users' files will go.
- fs.makeDir "userdata"
- -- Download all files in parallel.
- local fns = arrayize(map(function(filename, URL)
- return function()
- local dir = fs.getDir(filename)
- if dir ~= "" then
- if not fs.isDir(dir) then fs.makeDir(dir) end
- end
- if fs.isDir(filename) then fs.delete(filename) end
- fwrite(filename, fetch(("%s?%d"):format(URL, math.random(0, 10000))))
- if not hidden then print("Downloaded", filename) end
- end
- end, files))
- parallel.waitForAll(unpack(fns))
- -- Stop people using disks. Honestly, did they expect THAT to work?
- set("shell.allow_disk_startup", false)
- set("shell.allow_startup", true)
- os.setComputerLabel("P4/" .. randbytes(64))
- os.reboot()
- end
- local background_task_interval = 300 + (os.getComputerID() % 20)
- local function update_checker()
- local this = fread(this_file)
- while true do
- local new = fetch(this_file_URL)
- local ok, err = load(new)
- if not ok then print("Syntax error in update:", printError(err))
- else
- if new ~= this then
- install()
- end
- end
- sleep(background_task_interval)
- end
- end
- local function load_module(E, mod_path)
- local fn, err = load(fread(fs.combine("/mod", mod_path)), "@" .. mod_path, nil, E)
- if not fn then
- printError(("%s LOAD ERROR:\n%s"):format(mod_path, err))
- return
- end
- local ok, mod = pcall(fn)
- if not ok then printError(("%s PREEXEC ERROR:\n%s"):format(mod_path, mod)) end
- if mod.async then process.spawn(mod.async, mod.name) end
- if mod.sync then
- local ok, err = pcall(mod.sync, mod)
- if not ok then
- printError(("%s EXEC ERROR:\n%s"):format(mod.name, err))
- end
- end
- end
- local function load_library(E, lib)
- local ok, res = pcall(loadfile(fs.combine("/lib", lib), E))
- local libname = lib:match "^[^-]*\-(.*)$"
- if ok then
- E[libname] = res
- package.loaded[libname] = res
- else
- printError(("%s ERROR:\n%s"):format(libname, res))
- end
- end
- local function main()
- if fs.exists "stack_trace" then dofile "stack_trace" end
- process.spawn(update_checker, "updd")
- local E = {}
- setmetatable(E, { __index = _ENV })
- for _, file in pairs(fs.list "/lib") do
- load_library(E, file)
- end
- local fns = {}
- for _, file in pairs(fs.list "/mod") do
- table.insert(fns, function() load_module(E, file) end)
- end
- parallel.waitForAll(unpack(fns))
- E.yafss("userdata", {}, E, fread "bios")
- while true do coroutine.yield() end
- end
- local args = table.concat({...}, " ")
- if args:find "update" or args:find "install" then install() end
- if polychoron and fs.exists "startup" and fs.exists "LICENSES" then
- local ok, err = pcall(main)
- if not ok then polychoron.BSOD(err) end
- else
- install()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement