Skip to content

Commit f2e872d

Browse files
authored
miniOS chainloader tool
1 parent 3b21a8a commit f2e872d

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

miniOS/chain.lua

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
local targs = {...}
2+
local opt = table.remove(targs, 1)
3+
4+
if opt == "get" then print(fs.drive.toLetter(computer.getBootAddress()) .. ":"); return end
5+
6+
local td, tf = fs.drive.drivepathSplit(table.remove(targs, 1) or "")
7+
if #targs == 0 then targs = nil end
8+
local ta = fs.drive.toAddress(td)
9+
10+
if opt == "set" then computer.setBootAddress(ta); return end
11+
12+
if tf == "" then tf = "init.lua" end
13+
14+
local oldgetboot = computer.getBootAddress
15+
local fakeget = function() return ta end
16+
local oldsetboot = computer.setBootAddress
17+
local fakeset = function(addr) ta = addr end
18+
computer.getBootAddress = fakeget
19+
20+
if opt == "tmp" then computer.setBootAddress = fakeset
21+
elseif opt == "nex" then computer.setBootAddress = function(...) fakeset(...); oldsetboot(...) end
22+
else
23+
printErr("Unexpected option `" .. (opt or "") .. "`")
24+
print([[
25+
26+
Usage:
27+
chain <option> <path>
28+
29+
Options:
30+
get - get boot drive
31+
set - set boot drive from path
32+
tmp - start OS from path, blocks set
33+
nex - start OS from path, allows set
34+
35+
Warning!
36+
If the OS returns then REBOOT!
37+
miniOS will probably be broken.]])
38+
return
39+
end
40+
41+
term.clear()
42+
error({[1]="INTERRUPT", [2]="RUN", [3]=(td .. ":" .. tf), [4]=targs or {}})
43+
44+
error("INTERRUPT failiure.")

0 commit comments

Comments
 (0)