Last active
April 7, 2016 06:13
-
-
Save Gaiiden/4f16cfaaffbb27d4ecc327f722253360 to your computer and use it in GitHub Desktop.
Minimized version of kOS bootscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clearscreen. set dOF to 0.set bO to 0.set oL to shipname+".log.np2".log "" to oL. function DL{parameter aF,lF.if not addons:rt:haskscconnection(ship) return 0.if not archive:exists(aF) return 0.if exists(lF) set lFS to open(lF):size. else set lFS to 0.set aFS to archive:open(aF):size. if core:volume:freespace-aFS+lFS<0{if core:volume:freespace-aFS+lFS+open(oL):size>0{copy shipname+".log.backup.np2" to 0.delete(oL).print "deleting log to free up space".}else{print "unable to copy file "+aF+". Not enough disk space".return 0.}}copy aF from 0.archive:delete(aF).if lFS delete(lF).rename aF to lF. return 1.}if exists("backup.op.ks") and not addons:rt:haskscconnection(ship){delete operations. rename "backup.op.ks" to "operations.ks".print "KSC connection lost. Stored operations file loaded".}else{if not addons:rt:haskscconnection(ship){print "waiting for KSC link...".wait until addons:rt:haskscconnection(ship).}print "KSC link established, fetching operations...".wait addons:rt:kscdelay(ship).if DL(shipname+".boot.ks","boot.ks"){print "new boot file received".wait 2.reboot.}if DL(shipname+".op.ks","operations.ks") print "new operations file received".}set ship:control:pilotmainthrottle to 0.set lL to list().set lS to "["+time:calendar+"] boot up".log lS to oL. lL:add(lS).function OP{parameter tX,tC is 1.if tC print tX. set lS to "["+time:hour+":"+time:minute+":"+floor(time:second)+"] "+tX. if core:volume:freespace>lS:length{log lS to oL.}else{delete(oL).log "["+time:calendar+"] new file" to oL. log lS to oL.}if addons:rt:haskscconnection(ship){if not archive:exists(oL) archive:create(oL).if lL:length{for e in lL archive:open(oL):writeln(e).set lL to list().}archive:open(oL):writeln(lS).}else{if core:volume:freespace>lS:length{lL:add(lS).}else{delete(oL).lL:add("["+time:calendar+"] new file").lL:add(lS).}}}when addons:rt:haskscconnection(ship) and archive:exists(ship:name + ".bop.ks.") then{set bO to 1.if addons:rt:haskscconnection(ship) preserve.}if not exists("operations.ks") and addons:rt:haskscconnection(ship){print "waiting to receive operations...".until DL(shipname+".op.ks.","operations.ks"){if not addons:rt:haskscconnection(ship){if not exists("backup.op.ks"){print "KSC connection lost, awaiting connection...".wait until addons:rt:haskscconnection(ship).reboot.}else{if exists("operations.ks") delete operations. rename "backup.op.ks" to "operations.ks".print "KSC connection lost. Stored operations file loaded".break.}}wait 1.}}OP("executing operations").wait 2.run operations. if dOF delete operations. OP("operations execution complete").wait 2.reboot. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For use by executing programs:
deleteOnFinish
is nowdOF
backupOps
is nowbO
download()
is nowDL()
output()
is nowOP()