#!/usr/bin/env node require('hide-terminal-cursor')(); if (process.stdout.rows <= 50 || process.stdout.columns <= 130) { console.clear(); require('child_process').execSync("aplay /home/strawberry/strawberry/failure.wav 2> /dev/null"); process.exit(); } console.clear(); require('child_process').execSync("aplay /home/strawberry/strawberry/boot.wav 2> /dev/null"); if (require('fs').existsSync("/home/strawberry/strawberry/restart")) { require('fs').rmSync("/home/strawberry/strawberry/restart"); } global.osVersion = "1.1.7"; global.osVersionCode = 9; global.version = "1.5.6"; global.message = "Please insert a Startup Disk containing Strawberry OS " + osVersion + " or later."; global.mounted = false; (async () => { function error(text, text2) { clearInterval(loadInterval); clearInterval(loadInterval2); console.clear(); let out = ""; global.vertical = Math.round(process.stdout.rows / 2); let horizontal = Math.round(process.stdout.columns / 2 - (1 + (text.length / 2))); let horizontal2 = Math.round(process.stdout.columns / 2 - (1 + (text2.length / 2))); for (let n = 0; n < vertical; n++) { out += "\n" + " ".repeat(process.stdout.columns); } out += " ".repeat(horizontal) + text + " ".repeat(process.stdout.columns - horizontal - text.length) + "\n" + " ".repeat(horizontal2) + text2 + " ".repeat(process.stdout.columns - horizontal2 - text2.length); for (let n = 0; n < vertical - 2; n++) { out += "\n" + " ".repeat(process.stdout.columns); } console.log(chalk.bgRed.whiteBright(out)); if (fs.existsSync("/home/strawberry/strawberry/restart")) { fs.rmSync("/home/strawberry/strawberry/restart"); } else { require('child_process').execSync("aplay /home/strawberry/strawberry/crash.wav 2> /dev/null"); } } process.on('uncaughtException', (error) => { let text2; let text; if (error.message === "User pressed interrupt button") { text2 = "Error Code 0x00000003"; text = "The user interrupted the system's behavior."; } else { text2 = "Error Code 0xF" + require('crypto').createHash('md5').update(error.message).digest('hex').substring(0, 7).toUpperCase(); text = "The system encountered a serious internal error and couldn't continue running."; } clearInterval(loadInterval); clearInterval(loadInterval2); console.clear(); let out = ""; global.vertical = Math.round(process.stdout.rows / 2); let horizontal = Math.round(process.stdout.columns / 2 - (1 + (text.length / 2))); let horizontal2 = Math.round(process.stdout.columns / 2 - (1 + (text2.length / 2))); for (let n = 0; n < vertical; n++) { out += "\n" + " ".repeat(process.stdout.columns); } out += " ".repeat(horizontal) + text + " ".repeat(process.stdout.columns - horizontal - text.length) + "\n" + " ".repeat(horizontal2) + text2 + " ".repeat(process.stdout.columns - horizontal2 - text2.length); for (let n = 0; n < vertical - 2; n++) { out += "\n" + " ".repeat(process.stdout.columns); } console.log(chalk.bgRed.whiteBright(out)); process.stdout.cursorTo(0, 0); if (error.message !== "User pressed interrupt button") { process.stdout.write(error.stack); fs.writeFileSync("lastError.txt", error.stack); } if (fs.existsSync("/home/strawberry/strawberry/restart")) { fs.rmSync("/home/strawberry/strawberry/restart"); } else { if (error.message.endsWith("EIO")) { console.clear(); require('child_process').execSync("aplay /home/strawberry/strawberry/failure.wav 2> /dev/null"); } else { require('child_process').execSync("aplay /home/strawberry/strawberry/crash.wav 2> /dev/null"); } } process.exit(); }) const chalk = (await import('chalk')).default; const os = require('os'); const fs = require('fs'); const si = require('systeminformation'); if (!fs.existsSync("/Strawberry")) fs.mkdirSync("/Strawberry"); process.stdin.setRawMode(true); function clear() { process.stdout.cursorTo(0, vertical - 3); process.stdout.write(chalk.bgWhite.black(" ".repeat(process.stdout.columns))); } async function display() { let horizontal = Math.round(process.stdout.columns / 2 - (1 + (message.length / 2))); process.stdout.cursorTo(0, vertical - 3); process.stdout.write(chalk.bgWhite.black(" ".repeat(horizontal) + message + " ".repeat(process.stdout.columns - horizontal - message.length))); let disks = (await si.blockDevices()).filter((i) => { return i.type === "part"; }); process.stdout.cursorTo(0, process.stdout.columns - 1); process.stdout.clearLine(undefined, undefined); process.stdout.write(chalk.whiteBright("strawberry-boot v" + version + ", kernel-hal v" + os.release() + ", core v" + process.versions.node + " - " + process.arch + " x" + os.cpus().length + " - Partitions detected: " + disks.length + " (" + disks.map((i) => { if (i.label === "SBSTARTUPDK") { require('child_process').exec("mount -o ro /dev/" + i.name + " /Strawberry"); if (i.mount === "/Strawberry") { global.mounted = true; } return chalk.green(i.name + " " + i.label + " " + (i.mount && i.mount.trim() !== "" ? i.mount : "")); } else { if (i.mount && i.mount.trim() !== "") { return chalk.cyan(i.name + " " + i.label + " " + (i.mount && i.mount.trim() !== "" ? i.mount : "")); } else { return chalk.red(i.name + " " + i.label + " " + (i.mount && i.mount.trim() !== "" ? i.mount : "")); } } }).join(", ") + ")")); process.stdout.cursorTo(0, vertical - 3); if (mounted) { if (fs.existsSync("/Strawberry/System")) { let localVersion = parseInt(fs.readFileSync("/Strawberry/System/Version").toString().trim().split("\n")[0].trim()); if (localVersion < osVersionCode) { error("The inserted Strawberry Startup Disk is not compatible with this device.", "Error Code 0x0000002B") } else { global.message = "Checking Startup Disk..."; } } else { error("The inserted Strawberry Startup Disk is not compatible with this device.", "Error Code 0x0000000A") } if (global.message === "Checking Startup Disk...") { require('/Strawberry/System/Startup.js'); } } } global.center = (text) => { let out = ""; global.vertical = Math.round(process.stdout.rows / 2 + 1); let horizontal = Math.round(process.stdout.columns / 2 - (1 + (text.length / 2))); for (let n = 0; n < vertical; n++) { out += "\n" + " ".repeat(process.stdout.columns); } out += " ".repeat(horizontal) + text + " ".repeat(process.stdout.columns - horizontal - text.length); for (let n = 0; n < vertical - 2; n++) { out += "\n" + " ".repeat(process.stdout.columns); } return chalk.bgWhite.black(out); } console.clear(); console.log(center("")); process.stdout.write(chalk.whiteBright("strawberry-boot v" + version + ", kernel-hal v" + os.release() + ", core v" + process.versions.node + " - " + process.arch + " x" + os.cpus().length + " - Partitions detected: Please wait...")); process.stdout.cursorTo(0, 0); global.loadInterval = setInterval(clear, 2000); setTimeout(() => { global.loadInterval2 = setInterval(display, 2000); }, 1000) setInterval(() => {}) })()