pepeknamornik

Update service

May 2nd, 2020 (edited)
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.37 KB | None | 0 0
  1. verze = "20.0829.R1"
  2.  
  3.     if fs.exists("/C/system/server/rules/AD/period.cfg") then
  4.         local data = fs.open("/C/system/server/rules/AD/period.cfg", "r")
  5.         updatetime = data.readLine()
  6.         data.close()
  7.     else
  8.         updatetime = 3600
  9.     end
  10.  
  11. print("Aktualizacni server, obnova po: "..updatetime.." sek.")
  12.  
  13. local function download( pasteid, filepath ) --#more descriptive variable names
  14.   local handle = http.get( "https://www.pastebin.com/raw/" .. pasteid ) --#sometimes CC has problems with https
  15.   if handle then --#if the request succeeded
  16.     local file = fs.open( filepath, "w" )
  17.     file.write( handle.readAll() )
  18.     file.close()
  19.     handle.close() --#always close web handles!
  20.     bar("OK", "Aktualizace uspesna")
  21.     return true --#we succeeded, return true
  22.   end
  23.   bar("FAIL", "aktualizace neuspesna")
  24.   return false --#it didn't work, return false
  25. end
  26.  
  27. function bar(styl, text)
  28.     if (styl == "OK") then                  -- Uspech
  29.         term.setTextColor(colors.green)
  30.     elseif (styl == "FAIL") then            -- Neuspesne
  31.         term.setTextColor(colors.red)
  32.     elseif (styl == "INFO") then            -- Informativni
  33.         term.setTextColor(colors.lightBlue)
  34.     elseif (styl == "def") then             -- defaultni
  35.         term.setTextColor(colors.white)
  36.     elseif (styl == "PRO") then             -- Progress
  37.         term.setTextColor(colors.yellow)
  38.     else
  39.         styl = "def"
  40.         term.setTextColor(colors.white)
  41.     end
  42.    
  43.     if not (styl == "def") then
  44.         zprava = ("["..textutils.formatTime(os.time(), true).."] ["..styl.."] "..text)
  45.         else
  46.         zprava = text
  47.     end
  48.  
  49.     print (zprava)
  50. end
  51.  
  52. function update()
  53.     bar("PRO", "Probiha aktualizace desktop.lua")
  54.     if fs.exists ("/C/system/server/rules/Update/desktop.lua") then fs.delete ("/C/system/server/rules/Update/desktop.lua") end
  55.     download("HyhMtGvd", "/C/system/server/rules/Update/desktop.lua")
  56.     bar("PRO", "Probiha aktualizace startup.lua")
  57.     if fs.exists ("/C/system/server/rules/Update/startup.lua") then fs.delete ("/C/system/server/rules/Update/startup.lua") end
  58.     download("0xh6jEx1", "/C/system/server/rules/Update/startup.lua")
  59.     bar("PRO", "Probiha aktualizace setting.lua")
  60.     if fs.exists ("/C/system/server/rules/Update/setting.lua") then fs.delete ("/C/system/server/rules/Update/setting.lua") end
  61.     download("vxJjQzem", "/C/system/server/rules/Update/setting.lua")
  62.     sleep(tonumber(updatetime))
  63.     update()
  64. end
  65.  
  66. update()
Add Comment
Please, Sign In to add comment