kOS-scripts/boot/default.ks

79 lines
1.9 KiB
Plaintext
Raw Normal View History

@LAZYGLOBAL OFF.
clearscreen.
clearguis().
clearvecdraws().
2019-02-10 15:33:50 +01:00
set TERMINAL:width to max(TERMINAL:width, 50).
set TERMINAL:height to max(TERMINAL:height, 30).
CORE:doaction("Open Terminal", true).
2019-02-08 18:45:13 +01:00
print "==================== BOOTING =====================".
wait until SHIP:loaded and SHIP:unpacked.
2019-03-01 23:08:50 +01:00
wait 0. // 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-16 22:37:59 +01:00
local 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 {
2019-02-16 22:37:59 +01:00
// Recurse on directories
if not item:isfile {
copy_scripts(item:list).
}
2019-02-08 03:49:57 +01:00
2019-02-16 22:37:59 +01:00
local item_path is "/" + path(item):segments:join("/"). // full path of item without volume id
if should_copy(item, item_path) {
2019-02-08 03:49:57 +01:00
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.
}
}
}
}
2019-02-16 22:37:59 +01:00
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.
}
2019-03-01 23:08:50 +01:00
run "gui".