2021-08-02 04:06:43 +00:00
|
|
|
|
2021-09-01 05:46:03 +00:00
|
|
|
// "bootfile" should be the path to the bootfile, so it can be deleted.
|
|
|
|
// "programs" is a List() of programs to install in the CPU root.
|
|
|
|
// "debug" will skip compiling if enabled, and only copy files.
|
|
|
|
// if "init" is true, the first program in the programs List will become the new boot file.
|
|
|
|
// pass false in here if you want CPU control from the terminal.
|
2021-08-02 04:06:43 +00:00
|
|
|
function Bootstrap {
|
2021-09-01 05:46:03 +00:00
|
|
|
parameter bootFile, programs, debug, init is true.
|
|
|
|
|
|
|
|
local initProgram is "".
|
|
|
|
if init {
|
|
|
|
set initProgram to programs[0]:Replace("/prog", "").
|
|
|
|
}
|
2021-08-02 04:06:43 +00:00
|
|
|
|
2021-08-19 02:25:20 +00:00
|
|
|
// create a list of libraries that we need to compile
|
|
|
|
local libs is UniqueSet().
|
|
|
|
for program in programs {
|
|
|
|
addLibs(libs, program).
|
|
|
|
}
|
|
|
|
|
|
|
|
// compile the main program files
|
|
|
|
for program in programs {
|
|
|
|
compileFile(program, program:Replace("/prog", ""), debug).
|
|
|
|
}
|
|
|
|
|
|
|
|
// compile the libraries
|
|
|
|
for lib in libs {
|
2021-08-20 03:54:40 +00:00
|
|
|
compileFile(lib, lib, debug).
|
2021-08-19 02:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Either run init with a terminal open...
|
2021-08-02 04:06:43 +00:00
|
|
|
if debug {
|
|
|
|
// Open a terminal and run init.
|
|
|
|
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal").
|
2021-08-04 22:41:13 +00:00
|
|
|
if init <> "" {
|
2021-09-01 05:46:03 +00:00
|
|
|
RunPath(initProgram).
|
2021-08-04 22:41:13 +00:00
|
|
|
}
|
2021-09-01 05:46:03 +00:00
|
|
|
// ... or delete the bootstrapping file, configure to boot from the init program,
|
2021-08-19 02:25:20 +00:00
|
|
|
// and reboot.
|
2021-08-02 04:06:43 +00:00
|
|
|
} else {
|
|
|
|
DeletePath("1:" + bootfile).
|
2021-09-01 05:46:03 +00:00
|
|
|
set CORE:BOOTFILENAME to initProgram.
|
2021-08-20 03:57:25 +00:00
|
|
|
reboot.
|
2021-08-02 04:06:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-19 02:25:20 +00:00
|
|
|
// compile the target ('src') file on volume 0, compare compiled size with source size,
|
|
|
|
// copy the smaller file to 'dest' on volume 1.
|
|
|
|
// if debug is true, instead just copies src (volume 0) to dest (volume 1).
|
|
|
|
function compileFile {
|
|
|
|
parameter src, dest, debug is false.
|
|
|
|
|
2021-08-02 04:06:43 +00:00
|
|
|
if debug {
|
2021-08-19 02:25:20 +00:00
|
|
|
CopyPath("0:" + src + ".ks", "1:" + dest + ".ks").
|
2021-08-21 05:46:53 +00:00
|
|
|
return.
|
2021-08-02 04:06:43 +00:00
|
|
|
}
|
|
|
|
|
2021-08-19 02:25:20 +00:00
|
|
|
compile "0:" + src.
|
2021-08-20 03:54:40 +00:00
|
|
|
local srcVF is Open("0:" + src + ".ks").
|
|
|
|
local compiledVF is Open("0:" + src + ".ksm").
|
|
|
|
|
2021-08-19 02:25:20 +00:00
|
|
|
if srcVF:SIZE < compiledVF:SIZE {
|
|
|
|
CopyPath("0:" + src + ".ks", "1:" + dest + ".ks").
|
|
|
|
} else {
|
|
|
|
CopyPath("0:" + src + ".ksm", "1:" + dest + ".ksm").
|
2021-08-02 04:06:43 +00:00
|
|
|
}
|
|
|
|
|
2021-08-19 02:25:20 +00:00
|
|
|
DeletePath(compiledVF).
|
2021-08-02 04:06:43 +00:00
|
|
|
}
|
|
|
|
|
2021-08-19 02:25:20 +00:00
|
|
|
function addLibs {
|
|
|
|
parameter libs, src.
|
2021-08-04 22:41:13 +00:00
|
|
|
|
2021-08-19 02:25:20 +00:00
|
|
|
local srcVF is Open("0:" + src).
|
|
|
|
local contents is srcVF:ReadAll().
|
|
|
|
for line in contents {
|
|
|
|
if line:Contains("RunOncePath") {
|
2021-08-20 03:54:40 +00:00
|
|
|
local start is line:Find(char(34)).
|
|
|
|
local end is line:FindLast(char(34)).
|
2021-08-24 10:10:21 +00:00
|
|
|
local libFile is line:Substring(start + 1, end - start - 1).
|
|
|
|
libs:Add(libFile).
|
|
|
|
addLibs(libs, libFile).
|
2021-08-19 02:25:20 +00:00
|
|
|
}
|
2021-08-02 04:06:43 +00:00
|
|
|
}
|
|
|
|
}
|