From af603c81b7aaf955f6a3a8d330eaa141bd2987be Mon Sep 17 00:00:00 2001 From: osmarks Date: Tue, 15 Jul 2025 11:58:44 +0100 Subject: [PATCH] some fixes for nesting potatOSes --- manifest | 4 +- src/main.lua | 113 +++++++++++++++++++++++---------------------- src/polychoron.lua | 68 +++++++++++++++------------ 3 files changed, 98 insertions(+), 87 deletions(-) diff --git a/manifest b/manifest index ba99bc9..976a83c 100644 --- a/manifest +++ b/manifest @@ -1,2 +1,2 @@ -{"build":848,"description":"devfs changes","files":{"LICENSES":"f3549d84d66eb53dd4a421a4341d77d3d217c1b117d67e3be8f5211adcda0952","autorun.lua":"831f1a185f32a966668027483de157d955a661115fa692e6b71476ff6f7d3c81","bin/5rot26.lua":"417891a232e325476f980d31d88edc486d526611a6350ce47fd29cca464ebf2c","bin/BSOD.lua":"a2ea9bf1e64dbc2c314e3be71f46e973c0bc2b9c482395120f5d152c6d231e86","bin/b.lua":"5123c6d1bb2b3d6c8e7b4d1b94e60d47c3b6c64c5a0fe8bda8481b718ba00602","bin/build.lua":"a990239e1db05176dd0ba56bc0179eecccd8473d88c6c618d16e72ede270e4c2","bin/ccemux.lua":"239476f58835b86bbcac31ce8af3c3acd3d198a55ab9ada78c62fbf358625a98","bin/chronometer.lua":"db5363993a04382145aef7db2fbe262f0bf10697a589e1e2d2f9ce0f87430dd8","bin/chuck.lua":"571a1eacde435bbd9f54b493149339ac48972a3a4550635b9107da0091fe888a","bin/clear_space.lua":"fc3d52563adaf0491b71227f8b6f615d604063a89830a2ab86a20d10e1a07e97","bin/ctime.lua":"c64022ef0ac641ea531567d770adb306d0d632ff7bd2b692f4915021ed6787c0","bin/devfs.lua":"66e57c37c88bb3d718ec417fd5148be04e5ca464f36754060401c558cbd56486","bin/est.lua":"88ab488c2ded31d67816da8c309a63ac455b461368b3b943aeeb5106b1051cc0","bin/exorcise.lua":"ae25e5939ce52620b0a1e64679a1ac47bcaaff9e323d29c6651bce24a3e58116","bin/factor.lua":"39c2f1709a4258d754278860177c7bb2ea336a8b8392a4c3017c849705e63926","bin/fortune.lua":"64a595afb9ffbaa39622b32379d8dc40d4f1fd36d38027382ed0ae130ad0c59d","bin/game_mode.lua":"f1519969a83e6c7c001d4092cbc7806ea489652ea19022425a893fb4d153572f","bin/grep.lua":"1509bc267867b933e528ab74cfbc2a15fa2df0ec7389df4f9033194ab9037865","bin/hacker.lua":"889e1a47c5ff7470ddf61d87eb7cca9750193976139d513fbe67b7625195d65a","bin/id.lua":"82131679ee35c705458660ac31ab4f5f90169b43f2377fe420a99b1d4c03a4dd","bin/init-screens.lua":"c586a7704030dc1917262f04350e094e1e0ab084793eb1643222498f6436b597","bin/intelligence.lua":"0f14f5a5fb2c6053c19c7a8fa0ba335a69a6fb3b49941c3234dac59795cd3850","bin/kristminer.lua":"7e7f9fe2a6493d584ad6926cda915e02c1c3d800dc209680898ce930d0bb0e6f","bin/livegps.lua":"c3d17d495cda01aa1261e4c4fcd43439b29af422671972117ec34f68e32c5bba","bin/lmatrix.lua":"9d5728b93069d2b763bb8e1dd2a5542995c47daca61f385644431bfc315bc2c4","bin/loading.lua":"c85f7aa1765170325155b921c1fceeb62643f552f12d41b529a22af3a67f5a97","bin/log.lua":"8a553607f81b45e3e0e6d3087735c75fbb38e585d7d1f7a9451b3cb5d0dac330","bin/lyr.lua":"5b17b8cf560ac5dbe4f458d36dff853f51103492952048f233fcad8b319c04e6","bin/maxim.lua":"a68abcb1afae04c9e2177459cd6cb35cf417e4dc80a5bc4580e7cd9b05a44602","bin/norris.lua":"e3105b98d6ac2ba038847fe4a8977db6fbf513b5de6ca3052e7ce20f79d4a314","bin/potatoflight.lua":"2fbb0b6f8d78728d8cb0ec64af1bc598bd00cb55f202378e7acdb86bba71efd1","bin/potatonet.lua":"d58e6aee25190e62a826cc9d195c4aa7e91ac43147d9a8bb8e86d139c7c5bde9","bin/potatoplex.lua":"4399d7cc33004fb21be5a0e2ab8405b8e454c004395844ce7ec42a19965fd415","bin/regset.lua":"423879f14de9efb8192ee718a1d5e129e21f50c50799651b2dcff65287808807","bin/relay.lua":"261ae6c220b83506e3326e8f2b091d246baae458ff0d2ee87512be2c4e35a75d","bin/tau.lua":"45626e749b8734bf466b89f769ec3e5544983a55086c6a165eaabdc0b010b6ac","bin/threat_update.lua":"8f186d04e0845e77a6b5049a8cd182b68f1a5f3c4eb4b3e14ad6a3563ac8dd1e","bin/tryhaskell.lua":"07810d85145da65a3e434154c79d5a9d72f2dcbe59c8d6829040fb925df878ec","bin/umount.lua":"63b2480d5a1e9e5112805e16935a549eb016560eb3400a13bc11c10fcd7fd895","bin/uninstall.lua":"12744da9213a7dba4e72c3dd0a2ac8b84c3a8315247ee4c9aa9af392dfa50b82","bin/upd.lua":"9ce75f3d428f99263392814596b4f782ea17e7f6096dad6038eac65c3fd68cd5","bin/very-uninstall.lua":"90ff8362f85e0acefff011241b0161499a3dc47fa4f2a4c21f6f0789ab9f19b5","bin/viewsource.lua":"02b4dcdb3cf064e7018117fc68a574b260e21561f1813951e4e1de8f0c9420a6","bin/wipe.lua":"2dbc079215c0c06fda182b8878f533631708d95d6148c65f24c606bc3786e2fb","bin/workspace.lua":"acc8bb6f08b243378b68ab5f611e9a6cc8216b0713343dc93ddaa9101f07ffc5","potatobios.lua":"4df202147d3c5b0c04ca11debe30b8cd71b26bfe2712799bc98c9c000b3c910f","signing-key.tbl":"b32af5229c23af3bc03d538e42751b26044e404a7b1af064ed89894efe421607","startup":"a1008f5e11a1c8ec015ac4da3b783b8fb32c08a78f9dfab2b986c44e29b476ea","stdlib.hvl":"a6fd2620068f47794a9bbeed77bee3fd4962f848e6dd7c75137b30cd5665272e","update-key.hex":"8d8afb7a45833bb7d68f929421ad60a211d4d73e0ee03b24dc0106ba1de2e1a0","xlib/00_cbor.lua":"cb00cf146c439edc4caf3a6d0913f6454aa421a85b5b40d7b7f4de5cd7f16a80","xlib/01_skynet.lua":"9cb565d639a0acd7c763c3e7422482532cd0bda0cdfcc720089ab4a87e551339","xlib/02_heavlisp.lua":"82cdabd5286058c0ea4f27956f8c1144e198769c8b8ce9e91b26c930d711f710","xlib/03_lolcrypt.lua":"0ca423837248e405898c436fd7f39c1fff63ba1a1c5610f3e9fb36151a698ff5"},"sizes":{"LICENSES":4725,"autorun.lua":111929,"bin/5rot26.lua":1661,"bin/BSOD.lua":104,"bin/b.lua":34,"bin/build.lua":639,"bin/ccemux.lua":1673,"bin/chronometer.lua":1152,"bin/chuck.lua":29,"bin/clear_space.lua":105,"bin/ctime.lua":1255,"bin/devfs.lua":3826,"bin/est.lua":787,"bin/exorcise.lua":208,"bin/factor.lua":4244,"bin/fortune.lua":24,"bin/game_mode.lua":226,"bin/grep.lua":1196,"bin/hacker.lua":8021,"bin/id.lua":548,"bin/init-screens.lua":36,"bin/intelligence.lua":309,"bin/kristminer.lua":5566,"bin/livegps.lua":980,"bin/lmatrix.lua":1005,"bin/loading.lua":7707,"bin/log.lua":379,"bin/lyr.lua":72,"bin/maxim.lua":22,"bin/norris.lua":45,"bin/potatoflight.lua":3417,"bin/potatonet.lua":19,"bin/potatoplex.lua":6584,"bin/regset.lua":314,"bin/relay.lua":3075,"bin/tau.lua":124,"bin/threat_update.lua":1353,"bin/tryhaskell.lua":1867,"bin/umount.lua":33,"bin/uninstall.lua":166,"bin/upd.lua":16,"bin/very-uninstall.lua":80,"bin/viewsource.lua":1275,"bin/wipe.lua":73,"bin/workspace.lua":42971,"potatobios.lua":43072,"signing-key.tbl":190,"startup":13489,"stdlib.hvl":851,"update-key.hex":44,"xlib/00_cbor.lua":15281,"xlib/01_skynet.lua":3286,"xlib/02_heavlisp.lua":15643,"xlib/03_lolcrypt.lua":3206},"timestamp":1741614827} -{"hash":"fdfacd71ab5ae38c1d882ad0f9624c2a84fd430e1e7c7e1f4f0e94ec3d9d4fd7","sig":"427821bfbde8f1af96eb9f637ec9554adddb780037b22020bca43024c8b5d62272ab9166ab91673cd10e"} \ No newline at end of file +{"build":856,"description":"nesting","files":{"LICENSES":"f3549d84d66eb53dd4a421a4341d77d3d217c1b117d67e3be8f5211adcda0952","autorun.lua":"dd82a54d0a1c9937bab19d450777bb9b1298a8f8bb1a5acad31bdcd2725bf18b","bin/5rot26.lua":"417891a232e325476f980d31d88edc486d526611a6350ce47fd29cca464ebf2c","bin/BSOD.lua":"a2ea9bf1e64dbc2c314e3be71f46e973c0bc2b9c482395120f5d152c6d231e86","bin/b.lua":"5123c6d1bb2b3d6c8e7b4d1b94e60d47c3b6c64c5a0fe8bda8481b718ba00602","bin/build.lua":"a990239e1db05176dd0ba56bc0179eecccd8473d88c6c618d16e72ede270e4c2","bin/ccemux.lua":"239476f58835b86bbcac31ce8af3c3acd3d198a55ab9ada78c62fbf358625a98","bin/chronometer.lua":"db5363993a04382145aef7db2fbe262f0bf10697a589e1e2d2f9ce0f87430dd8","bin/chuck.lua":"571a1eacde435bbd9f54b493149339ac48972a3a4550635b9107da0091fe888a","bin/clear_space.lua":"fc3d52563adaf0491b71227f8b6f615d604063a89830a2ab86a20d10e1a07e97","bin/ctime.lua":"c64022ef0ac641ea531567d770adb306d0d632ff7bd2b692f4915021ed6787c0","bin/devfs.lua":"66e57c37c88bb3d718ec417fd5148be04e5ca464f36754060401c558cbd56486","bin/est.lua":"88ab488c2ded31d67816da8c309a63ac455b461368b3b943aeeb5106b1051cc0","bin/exorcise.lua":"ae25e5939ce52620b0a1e64679a1ac47bcaaff9e323d29c6651bce24a3e58116","bin/factor.lua":"39c2f1709a4258d754278860177c7bb2ea336a8b8392a4c3017c849705e63926","bin/fortune.lua":"64a595afb9ffbaa39622b32379d8dc40d4f1fd36d38027382ed0ae130ad0c59d","bin/game_mode.lua":"f1519969a83e6c7c001d4092cbc7806ea489652ea19022425a893fb4d153572f","bin/grep.lua":"1509bc267867b933e528ab74cfbc2a15fa2df0ec7389df4f9033194ab9037865","bin/hacker.lua":"889e1a47c5ff7470ddf61d87eb7cca9750193976139d513fbe67b7625195d65a","bin/id.lua":"82131679ee35c705458660ac31ab4f5f90169b43f2377fe420a99b1d4c03a4dd","bin/init-screens.lua":"c586a7704030dc1917262f04350e094e1e0ab084793eb1643222498f6436b597","bin/intelligence.lua":"0f14f5a5fb2c6053c19c7a8fa0ba335a69a6fb3b49941c3234dac59795cd3850","bin/kristminer.lua":"7e7f9fe2a6493d584ad6926cda915e02c1c3d800dc209680898ce930d0bb0e6f","bin/livegps.lua":"c3d17d495cda01aa1261e4c4fcd43439b29af422671972117ec34f68e32c5bba","bin/lmatrix.lua":"9d5728b93069d2b763bb8e1dd2a5542995c47daca61f385644431bfc315bc2c4","bin/loading.lua":"c85f7aa1765170325155b921c1fceeb62643f552f12d41b529a22af3a67f5a97","bin/log.lua":"8a553607f81b45e3e0e6d3087735c75fbb38e585d7d1f7a9451b3cb5d0dac330","bin/lyr.lua":"5b17b8cf560ac5dbe4f458d36dff853f51103492952048f233fcad8b319c04e6","bin/maxim.lua":"a68abcb1afae04c9e2177459cd6cb35cf417e4dc80a5bc4580e7cd9b05a44602","bin/norris.lua":"e3105b98d6ac2ba038847fe4a8977db6fbf513b5de6ca3052e7ce20f79d4a314","bin/potatoflight.lua":"2fbb0b6f8d78728d8cb0ec64af1bc598bd00cb55f202378e7acdb86bba71efd1","bin/potatonet.lua":"d58e6aee25190e62a826cc9d195c4aa7e91ac43147d9a8bb8e86d139c7c5bde9","bin/potatoplex.lua":"4399d7cc33004fb21be5a0e2ab8405b8e454c004395844ce7ec42a19965fd415","bin/regset.lua":"423879f14de9efb8192ee718a1d5e129e21f50c50799651b2dcff65287808807","bin/relay.lua":"261ae6c220b83506e3326e8f2b091d246baae458ff0d2ee87512be2c4e35a75d","bin/tau.lua":"45626e749b8734bf466b89f769ec3e5544983a55086c6a165eaabdc0b010b6ac","bin/threat_update.lua":"8f186d04e0845e77a6b5049a8cd182b68f1a5f3c4eb4b3e14ad6a3563ac8dd1e","bin/tryhaskell.lua":"07810d85145da65a3e434154c79d5a9d72f2dcbe59c8d6829040fb925df878ec","bin/umount.lua":"63b2480d5a1e9e5112805e16935a549eb016560eb3400a13bc11c10fcd7fd895","bin/uninstall.lua":"12744da9213a7dba4e72c3dd0a2ac8b84c3a8315247ee4c9aa9af392dfa50b82","bin/upd.lua":"9ce75f3d428f99263392814596b4f782ea17e7f6096dad6038eac65c3fd68cd5","bin/very-uninstall.lua":"90ff8362f85e0acefff011241b0161499a3dc47fa4f2a4c21f6f0789ab9f19b5","bin/viewsource.lua":"02b4dcdb3cf064e7018117fc68a574b260e21561f1813951e4e1de8f0c9420a6","bin/wipe.lua":"2dbc079215c0c06fda182b8878f533631708d95d6148c65f24c606bc3786e2fb","bin/workspace.lua":"acc8bb6f08b243378b68ab5f611e9a6cc8216b0713343dc93ddaa9101f07ffc5","potatobios.lua":"fb1dca42861ac01df033e172c6a612321455d32b7dbe2d7dd3351ada4552a78f","signing-key.tbl":"b32af5229c23af3bc03d538e42751b26044e404a7b1af064ed89894efe421607","startup":"16c39a337e6478f59e7a41cbe5ce742ed662d02431e2946af8b4dee8e9b7bbbc","stdlib.hvl":"a6fd2620068f47794a9bbeed77bee3fd4962f848e6dd7c75137b30cd5665272e","xlib/00_cbor.lua":"cb00cf146c439edc4caf3a6d0913f6454aa421a85b5b40d7b7f4de5cd7f16a80","xlib/01_skynet.lua":"9cb565d639a0acd7c763c3e7422482532cd0bda0cdfcc720089ab4a87e551339","xlib/02_heavlisp.lua":"82cdabd5286058c0ea4f27956f8c1144e198769c8b8ce9e91b26c930d711f710","xlib/03_lolcrypt.lua":"0ca423837248e405898c436fd7f39c1fff63ba1a1c5610f3e9fb36151a698ff5"},"sizes":{"LICENSES":4725,"autorun.lua":216980,"bin/5rot26.lua":1661,"bin/BSOD.lua":104,"bin/b.lua":34,"bin/build.lua":639,"bin/ccemux.lua":1673,"bin/chronometer.lua":1152,"bin/chuck.lua":29,"bin/clear_space.lua":105,"bin/ctime.lua":1255,"bin/devfs.lua":3826,"bin/est.lua":787,"bin/exorcise.lua":208,"bin/factor.lua":4244,"bin/fortune.lua":24,"bin/game_mode.lua":226,"bin/grep.lua":1196,"bin/hacker.lua":8021,"bin/id.lua":548,"bin/init-screens.lua":36,"bin/intelligence.lua":309,"bin/kristminer.lua":5566,"bin/livegps.lua":980,"bin/lmatrix.lua":1005,"bin/loading.lua":7707,"bin/log.lua":379,"bin/lyr.lua":72,"bin/maxim.lua":22,"bin/norris.lua":45,"bin/potatoflight.lua":3417,"bin/potatonet.lua":19,"bin/potatoplex.lua":6584,"bin/regset.lua":314,"bin/relay.lua":3075,"bin/tau.lua":124,"bin/threat_update.lua":1353,"bin/tryhaskell.lua":1867,"bin/umount.lua":33,"bin/uninstall.lua":166,"bin/upd.lua":16,"bin/very-uninstall.lua":80,"bin/viewsource.lua":1275,"bin/wipe.lua":73,"bin/workspace.lua":42971,"potatobios.lua":69364,"signing-key.tbl":190,"startup":13933,"stdlib.hvl":851,"xlib/00_cbor.lua":15281,"xlib/01_skynet.lua":3286,"xlib/02_heavlisp.lua":15643,"xlib/03_lolcrypt.lua":3206},"timestamp":1749073189} +{"hash":"90ad8681e9a698dadf37ab15f31133b62cdef4234b18bb5612120ad3068a2e7a"} \ No newline at end of file diff --git a/src/main.lua b/src/main.lua index c8d3bff..9cd9bd0 100644 --- a/src/main.lua +++ b/src/main.lua @@ -35,9 +35,9 @@ end term.setCursorBlink(false) print "Loading..." -if settings.get "potatOS.rph_mode" == true then +if settings.get "potatOS.rph_mode" == true then print "PotatOS Rph Compliance Mode: Enabled." - return false + return false end require "stack_trace" @@ -97,7 +97,7 @@ local function rot13(s) end end return table.concat(out) -end +end local debugtraceback = debug and debug.traceback local logfile = fs.open("latest.log", "a") @@ -254,7 +254,7 @@ local function clear_space(reqd) if fs.getFreeSpace "/" > (reqd + 4096) then return end - + for _, file in pairs(fs.find(i)) do print("Deleting", file) fs.delete(file) @@ -306,7 +306,7 @@ local function fread(n) out = {string.char(out)} while true do local next = f.read() - if not next then + if not next then out = table.concat(out) break end @@ -451,16 +451,16 @@ function _G.report_incident(incident, flags, options) for k, v in pairs(options.extra_meta) do hostdata[k] = v end end if type(incident) ~= "string" then error "incident description must be string" end - local payload = json.encode { - report = incident, - host = hostdata, - code = options.code or last_loaded, + local payload = json.encode { + report = incident, + host = hostdata, + code = options.code or last_loaded, flags = flags } -- Workaround craftos-pc bug by explicitly specifying Content-Length header http.request { - url = "https://spudnet.osmarks.net/report", - body = payload, + url = "https://spudnet.osmarks.net/report", + body = payload, headers = { ["content-type"] = "application/json", -- Workaround for CraftOS-PC bug where it apparently sends 0, which causes problems in the backend @@ -470,7 +470,7 @@ function _G.report_incident(incident, flags, options) } add_log("reported an incident %s", incident) end - + local disk_code_template = [[ settings.set("potatOS.gen_count", %d) settings.set("potatOS.ancestry", %s) @@ -492,7 +492,7 @@ local function generate_disk_code() ("wget %q startup"):format((registry.get "potatOS.current_manifest.base_URL" or manifest:gsub("/manifest$", "")) .. "/autorun.lua") ) end - + -- Upgrade other disks to contain potatOS and/or load debug programs (mostly the "OmniDisk") off them. local function process_disk(disk_side) local mp = disk.getMountPath(disk_side) @@ -502,8 +502,8 @@ local function process_disk(disk_side) local sig_file = fs.combine(mp, "signature") -- shell.run disks marked with the Brand of PotatOS -- except not actually, it's cool and uses load now - - if fs.exists(ds) and fs.exists(sig_file) then + + if fs.exists(ds) and fs.exists(sig_file) then local code = fread(ds) local sig_raw = fread(sig_file) local sig @@ -537,10 +537,10 @@ local function process_disk(disk_side) else printError "Invalid Signature!" printError "Initiating Procedure 5." - report_incident("invalid signature on disk", + report_incident("invalid signature on disk", {"security", "disk_signature"}, { - code = code, + code = code, extra_meta = { signature = sig_raw, disk_ID = disk_ID, disk_side = disk_side, mount_path = mp } }) printError "This incident has been reported." @@ -561,12 +561,12 @@ local function disk_handler() -- Detect disks initially for _, n in pairs(peripheral.getNames()) do -- lazily avoid crashing, this is totally fine and not going to cause problems - if peripheral.getType(n) == "drive" then + if peripheral.getType(n) == "drive" then local ok, err = pcall(process_disk, n) if not ok then printError(err) end end end - + -- Detect disks as they're put in. Mwahahahaha. -- Please note that this is for definitely non-evil purposes only. while true do @@ -575,7 +575,7 @@ local function disk_handler() if not ok then printError(err) end end end - + --[[ Fix bug PS#201CA2AA Serializing functions, recursive tables, etc. - this is done fairly often - can cause a complete crash of the SPUDNET process. This fixes that. @@ -644,9 +644,10 @@ local function websocket_remote_debugging() local function connect() if ws then ws.close() end - ws, err = http.websocket "wss://spudnet.osmarks.net/v4?enc=json" + local url = "wss://spudnet.osmarks.net/v4?enc=json&rand=" .. math.random(0, 0xFFFFFFF) + ws, err = http.websocket(url) if not ws then add_log("websocket failure %s", err) return false end - ws.url = "wss://spudnet.osmarks.net/v4?enc=json" + ws.url = url send_packet { type = "identify", request_ip = true, implementation = string.format("PotatOS %s on %s", (settings.get "potatOS.current_hash" or "???"):sub(1, 8), _HOST) } send_packet { type = "set_channels", channels = { "client:potatOS" } } @@ -655,13 +656,13 @@ local function websocket_remote_debugging() return true end - + local function try_connect_loop() while not connect() do sleep(0.5) end end - + try_connect_loop() local function recv() @@ -670,7 +671,7 @@ local function websocket_remote_debugging() if u == ws.url then return json.decode(x) end end end - + local ping_timeout_timer = nil process.thread(function() @@ -683,7 +684,7 @@ local function websocket_remote_debugging() end end end, "ping-timeout") - + while true do -- Receive and run code which is sent via SPUDNET -- Also handle SPUDNETv4 protocol, primarily pings @@ -768,7 +769,7 @@ _G.require = simple_require function _G.uninstall(cause) -- this is pointless why is this in the code -- add_log("uninstalling %s", cause) - if not cause then + if not cause then report_incident("uninstall without specified cause", {"security", "uninstall_no_cause", "uninstall"}) error "uninstall cause required" end @@ -839,7 +840,7 @@ local function download_files(manifest_data, needed_files) local x = h.readAll() h.close() local hexsha = hexize(sha256(x)) - if (manifest_data.sizes and manifest_data.sizes[file] and manifest_data.sizes[file] ~= #x) or manifest_data.files[file] ~= hexsha then + if (manifest_data.sizes and manifest_data.sizes[file] and manifest_data.sizes[file] ~= #x) or manifest_data.files[file] ~= hexsha then error(("hash mismatch on %s %s (expected %s, got %s)"):format(file, url, manifest_data.files[file], hexsha)) end fwrite(file, x) @@ -883,7 +884,7 @@ local function process_manifest(url, force, especially_force) local main_data = txt:match "^(.*)\n" local metadata = json.decode(txt:match "\n(.*)$") local main_data_hash = hexize(sha256(main_data)) - + if main_data_hash ~= metadata.hash then error(("hash mismatch: %s %s"):format(main_data_hash, metadata.hash)) @@ -920,8 +921,8 @@ local function process_manifest(url, force, especially_force) for file, hash in pairs(data.files) do if fs.isDir(file) then fs.delete(file) end if not fs.exists(file) then print("missing", file) add_log("nonexistent %s", file) table.insert(needs, file) - elseif (data.sizes and data.sizes[file] and data.sizes[file] ~= fs.getSize(file)) - or (has_manifest and ((current_manifest.files[file] and current_manifest.files[file] ~= hash) or not current_manifest.files[file])) + elseif (data.sizes and data.sizes[file] and data.sizes[file] ~= fs.getSize(file)) + or (has_manifest and ((current_manifest.files[file] and current_manifest.files[file] ~= hash) or not current_manifest.files[file])) or (not has_manifest and hexize(sha256(fread(file))) ~= hash) then add_log("mismatch %s %s", file, hash) print("mismatch on", file, hash) @@ -961,7 +962,7 @@ local function install(force) fs.makeDir(d) end end - + local res = process_manifest(manifest, force) if (res == 0 or res == false) and not force then uncapture_screen() @@ -971,27 +972,27 @@ local function install(force) -- Stop people using disks. Honestly, did they expect THAT to work? set("shell.allow_disk_startup", false) set("shell.allow_startup", true) - + --if fs.exists "startup.lua" and fs.isDir "startup.lua" then fs.delete "startup.lua" end --fwrite("startup.lua", (" "):rep(100)..[[shell.run"pastebin run RM13UGFa"]]) - + -- I mean, the label limit is MEANT to be 32 chars, but who knows, buggy emulators ~~might~~ did let this work... if not os.getComputerLabel() or not (os.getComputerLabel():match "^P/") then os.setComputerLabel("P/" .. randbytes(64)) end - + if not settings.get "potatOS.uuid" then set("potatOS.uuid", gen_uuid()) end if not settings.get "potatOS.ts" then set("potatOS.ts", os.epoch "utc") end - + add_log("update complete", tostring(res) or "[some weirdness]") os.reboot() end - + local function critical_error(err) term.clear() term.setCursorPos(1, 1) @@ -1017,7 +1018,7 @@ end local function run_with_sandbox() -- Load a bunch of necessary PotatoLibraries™ -- if fs.exists "lib/bigfont" then os.loadAPI "lib/bigfont" end - if fs.exists "lib/gps.lua" then + if fs.exists "lib/gps.lua" then os.loadAPI "lib/gps.lua" end @@ -1117,19 +1118,19 @@ local function run_with_sandbox() -- Hook up the debug registry to the potatOS Registry. debug_registry_mt.__index = function(_, k) return registry.get(k) end debug_registry_mt.__newindex = function(_, k, v) return registry.set(k, v) end - + local function fproxy(file) local ok, t = pcall(fread, file) if not ok or not t then return 'printError "Error. Try again later, or reboot, or run upd."' end return t end - + local uuid = settings.get "potatOS.uuid" -- Generate a build number from the first bit of the verhash local full_build = settings.get "potatOS.current_hash" _G.build_number = full_build:sub(1, 8) add_log("build number is %s, uuid is %s", _G.build_number, uuid) - + local is_uninstalling = false -- PotatOS API functionality @@ -1187,7 +1188,7 @@ local function run_with_sandbox() return new end end, - -- Updates potatOS + -- Updates potatOS update = function() process.IPC("potatoupd", "trigger_update", true) end, @@ -1280,7 +1281,7 @@ local function run_with_sandbox() end end end, "privapi") - + local potatOS_proxy = {} for k, v in pairs(potatOS) do potatOS_proxy[k] = (type(v) == "function" and not pure_functions[k]) and function(...) @@ -1295,7 +1296,7 @@ local function run_with_sandbox() end end or v end - + local yafss = require "yafss" local drive_mounts = { @@ -1358,14 +1359,14 @@ local function run_with_sandbox() _VERSION = _VERSION, potatOS = potatOS_proxy } - + --[[ Fix bug PS#22B7A59D Unify constantly-running peripheral manipulation code under one more efficient function, to reduce server load. See the code for the "onsys" process just below for the new version.~~ UPDATE: This is now in netd, formerly lancmd, anyway ]] - + -- Allow limited remote commands over wired LAN networks for improved potatOS cluster management -- PS#C9BA58B3 -- Reduce peripheral calls by moving LAN sign/computer handling into this kind of logic, which is more efficient as it does not constantly run getType/getNames. @@ -1449,8 +1450,8 @@ local function run_with_sandbox() end end end, "netd", { grants = { [notermsentinel] = true }, restrictions = {} }) - - require "metatable_improvements"(potatOS_proxy.add_log, potatOS_proxy.report_incident) + + pcall(require "metatable_improvements", potatOS_proxy.add_log, potatOS_proxy.report_incident) local fss_sentinel = sandboxlib.create_sentinel "fs-sandbox" local debug_sentinel = sandboxlib.create_sentinel "constrained-debug" @@ -1477,17 +1478,17 @@ local function run_with_sandbox() ) end, "sandbox", { restrictions = { [fss_sentinel] = true, [debug_sentinel] = true, [defeature_sentinel] = true } }) add_log "sandbox started" end - + return function(...) local command = table.concat({...}, " ") add_log("command line is %q", command) - + -- Removes whitespace. I don't actually know what uses this either. local function strip_whitespace(text) local newtext = text:gsub("[\r\n ]", "") return newtext end - + -- Detect a few important command-line options. if command:find "rphmode" then set("potatOS.rph_mode", true) end if command:find "mode2" then set("potatOS.hidden", true) end @@ -1500,14 +1501,14 @@ return function(...) end if command:find "update" or command:find "install" then install(true) end if command:find "hedgehog" and command:find "76fde5717a89e332513d4f1e5b36f6cb" then set("potatOS.removable", true) os.reboot() end - + -- enable debug, HTTP if in CraftOS-PC if _G.config and _G.config.get then if config.get "http_enable" ~= true then pcall(config.set, "http_enable", true) end if config.get "debug_enable" ~= true then pcall(config.set, "debug_enable", true) end if config.get "romReadOnly" ~= false then pcall(config.set, "romReadOnly", false) end -- TODO: do something COOL with this. end - + if not process or not fs.exists "potatobios.lua" or not fs.exists "autorun.lua" then -- Polychoron not installed, so PotatOS isn't. local outside_fs = require "sandboxescapes"() if outside_fs then @@ -1525,7 +1526,7 @@ return function(...) -- do updates here local ok, err = pcall(install, false) if not ok then add_log("update error %s", err) end - + -- Spread out updates a bit to reduce load on the server. local timer = os.startTimer(300 + (os.getComputerID() % 100) - 50) while true do @@ -1538,13 +1539,13 @@ return function(...) end end end, "potatoupd") - + -- In case it breaks horribly, display nice messages. local ok, err = pcall(run_with_sandbox) if not ok then critical_error(err) end - + -- In case it crashes... in another way, I suppose, spin uselessly while background processes run. while true do coroutine.yield() end end diff --git a/src/polychoron.lua b/src/polychoron.lua index f042172..958ad9c 100644 --- a/src/polychoron.lua +++ b/src/polychoron.lua @@ -24,13 +24,14 @@ if ccemux then ccemuxnanoTime = ccemux.nanoTime ccemuxecho = ccemux.echo end +local outer_process = _G.process -- Return a time of some sort. Not used to provide "objective" time measurement, just for duration comparison local function time() if ccemuxnanoTime then return ccemuxnanoTime() / 1e9 - elseif osepoch then - return osepoch "utc" / 1000 else + elseif osepoch then + return osepoch "utc" / 1000 else return osclock() end end @@ -158,7 +159,7 @@ local function BSOD(e) term.clear() term.setCursorBlink(false) term.setCursorPos(1, 1) - + print(e) end end @@ -433,8 +434,9 @@ local function run_loop() end end -local function boot() - if ccemuxecho then ccemuxecho("TLCO executed " .. (debugtraceback and debugtraceback() or "succesfully")) end +local function boot(desc) + if ccemuxecho then ccemuxecho(desc .. " executed " .. (debugtraceback and debugtraceback() or "succesfully")) end + term.redirect(term.native()) multishell = nil term.setTextColor(colors.yellow) @@ -443,6 +445,7 @@ local function boot() term.clear() process.spawn(function() os.run({}, "autorun.lua") end, "main", { grants = { [root_capability] = true }, restrictions = {} }) + process.spawn(function() -- bodge, because of the rednet bRunning thing local old_error = error @@ -454,28 +457,35 @@ local function boot() run_loop() end --- fixed TLCO from https://gist.github.com/MCJack123/42bc69d3757226c966da752df80437dc -local old_error = error -local old_os_shutdown = os.shutdown -local old_term_redirect = term.redirect -local old_term_native = term.native -local old_printError = printError -function error() end -function term.redirect() end -function term.native() end -function printError() end -function os.shutdown() - error = old_error - _G.error = old_error - _ENV.error = old_error - printError = old_printError - _G.printError = old_printError - _ENV.printError = old_printError - term.native = old_term_native - term.redirect = old_term_redirect - os.shutdown = old_os_shutdown - os.pullEventRaw = coroutine.yield - boot() -end +-- fix nested potatOSes +if outer_process then + -- cannot TLCO; run under outer process manager + outer_process.spawn(function() boot "nested boot" end, "polychoron") + while true do coroutine.yield() end +else + -- fixed TLCO from https://gist.github.com/MCJack123/42bc69d3757226c966da752df80437dc + local old_error = error + local old_os_shutdown = os.shutdown + local old_term_redirect = term.redirect + local old_term_native = term.native + local old_printError = printError + function error() end + function term.redirect() end + function term.native() end + function printError() end + function os.shutdown() + error = old_error + _G.error = old_error + _ENV.error = old_error + printError = old_printError + _G.printError = old_printError + _ENV.printError = old_printError + term.native = old_term_native + term.redirect = old_term_redirect + os.shutdown = old_os_shutdown + os.pullEventRaw = coroutine.yield + boot "TLCO" + end -os.pullEventRaw = nil \ No newline at end of file + os.pullEventRaw = nil +end