Advertisement
Guest User

test

a guest
Jun 20th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.40 KB | None | 0 0
  1. -- GCorp Package Manager
  2. -- /etc/gcpm/packages.db
  3.  
  4. -- Libary / Component Requirements
  5.  
  6. local file = require "filesystem"
  7. local serialization = require "serialization"
  8.  
  9. -- Package DB location
  10.  
  11. local package_list = "https://gitlab.com/amberkowalski/opencomputers-files/raw/master/package_list"
  12.  
  13. -- Package DB
  14.  
  15. local package_db = {}
  16. installed_packages = {}
  17.  
  18. -- Functions
  19.  
  20. local function download_file(file, file_path)
  21.   os.execute("cd " .. file_path .. " && wget " .. file)
  22. end
  23.  
  24. local function reload_packages()
  25.   local data = ""
  26.   for line in io.lines("/etc/.gcpm/package_list") do
  27.     data = data .. line
  28.   end
  29.   print(data)
  30.   local db = serialization.unserialize(data)
  31.   return db
  32. end
  33.  
  34.  
  35. -- Check for important files
  36.  
  37. if file.exists("/etc/.gcpm/packages.db") == false then
  38.   io.stderr:write("[WARN] No package DB exists or your installation is corrupt, creating a new one!\n")
  39.   if file.isDirectory("/etc/.gcpm") ~= true then
  40.     file.makeDirectory("/etc/.gcpm")
  41.     local db = file.open("/etc/.gcpm/packages.db", "w")
  42.     db:write("")
  43.     db:close()
  44.   else
  45.     local db = file.open("/etc/.gcpm/packages.db", "w")
  46.     db:write("")
  47.     db:close()
  48.   end
  49. end
  50. if file.exists("/etc/.gcpm/package_list") == false then
  51.   io.stderr:write("[WARN] Package list has not been synced, syncing now!\n")
  52.   download_file(package_list, "/etc/.gcpm")
  53. end
  54.  
  55. -- Read the packages.db and store in package_db
  56.  
  57. package_db = reload_packages()
  58.  
  59.  
  60. print(package_db)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement