BrainStone

API Installer

Dec 25th, 2015
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.95 KB | None | 0 0
  1. -- BrainStone's APIs autoupdater installer
  2. -- Version 1.12
  3. --
  4. -- This script will install BrainStone's APIs autoupdater
  5. --
  6. -- Execute " pastebin run V2uDhBFU " to install or update if already installed
  7. -- Execute " pastebin run V2uDhBFU update " to force update
  8.  
  9. function getLastLine(file)
  10.   if not fs.exists(file) then
  11.     return nil
  12.   end
  13.  
  14.   local handle = fs.open(file, "r")
  15.  
  16.   local line, lastline
  17.  
  18.   repeat
  19.     lastline = line
  20.     line = handle.readLine()
  21.   until line == nil
  22.  
  23.   return lastline
  24. end
  25.  
  26. local targs = {...}
  27. local mode = targs[1] or "install"
  28. local useColor = term.isColor ~= nil and term.isColor()
  29.  
  30. if fs.exists("startup") then
  31.   if mode ~= "update" and getLastLine("startup") == "-- 4024a1f38967b6f8d01e32a34688b43a" then
  32.     mode = "update"
  33.   end
  34.  
  35.   if mode == "install" then
  36.     if fs.exists("startup.custom") then
  37.       if useColor then
  38.         term.setTextColor(colors.red)
  39.       end
  40.      
  41.       print("Warning! \"startup\" and \"startup.custom\" already exsist!")
  42.       print("If you install now \"startup.custom\" will be deleted!")
  43.      
  44.       if useColor then
  45.         term.setTextColor(colors.white)
  46.       end
  47.      
  48.       local text
  49.      
  50.       repeat
  51.         write("Would you rather like to update instead? (y/n) ")
  52.        
  53.         text = read():sub(1, 1)
  54.       until text == "y" or text == "n"
  55.      
  56.       if text == "n" then
  57.         fs.delete("startup.custom")
  58.         fs.move("startup", "startup.custom")
  59.       else
  60.         mode = "update"
  61.       end
  62.     else
  63.       fs.move("startup", "startup.custom")
  64.     end
  65.   end
  66.  
  67.   fs.delete("startup")
  68. end
  69.  
  70. if useColor then
  71.   term.setTextColor(colors.lime)
  72. end
  73.  
  74. if mode == "install" then
  75.   write("Installing")
  76. elseif mode == "update" then
  77.   write("Updating")
  78. end
  79.  
  80. if useColor then
  81.   term.setTextColor(colors.white)
  82. end
  83.  
  84. print(" BrainStone's APIs autoupdater")
  85.  
  86. shell.run("pastebin get mEYD0JM5 startup")
  87. shell.run("startup")
Advertisement
Add Comment
Please, Sign In to add comment