local a=require("io")local b=require("component")if not b.isAvailable("internet")then a.stderr.write("This program requires an internet card to run.")return end;local c=b.internet;local d=require("computer")local d=require("filesystem")local e=b.gpu;local f,g=e.getResolution()local h=require("event")local i=require("keyboard")local j;local k;local l={}local m={}for a in d.list("/mnt/")do local c=b.get(a:sub(1,3),"filesystem")if not b.invoke(c,"isReadOnly")then table.insert(l,a)table.insert(m,c)end end;local function n()e.setBackground(0)e.setForeground(16777215)e.fill(1,1,f,g," ")require("tty").setCursor(1,1)end;local function o()local a={}for c,d in ipairs(l)do local c=m[c]table.insert(a,b.invoke(c,"getLabel"))end;e.set(1,1,"Please select a drive to install Halyde to:")local b=1;local function c(b,c)if c then e.setBackground(16777215)e.setForeground(0)else e.setBackground(0)e.setForeground(16777215)end;e.fill(4,2+b,f-3,1," ")local a=a[b]or"No label"e.set(4,2+b,a)e.set(4+#a+1,2+b,m[b]:sub(1,5).."...")end;local function a(a)local a=math.max(math.min(b+a,#l),1)if b==a then return end;c(a,true)c(b,false)b=a end;e.fill(2,3,1,#l,"*")for a=1,#l do c(a,b==a)end;while true do local b={h.pull("key_down")}if not b or not b[1]or not b[4]then goto continue end;local b=i.keys[b[4]]if b=="up"then a(-1)elseif b=="down"then a(1)elseif b=="right"or b=="enter"then e.setBackground(0)e.setForeground(16777215)e.fill(1,1,f,g-1," ")break elseif b=="left"or b=="back"then return false end::continue::end;j="/mnt/"..l[b]k=m[b]return true end;if#l==0 then a.stderr.write("All drives are read-only.\nHalyde cannot be installed.")elseif#l==1 then j="/mnt/"..l[1]k=m[1]end;e.fill(1,1,f,g," ")e.setBackground(16777215)e.setForeground(0)e.fill(1,g,f,1," ")e.set(1,g,"Halyde Web Installer (OpenOS)")e.setBackground(0)e.setForeground(16777215)if#l>1 then if not o()then n()return end end;if not j then n()a.stderr.write("All drives are read-only.\nHalyde cannot be installed.")return end;if f<80 then e.set(1,1,"Are you sure you would like to install Halyde?")else e.set(1,1,"Are you sure you would like to install Halyde to "..j.."?")end;e.set(1,2,"This will erase all data on this disk.")e.set(1,g-1,"Press Y to accept, or N to cancel.")e.set(3,4,"Capacity: ")e.set(3,5,"Used: ")e.set(3,6,"ID: ")e.set(3,7,"Label: ")e.setForeground(65280)if f>=80 then e.set(50,1,j)end;e.set(13,4,math.floor(b.invoke(k,"spaceTotal")/1024).." KiB")e.set(9,5,math.floor(b.invoke(k,"spaceUsed")/1024).." KiB")e.set(7,6,k)e.set(10,7,b.invoke(k,"getLabel")or"No label")if i.keys[({h.pull("key_down")})[4]]=="n"then return n()end;local a=require("computer")local function h(a)local b,d,e=nil,"",nil;local a,c=pcall(function()b=c.request(a)b:finishConnect()end)if not a then return false,c end;local a=b:response()if a and a~=200 then return false,a end;repeat e=b.read(math.huge)d=d..(e or"")until not e;return d end;local c;local i={"halyde","edit","argentum","webinstall-extras"}e.setBackground(0)e.setForeground(16777215)e.fill(1,1,f,g," ")local function k(a,b,c)a=tostring(a)if c==nil then c=' 'end;return string.rep(c,b-#a)..a end;local function l(a,b)local d=0;if c and type(c)=="table"then for a,a in ipairs(i)do local a=c[a]d=d+#(a.directories or{})+#(a.files or{})end else d=1 end;local h=""local j=1;if type(a)=="string"then j=b;h=string.format("%s %s%%",a,k(math.floor(b*100),2))else j=0;for d=1,a do local c=c[i[d]]if d==a then j=j+b else local a=#(c.directories or{})+#c.files;j=j+a end end;j=j/d;local c=c[i[a]]b=b/(#(c.directories or{})+#c.files)local a=i[a].." "..k(math.floor(b*100),2).."%"h=string.format("%s%% [%s]",k(math.floor(j*100),2),a)end;h=h..string.rep(" ",f-#h)local a=math.floor(j*f)e.setBackground(65280)e.setForeground(0)e.set(1,g,h:sub(1,a))e.setBackground(0)e.setForeground(16777215)e.set(a+1,g,h:sub(a+1))end;local k=1;local function m(a)if k>=g then e.copy(1,2,f,g-2,0,-1)e.fill(1,g-1,f,1," ")k=k-1 end;e.set(1,k,a)k=k+1 end;m("Fetching Argentum configuration for Halyde")l("Preparing",0)c=h("https://raw.githubusercontent.com/Team-Cerulean-Blue/Halyde/refs/heads/main/argentum.cfg")m("Loading Argentum configuration")l("Preparing",0.5)c=load(c)c=c()m("Looking for outdated files in the drive")l("Preparing",1)local k={}for a in d.list(j)do local b=false;for d=1,3 do for c,c in pairs(c[i[d]].files)do if a==c then b=true end end;if c[i[d]].directories then for c,c in pairs(c[i[d]].directories)do if a==c.."/"then b=true end end end end;if a=="halyde/"then b=true end;if not b then table.insert(k,a)end end;m("Found "..#k)l(1,0)for a=1,4 do local b=c[i[a]]local c=0;if b.directories then c=#b.directories;for b,c in ipairs(b.directories)do m("Creating "..c.."...")l(a,b-1)d.makeDirectory(j..c)end end;for b,e in ipairs(b.files)do m("Downloading "..e.."...")l(a,b-1+c)local a=d.open(j..e,"w")a:write(h("https://raw.githubusercontent.com/Team-Cerulean-Blue/Halyde/refs/heads/main/"..e))a:close()end end;for a,b in ipairs(k)do m("Removing "..b)l("Finishing up",(a-1)/#k*1)d.remove(j..b)end;m("Setting boot address")l("Finishing up",1)a.setBootAddress(b.get(j:sub(6,-2)))m("Setting label to Halyde")b.invoke(b.get(j:sub(6,-2)),"setLabel","Halyde")e.fill(1,1,f,g," ")a.shutdown(true)