Advertisement
gravitowl

store.lua

Dec 10th, 2024 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | None | 0 0
  1. local STORE_URL = "QV6xpc1r";
  2. local args = { ... };
  3.  
  4. local function help()
  5.     print("Usage: pkgmanager <program_name>")
  6. end
  7.  
  8. local function loadStore()
  9.     local pastebin = "https://pastebin.com/raw/";
  10.     local response, error, fail = http.get(pastebin .. STORE_URL);
  11.  
  12.     if response == nil then
  13.         return nil, error, fail;
  14.     end
  15.  
  16.     local file = response.readAll();
  17.     response.close();
  18.  
  19.     print(file);
  20.  
  21.     local storeTable = textutils.unserialiseJSON(file);
  22.  
  23.     return storeTable
  24. end
  25.  
  26. local function downloadProgram(programName, store)
  27.     local program = store[programName];
  28.  
  29.     if not program then
  30.         print("Error: non-existant program '"..programName.."'.");
  31.         print("Valid options are:");
  32.  
  33.         for programName, _ in pairs(store) do
  34.             print("- " .. programName);
  35.    
  36.         end
  37.     end
  38.  
  39.     print("Installing program!");
  40. end
  41.  
  42. local function main()
  43.     if #args == 0 then
  44.         print("Error: No argument supplied. Please specify which program to install.");
  45.         help();
  46.         return;
  47.     end
  48.  
  49.     local storeTable, error, fail = loadStore();
  50.  
  51.     if not storeTable then
  52.         print(error);
  53.         return;
  54.     end
  55.  
  56.     downloadProgram(args[1], storeTable);
  57. end
  58.  
  59. main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement