Jameelo

Lua Package Installer

Nov 8th, 2023 (edited)
856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.71 KB | None | 0 0
  1. --[[
  2.     Package installer for the stuff I've made
  3.     It also has a progress bar!
  4. ]]
  5.  
  6. -------------------------Constant Declarations-------------------------
  7.  
  8. -- Common Utility Libraries
  9. local PACKAGES = {
  10.     -- APIs
  11.     ["common/systemLib.lua"] = "q4vfvQPk",
  12.     ["common/storageLib.lua"] = "SzD8A2sq",
  13.     ["common/mineLib.lua"] = "N0mkQCxV",
  14.     -- Programs
  15.     ["stairMiner.lua"] = "QHf8evLE",
  16.     ["quarry.lua"] = "aaNTTxMV",
  17.     ["elevator.lua"] = "5F9wdhrm",
  18.     ["platformBuilder.lua"] = "F0HQRDnX",
  19.     ["lavaRefuel.lua"] = "yCMci8qT",
  20. }
  21.  
  22. -- Generic command line strings
  23. local INSTALLSHELL = "pastebin get %s %s"
  24. local UNINSTALLSHELL = "delete %s"
  25.  
  26. local maxProgress, progressBar = 0, 0
  27. for _ in pairs(PACKAGES) do maxProgress = maxProgress + 1 end
  28.  
  29. local function printProgressBar(current, max)
  30.     local progress = current/max -- Normalised progress
  31.     local width,_,_ = term.getSize()
  32.     local progressPips, n = width - 2, 0
  33.  
  34.     term.clear()
  35.     io.write("[")
  36.     while n < progressPips do
  37.         if (n/progressPips) > progress then
  38.             io.write(".")
  39.         else
  40.             io.write("|")
  41.         end
  42.         n = n + 1
  43.     end
  44.     io.write("]")
  45.     print("")
  46. end
  47.  
  48. -------------------------Start Program-------------------------
  49.  
  50. -- Install required libraries, ensure they are done first
  51. for k,v in pairs(PACKAGES) do
  52.     printProgressBar(progressBar, maxProgress)
  53.     print("Current package: ", k)
  54.     print(" ")
  55.     if fs.exists(k) == true then
  56.         shell.run(string.format(UNINSTALLSHELL,k))
  57.     end
  58.     shell.run(string.format(INSTALLSHELL,v,k))
  59.     progressBar = progressBar + 1
  60. end
  61.  
  62. printProgressBar(maxProgress,maxProgress)
  63. print("Installation complete\n:3")
Advertisement
Add Comment
Please, Sign In to add comment