Corbinhol

OpenComputers Gitlab API Library Installer

Dec 30th, 2024 (edited)
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.67 KB | None | 0 0
  1. --Installer for OpenComputers Gitlab API Library
  2. --For More Info See: https://gitlab.com/Corbinhol/opencomputers-gitlab-api-library
  3. if gitlab ~= nil then
  4.     io.write("It seems that the gitlab library is already loaded. Unloading...");
  5.     gitlab = nil;
  6.     if gitlab ~= nil then
  7.         io.write("Failed.\n");
  8.         os.exit();
  9.     end
  10.     io.write("Done.\n")
  11. end
  12.  
  13. local filesystem = require("filesystem");
  14. local internet = require("internet");
  15. local term = require("term");
  16.  
  17. function combine(handle)
  18.     local out = "";
  19.     for chunk in handle do out = out .. chunk end
  20.     return out;
  21. end
  22.  
  23. function download(url, dir)
  24.     local handle = internet.request(url);
  25.     local result, data = pcall(combine, handle);
  26.     if not result then
  27.         error("Failure to connect to " .. url);
  28.     end
  29.     local file = io.open(dir, "w");
  30.     file:write(data);
  31.     file:close();
  32.     return true;
  33. end
  34.  
  35. if not filesystem.exists("/usr/lib") then
  36.     io.write("User library folder does not seem to exist. Creating now...");
  37.     filesystem.makeDirectory("/usr/lib");
  38.     io.write("done.\n");
  39. end
  40. io.write("Beginning Installation of Gitlab API Library...\n");
  41. io.write("Downloading Gitlab Module...");
  42. download("https://gitlab.com/Corbinhol/opencomputers-gitlab-api-library/-/raw/main/gitlab.lua?ref_type=heads", "/usr/lib/gitlab.lua");
  43. io.write("done.\n");
  44. io.write("Downloading Base64 Dependency...");
  45. download("https://gitlab.com/Corbinhol/opencomputers-gitlab-api-library/-/raw/main/base64.lua?ref_type=heads", "/usr/lib/base64.lua");
  46. io.write("done.\n");
  47. io.write("Downloading JSON Dependency...");
  48. download("https://gitlab.com/Corbinhol/opencomputers-gitlab-api-library/-/raw/main/json.lua?ref_type=heads", "/usr/lib/json.lua");
  49. io.write("done.\n");
  50. if not filesystem.exists("/usr/bin") then
  51.     io.write("User bin folder does not seem to exist. Creating now...");
  52.     filesystem.makeDirectory("/usr/bin");
  53.     io.write("done.\n");
  54. end
  55. io.write("Downloading Gitlab Application...");
  56. download("https://gitlab.com/Corbinhol/opencomputers-gitlab-api-library/-/raw/main/Program/Gitlab.lua?ref_type=heads", "/usr/bin/gitlab.lua");
  57. io.write("done.\n");
  58. io.write("If you have an API Key you'd like to use, please enter it. If not, then just press enter. [Warning Key will be saved on computer.\nDo not use if you share this computer with others you do not trust!!]: ");
  59. local key = term.read({pwchar = "*", dobreak=false});
  60. local key = string.gsub(key, "\n", "");
  61. if key ~= "" then
  62.     io.write("\nSaving key...");
  63.     local gitlab = require("gitlab");
  64.     gitlab.save_key(key);
  65.     io.write("done.\n");
  66. else
  67.     io.write("\nSkipping Key.\n");
  68. end
  69. io.write("Instalation Complete!");
Add Comment
Please, Sign In to add comment