1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
#!/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 : "<unmounted>"));
} else {
if (i.mount && i.mount.trim() !== "") {
return chalk.cyan(i.name + " " + i.label + " " + (i.mount && i.mount.trim() !== "" ? i.mount : "<unmounted>"));
} else {
return chalk.red(i.name + " " + i.label + " " + (i.mount && i.mount.trim() !== "" ? i.mount : "<unmounted>"));
}
}
}).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(() => {})
})()
|