kOS-scripts/boot/default.ks
2019-02-16 22:37:59 +01:00

76 lines
1.9 KiB
Plaintext

@LAZYGLOBAL OFF.
clearscreen.
clearguis().
clearvecdraws().
set TERMINAL:width to max(TERMINAL:width, 50).
set TERMINAL:height to max(TERMINAL:height, 30).
CORE:doaction("Open Terminal", true).
print "==================== BOOTING =====================".
wait until SHIP:loaded and SHIP:unpacked.
wait 0.001. // wait one physics tick
if HOMECONNECTION:isconnected {
copy_scripts().
} else {
print "No connection to KSC: not updating scripts.".
}
print "============= BOOT SEQUENCE COMPLETE =============".
local function copy_scripts {
//
// Copy all .ks-files from the archive to the CPU's internal storage.
//
parameter archive_dir is ARCHIVE:files.
for item in archive_dir:values {
// Recurse on directories
if not item:isfile {
copy_scripts(item:list).
}
local item_path is "/" + path(item):segments:join("/"). // full path of item without volume id
if should_copy(item, item_path) {
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.
}
}
}
}
local function should_copy {
parameter item.
parameter item_path.
// Skip Linux hidden files and directories (e.g. .git)
if item:name[0] = "." {
return false.
}
// Skip non-script items (e.g. README.md)
if item:extension <> "ks" {
return false.
}
// Always copy files we don't have
if not CORE:volume:exists(item_path) {
return true.
}
// Copy file if local one has different size
if item:size <> CORE:volume:open(item_path):size {
return true.
}
// Copy file if local one has different contents
if item:readall:string <> CORE:volume:open(item_path):readall:string {
return true.
}
return false.
}