kOS-scripts/boot/default.ks

58 lines
1.7 KiB
Plaintext
Raw Normal View History

@LAZYGLOBAL OFF.
clearscreen.
clearguis().
clearvecdraws().
set TERMINAL:width to 50.
set TERMINAL:height to 30.
CORE:doaction("Open Terminal", true).
2019-02-08 18:45:13 +01:00
print "==================== BOOTING =====================".
wait until SHIP:loaded and SHIP:unpacked.
2019-02-08 18:45:13 +01:00
wait 0.001. // wait one physics tick
2018-07-19 14:42:03 +02:00
if HOMECONNECTION:isconnected {
2019-02-08 03:49:57 +01:00
copy_scripts().
} else {
print "No connection to KSC: not updating scripts.".
}
2019-02-08 18:45:13 +01:00
print "============= BOOT SEQUENCE COMPLETE =============".
2019-02-08 03:49:57 +01:00
function copy_scripts {
2019-02-07 21:56:34 +01:00
//
// Copy all .ks-files from the archive to the CPU's internal storage.
2019-02-07 21:56:34 +01:00
//
2019-02-08 03:49:57 +01:00
parameter archive_dir is ARCHIVE:files.
for item in archive_dir:values {
function iteration { // allows for quick-bailing using 'return' (kOS doesn't have the 'continue' keyword
local item_path is "/" + path(item):segments:join("/"). // full path of item without volume id
if item:name[0] = "." // skip Linux hidden files and directories (e.g. .git)
return.
// Recurse on directories
if not item:isfile {
copy_scripts(item:list).
return.
}
if item:extension <> "ks" // skip non-script items (e.g. README.md)
return.
if CORE:volume:exists(item_path) and item:size = CORE:volume:open(item_path):size // skip if file exists locally with the same size
return.
print "Copying " + item_path.
copypath(item, path(CORE:volume):combine(item_path)).
if item_path = CORE:bootfilename {
print "Rebooting to apply new bootfile".
wait 2.
reboot.
}
}
iteration().
}
}