diff --git a/boot/helicopter.ks b/boot/helicopter.ks index f61d23f..1440a86 100644 --- a/boot/helicopter.ks +++ b/boot/helicopter.ks @@ -1,9 +1,11 @@ -deletepath("/boot/helicopter"). +runoncepath("0:/lib/boot"). -compile "0:/lib/stabilize_helicopter" to "1:/lib/stabilize_helicopter". -compile "0:/init/helicopter" to "1:/init". +parameter debug is false. -// Set OS to boot and restart. -set core:bootfilename to "/init". - -reboot. +Bootstrap( +"/boot/helicopter", +"/init/helicopter", +list("/lib/stabilize_helicopter"), +list("/lib/ui"), +debug +). diff --git a/boot/helicopter_debug.ks b/boot/helicopter_debug.ks index 21c206f..8b5f20d 100644 --- a/boot/helicopter_debug.ks +++ b/boot/helicopter_debug.ks @@ -1,5 +1 @@ -copypath("0:/lib/stabilize_helicopter", "1:/lib/stabilize_helicopter"). -copypath("0:/init/helicopter", "1:/init"). - -CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal"). -run "1:/init". +runpath("0:/boot/rocket", true). diff --git a/boot/rocket.ks b/boot/rocket.ks index 1a69918..380a147 100644 --- a/boot/rocket.ks +++ b/boot/rocket.ks @@ -1,19 +1,22 @@ -// rocketOS bootstrapping sequence +runoncepath("0:/lib/boot"). -// To maximize space, remove this file first thing. The in-memory copy -// will still run to completion, and it should only run once per vessel. -deletepath("/boot/rocket"). +parameter debug is false. -// Install software. -copypath("0:/lib/ui", "1:/lib/ui"). -compile "0:/lib/navigation" to "1:/lib/navigation". -compile "0:/lib/throttle" to "1:/lib/throttle". -compile "0:/lib/stabilize_rocket" to "1:/lib/stabilize_rocket". -compile "0:/lib/node" to "1:/lib/node". -compile "0:/init/rocket" to "1:/init". -compile "0:/rocket/launch" to "1:/launch". +local compiled is list( + "/lib/navigation", + "/lib/throttle", + "/lib/stabilize_rocket", + "/lib/node" +). -// Set OS to boot and restart. -set core:bootfilename to "/init". +local copied is list( + "/lib/ui" +). -reboot. +Bootstrap( +"/boot/rocket", +"/init/rocket", +compiled, +copied, +debug +). diff --git a/boot/rocket_debug.ks b/boot/rocket_debug.ks index c7592ad..32d1eb9 100644 --- a/boot/rocket_debug.ks +++ b/boot/rocket_debug.ks @@ -1,11 +1,2 @@ // Install software. -copypath("0:/lib/navigation", "1:/lib/navigation"). -copypath("0:/lib/throttle", "1:/lib/throttle"). -copypath("0:/lib/node", "1:/lib/node"). -copypath("0:/lib/ui", "1:/lib/ui"). -copypath("0:/lib/stabilize_rocket", "1:/lib/stabilize_rocket"). -copypath("0:/init/rocket", "1:/init"). -copypath("0:/rocket/launch", "1:/launch"). - -CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal"). -run "1:/init". +runpath("0:/boot/rocket", true). diff --git a/lib/boot.ks b/lib/boot.ks new file mode 100644 index 0000000..58f12a4 --- /dev/null +++ b/lib/boot.ks @@ -0,0 +1,47 @@ + +function Bootstrap { + parameter bootfile, init, compiled, copied, debug. + compileInit(init, debug). + compileLibs(compiled, debug). + copyLibs(copied). + + if debug { + // Open a terminal and run init. + CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal"). + run "/init". + } else { + DeletePath("1:" + bootfile). + // Set OS to boot and restart. + set core:bootfilename to "/init". + reboot. + } +} + +function compileLibs { + parameter libs, debug. + if debug { + CopyLibs(libs). + return. + } + + for lib in libs { + compile "0:" + lib to "1:" + lib. + } +} + +function copyLibs { + parameter libs. + for lib in libs { + copypath("0:" + lib, "1:" + lib). + } +} + +function copyInit { + parameter init, debug is false. + if debug { + copypath("0:" + init, "1:/init"). + return. + } + + compile "0:" + init to "1:/init". +}