os.loadAPI("/System/API/windows")
os.loadAPI("/System/API/sysbar")
local run = true
local xSize, ySize = term.getSize()
local xCenter = math.floor(xSize/2)
local yCenter = math.floor(ySize/2)
local obj = {}
local arg = {...}
local cursor = 3 
local check = -4
local draw = true

local clear = function(color)
 term.setBackgroundColor(color)
 term.clear()
 term.setCursorPos(1,1)
end
 
local text = function(string,xPos,yPos)
 term.setCursorPos(xPos,yPos)
 term.write(string)
end

local pastebin = function(paste,filename)
 local file = http.get("https://pastebin.com/raw/"..paste)
 if file then
  file = file.readAll()
  h=fs.open(filename,"w")
  h.write(file)
  h.close()
 else
  windows.error("Unable to connect to the Internet")
 end
end

local sysBar = function()
	while true do
		if draw then
			sysbar.header(" < Update",mainTextCol,mainColor)
			sysbar.draw(colors.white,colors.black,noty,true,false)
		end
		sleep(1)
	end
end

local redraw = function()
 clear(colors.white)
 term.setTextColor(colors.black)
 text("Your OS version:",2,6)
 text("Last OS version:",2,4)
 if version == lastVer then
  term.setTextColor(colors.lime)
 elseif version < lastVer then
  term.setTextColor(colors.red)
 elseif version > lastVer then
  term.setTextColor(colors.lightBlue)
 end
 text(version,xSize-#version,6)
 term.setTextColor(colors.lime)
 text(lastVer,xSize-#lastVer,4)
 term.setTextColor(colors.white)
 term.setBackgroundColor(colors.lime)
 text(" Update ",xCenter-3,ySize-3)
end
 

local running = function()
 while run == true and l_login ~= '...' and l_login ~= nil and l_login ~= '' and l_login ~= '$test' do
  event, side, x, y = os.pullEvent()
  if event == "mouse_click" then
   draw = false
   if sysbar.back(x,y) or y==1 then
    term.clear()
    term.setCursorPos(1,1)
    run = false
   elseif sysbar.home(x,y) then
    home = true
    term.clear()
    term.setCursorPos(1,1)
    run = false
   elseif y==ySize-3 then
    clear(colors.white)
    pastebin("GSn51ZQM","/System/prog/up")
    shell.run("/System/prog/up")
   end
   draw = true
  end
 end
end

pastebin("AH3k8DMa","/ver")
shell.run("/ver")
if l_login ~= '...' and l_login ~= nil and l_login ~= '' then
	redraw()
	parallel.waitForAny(sysBar,running)
end
