From 26dec6fa411ec7a91ec025ab8268c1b4a66457b0 Mon Sep 17 00:00:00 2001 From: IgorTimofeev Date: Thu, 6 Jun 2024 15:36:29 +0300 Subject: [PATCH] Added some checks for PKIX errors in OpenOS installer --- Installer/BIOS.lua | 30 ----------- Installer/OpenOS.lua | 122 +++++++++++++++++++++++++++++++++++++++++++ README-ru_RU.md | 2 +- README-zh_CN.md | 2 +- README.md | 2 +- 5 files changed, 125 insertions(+), 33 deletions(-) delete mode 100644 Installer/BIOS.lua create mode 100644 Installer/OpenOS.lua diff --git a/Installer/BIOS.lua b/Installer/BIOS.lua deleted file mode 100644 index 10d4f05d..00000000 --- a/Installer/BIOS.lua +++ /dev/null @@ -1,30 +0,0 @@ - -local result, reason = "" - -do - local handle, chunk = component.proxy(component.list("internet")() or error("Required internet component is missing")).request("https://raw.githubusercontent.com/IgorTimofeev/MineOS/master/Installer/Main.lua") - - while true do - chunk = handle.read(math.huge) - - if chunk then - result = result .. chunk - else - break - end - end - - handle.close() -end - -result, reason = load(result, "=installer") - -if result then - result, reason = xpcall(result, debug.traceback) - - if not result then - error(reason) - end -else - error(reason) -end diff --git a/Installer/OpenOS.lua b/Installer/OpenOS.lua new file mode 100644 index 00000000..ec93789e --- /dev/null +++ b/Installer/OpenOS.lua @@ -0,0 +1,122 @@ +local component = require("component") +local computer = require("computer") +local os = require("os") + +local gpu = component.gpu + +-- Checking if computer is tough enough for such a S T Y L I S H product as MineOS +do + local potatoes = {} + + -- GPU/screen + if gpu.getDepth() < 8 or gpu.maxResolution() < 160 then + table.insert(potatoes, "Tier 3 graphics card and screen"); + end + + -- RAM + if computer.totalMemory() < 2 * 1024 * 1024 then + table.insert(potatoes, "At least 2x tier 3.5 RAM modules"); + end + + -- HDD + do + local filesystemFound = false + + for address in component.list("filesystem") do + if component.invoke(address, "spaceTotal") >= 2 * 1024 * 1024 then + filesystemFound = true + break + end + end + + if not filesystemFound then + table.insert(potatoes, "At least tier 2 hard disk drive"); + end + end + + -- Internet + if not component.isAvailable("internet") then + table.insert(potatoes, "Internet card"); + end + + -- EEPROM + if not component.isAvailable("eeprom") then + table.insert(potatoes, "EEPROM"); + end + + -- SORRY BRO NOT TODAY + if #potatoes > 0 then + print("Your computer does not meet the minimum system requirements:") + + for i = 1, #potatoes do + print(" ⨯ " .. potatoes[i]) + end + + return + end +end + +-- Checking if installer can be downloaded from GitHub, because of PKIX errors, server blacklists, etc +do + local success, result = pcall(component.internet.request, "https://raw.githubusercontent.com/IgorTimofeev/MineOS/master/Installer/Main.lua") + + if not success then + if result then + if result:match("PKIX") then + print("Download server SSL sertificate was rejected by Java. Update your Java version or install sertificate for github.com manually") + else + print("Download server is unavailable: " .. tostring(result)) + end + else + print("Download server is unavailable for unknown reasons") + end + + return + end + + local deadline = computer.uptime() + 5 + local message + + while computer.uptime() < deadline do + success, message = result.finishConnect() + + if success then + break + else + if message then + break + else + os.sleep(0.1) + end + end + end + + result.close() + + if not success then + print("Download server is unavailable. Check if github.com is not blocked by your internet provider or OpenComputers configuration file") + return + end +end + +-- Flashing EEPROM with tiny script that will run installer itself after reboot. +-- It's necessary, because we need clean computer without OpenOS hooks to computer.pullSignal() +component.eeprom.set([[ + local connection, data, chunk = component.proxy(component.list("internet")()).request("https://raw.githubusercontent.com/IgorTimofeev/MineOS/master/Installer/Main.lua"), "" + + while true do + chunk = connection.read(math.huge) + + if chunk then + data = data .. chunk + else + break + end + end + + connection.close() + + load(data)() +]]) + +computer.shutdown(true) \ No newline at end of file diff --git a/README-ru_RU.md b/README-ru_RU.md index 67d87c8a..0bcd588e 100644 --- a/README-ru_RU.md +++ b/README-ru_RU.md @@ -27,7 +27,7 @@ MineOS - это графическая операционная система Если по какой-то причине ресурс pastebin для вас недоступен, используйте альтернативную команду для установки: - wget -f https://raw.githubusercontent.com/IgorTimofeev/MineOS/master/Installer/BIOS.lua /tmp/bios.lua && flash -q /tmp/bios.lua && reboot + wget -f https://raw.githubusercontent.com/IgorTimofeev/MineOS/master/Installer/OpenOS.lua /tmp/installer.lua && /tmp/installer.lua Вы можете вставить её в консоль, используя среднюю кнопку мыши или кнопку Insert (по умолчанию). Спустя некоторое время запустится симпатичный установщик, где вам предложат выбрать предпочитаемый язык, загрузочный диск (можно отформатировать, если нужно), создать профиль пользователя и настроить несколько параметров под себя. diff --git a/README-zh_CN.md b/README-zh_CN.md index 8a6b80b6..5a5dbadd 100644 --- a/README-zh_CN.md +++ b/README-zh_CN.md @@ -26,7 +26,7 @@ MineOS是一个拥有GUI的操作系统,运行在Minecraft模组Open Computers 如果由于某种原因无法使用pastebin网站,请使用替代安装命令: - wget -f https://raw.githubusercontent.com/IgorTimofeev/MineOS/master/Installer/BIOS.lua /tmp/bios.lua && flash -q /tmp/bios.lua && reboot + wget -f https://raw.githubusercontent.com/IgorTimofeev/MineOS/master/Installer/OpenOS.lua /tmp/installer.lua && /tmp/installer.lua 过一会儿,一个制作优良的系统安装程序将会被启动。 安装程序将提示你选择你的首选语言、选择并格式化引导卷、创建用户配置文件并修改一些设置。 diff --git a/README.md b/README.md index 66423629..aa0463ce 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ The easiest way is to use default `pastebin` script. Insert an OpenOS floppy dis If for some reason pastebin website is not available to you, use alternative installation command: - wget -f https://raw.githubusercontent.com/IgorTimofeev/MineOS/master/Installer/BIOS.lua /tmp/bios.lua && flash -q /tmp/bios.lua && reboot + wget -f https://raw.githubusercontent.com/IgorTimofeev/MineOS/master/Installer/OpenOS.lua /tmp/installer.lua && /tmp/installer.lua You can paste it to console using middle mouse button or Insert key (by default). After a moment, a nice system installer will be shown. You will be prompted to select your preferred language, boot volume (can be formatted if needed), create a user profile and customize some settings