|
@ -21,8 +21,10 @@ if not component.isAvailable("internet") then |
|
|
end |
|
|
end |
|
|
local internet = require("internet") |
|
|
local internet = require("internet") |
|
|
|
|
|
|
|
|
--local repoLocationConfig="https://raw.githubusercontent.com/OpenPrograms/openprograms.github.io/master/repos.cfg" |
|
|
|
|
|
local repoLocationConfig = "https://sothr.com/download/oc/release/repos.cfg" |
|
|
|
|
|
|
|
|
local githubContentRoot = "https://raw.githubusercontent.com/" |
|
|
|
|
|
local repoLocationConfig = "{URL_BASE}/repos.cfg" |
|
|
|
|
|
local localInstalledPackagesFile = "/etc/spdata.svd" |
|
|
|
|
|
local localConfigFile = "/etc/spm.cfg" |
|
|
|
|
|
|
|
|
local args, options = shell.parse(...) |
|
|
local args, options = shell.parse(...) |
|
|
|
|
|
|
|
@ -34,48 +36,54 @@ local function printUsage() |
|
|
print("'spm list [-i] <filter>' to get a list of available packages containing the specified substring") |
|
|
print("'spm list [-i] <filter>' to get a list of available packages containing the specified substring") |
|
|
print(" -i: Only list already installed packages") |
|
|
print(" -i: Only list already installed packages") |
|
|
print("'spm info <package>' to get further information about a program package") |
|
|
print("'spm info <package>' to get further information about a program package") |
|
|
print("'spm install [-f] <package> [path]' to download a package to a directory on your system (or /usr by default)") |
|
|
|
|
|
|
|
|
print("'spm install [-f] [-m] <package> [path]' to download a package to a directory on your system (or /usr by default)") |
|
|
print("'spm update <package>' to update an already installed package") |
|
|
print("'spm update <package>' to update an already installed package") |
|
|
print("'spm update all' to update every already installed package") |
|
|
print("'spm update all' to update every already installed package") |
|
|
print("'spm uninstall <package>' to remove a package from your system") |
|
|
print("'spm uninstall <package>' to remove a package from your system") |
|
|
print(" -f: Force creation of directories and overwriting of existing files.") |
|
|
print(" -f: Force creation of directories and overwriting of existing files.") |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
-- Make an internet http/s request for data |
|
|
local function getContent(url) |
|
|
local function getContent(url) |
|
|
local sContent = "" |
|
|
local sContent = "" |
|
|
local result, response = pcall(internet.request, url) |
|
|
local result, response = pcall(internet.request, url) |
|
|
|
|
|
|
|
|
if not result then |
|
|
if not result then |
|
|
return nil |
|
|
return nil |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
for chunk in response do |
|
|
for chunk in response do |
|
|
sContent = sContent .. chunk |
|
|
sContent = sContent .. chunk |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
return sContent |
|
|
return sContent |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
-- Request repository information |
|
|
local function getRepos() |
|
|
local function getRepos() |
|
|
local success, sRepos = pcall(getContent, repoLocationConfig) |
|
|
local success, sRepos = pcall(getContent, repoLocationConfig) |
|
|
|
|
|
|
|
|
if not success then |
|
|
if not success then |
|
|
io.stderr:write("Could not connect to the Internet. Please ensure you have an Internet connection.") |
|
|
io.stderr:write("Could not connect to the Internet. Please ensure you have an Internet connection.") |
|
|
return -1 |
|
|
return -1 |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
return serial.unserialize(sRepos) |
|
|
return serial.unserialize(sRepos) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
-- Get Packages for src |
|
|
local function getPackages(src) |
|
|
local function getPackages(src) |
|
|
local success, sPackages = pcall(getContent, src .. "/programs.cfg") |
|
|
local success, sPackages = pcall(getContent, src .. "/programs.cfg") |
|
|
|
|
|
|
|
|
if not success or not sPackages then |
|
|
if not success or not sPackages then |
|
|
return -1 |
|
|
return -1 |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
return serial.unserialize(sPackages) |
|
|
return serial.unserialize(sPackages) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
local function getGithubPackages(repo) |
|
|
local function getGithubPackages(repo) |
|
|
local success, sPackages = pcall(getContent, "https://raw.githubusercontent.com/" .. repo .. "/master/programs.cfg") |
|
|
|
|
|
if not success or not sPackages then |
|
|
|
|
|
return -1 |
|
|
|
|
|
end |
|
|
|
|
|
return serial.unserialize(sPackages) |
|
|
|
|
|
|
|
|
return getPackages(githubContentRoot .. repo .. "/master") |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
--For sorting table values by alphabet |
|
|
--For sorting table values by alphabet |
|
@ -85,6 +93,7 @@ local function compare(a, b) |
|
|
return a:sub(i, i) < b:sub(i, i) |
|
|
return a:sub(i, i) < b:sub(i, i) |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
return #a < #b |
|
|
return #a < #b |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
@ -96,127 +105,134 @@ local function downloadFile(url, path, force) |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
local function readFromFile(fNum) |
|
|
|
|
|
local path |
|
|
|
|
|
if fNum == 1 then |
|
|
|
|
|
path = "/etc/spdata.svd" |
|
|
|
|
|
elseif fNum == 2 then |
|
|
|
|
|
path = "/etc/spm.cfg" |
|
|
|
|
|
if not fs.exists(path) then |
|
|
|
|
|
local tProcess = process.running() |
|
|
|
|
|
path = fs.concat(fs.path(shell.resolve(tProcess)), "/etc/spm.cfg") |
|
|
|
|
|
end |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
local function readFromFile(path) |
|
|
if not fs.exists(fs.path(path)) then |
|
|
if not fs.exists(fs.path(path)) then |
|
|
fs.makeDirectory(fs.path(path)) |
|
|
fs.makeDirectory(fs.path(path)) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
if not fs.exists(path) then |
|
|
if not fs.exists(path) then |
|
|
return { -1 } |
|
|
return { -1 } |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
local file, msg = io.open(path, "rb") |
|
|
local file, msg = io.open(path, "rb") |
|
|
if not file then |
|
|
if not file then |
|
|
io.stderr:write("Error while trying to read file at " .. path .. ": " .. msg) |
|
|
io.stderr:write("Error while trying to read file at " .. path .. ": " .. msg) |
|
|
return |
|
|
return |
|
|
end |
|
|
end |
|
|
local sPacks = file:read("*a") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local serializedTableData = file:read("*a") |
|
|
file:close() |
|
|
file:close() |
|
|
return serial.unserialize(sPacks) or { -1 } |
|
|
|
|
|
|
|
|
return serial.unserialize(serializedTableData) or { -1 } |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
local function saveToFile(tPacks) |
|
|
|
|
|
local file, msg = io.open("/etc/spdata.svd", "wb") |
|
|
|
|
|
|
|
|
local function readFromLocalInstallFile() |
|
|
|
|
|
readFromFile(localInstalledPackagesFile) |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
local function readLocalConfigFile() |
|
|
|
|
|
local path = localConfigFile |
|
|
|
|
|
if not fs.exists(path) then |
|
|
|
|
|
return { -1 } |
|
|
|
|
|
else |
|
|
|
|
|
return readFromFile(path) |
|
|
|
|
|
end |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
local function saveToInstalledPackagesFile(installedPackages) |
|
|
|
|
|
|
|
|
|
|
|
local file, msg = io.open(localInstalledPackagesFile, "wb") |
|
|
|
|
|
|
|
|
if not file then |
|
|
if not file then |
|
|
io.stderr:write("Error while trying to save package names: " .. msg) |
|
|
io.stderr:write("Error while trying to save package names: " .. msg) |
|
|
return |
|
|
return |
|
|
end |
|
|
end |
|
|
local sPacks = serial.serialize(tPacks) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local sPacks = serial.serialize(installedPackages) |
|
|
file:write(sPacks) |
|
|
file:write(sPacks) |
|
|
file:close() |
|
|
file:close() |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
local function listPackages(filter) |
|
|
local function listPackages(filter) |
|
|
filter = filter or false |
|
|
filter = filter or false |
|
|
|
|
|
|
|
|
if filter then |
|
|
if filter then |
|
|
filter = string.lower(filter) |
|
|
filter = string.lower(filter) |
|
|
end |
|
|
end |
|
|
local packages = {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local packageTable = {} |
|
|
print("Receiving Package list...") |
|
|
print("Receiving Package list...") |
|
|
if not options.i then |
|
|
if not options.i then |
|
|
local success, repos = pcall(getRepos) |
|
|
|
|
|
if not success or repos == -1 then |
|
|
|
|
|
|
|
|
local success, repositories = pcall(getRepos) |
|
|
|
|
|
|
|
|
|
|
|
if not success or repositories == -1 then |
|
|
io.stderr:write("Unable to connect to the Internet.\n") |
|
|
io.stderr:write("Unable to connect to the Internet.\n") |
|
|
return |
|
|
return |
|
|
elseif repos == nil then |
|
|
|
|
|
|
|
|
elseif repositories == nil then |
|
|
print("Error while trying to receive repository list") |
|
|
print("Error while trying to receive repository list") |
|
|
return |
|
|
return |
|
|
end |
|
|
end |
|
|
for _, j in pairs(repos) do |
|
|
|
|
|
local lPacks |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, repository in pairs(repositories) do |
|
|
|
|
|
local packages |
|
|
local target |
|
|
local target |
|
|
if j.src then |
|
|
|
|
|
print("Checking Repository " .. j.src) |
|
|
|
|
|
lPacks = getPackages(j.src) |
|
|
|
|
|
target = j.src |
|
|
|
|
|
elseif j.repo then |
|
|
|
|
|
print("Checking Repository " .. j.repo) |
|
|
|
|
|
lPacks = getGithubPackages(j.repo) |
|
|
|
|
|
target = j.repo |
|
|
|
|
|
end |
|
|
|
|
|
if lPacks == nil then |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if repository.src then |
|
|
|
|
|
print("Checking Repository " .. repository.src) |
|
|
|
|
|
packages = getPackages(repository.src) |
|
|
|
|
|
target = repository.src |
|
|
|
|
|
elseif repository.repo then |
|
|
|
|
|
print("Checking Repository " .. repository.repo) |
|
|
|
|
|
packages = getGithubPackages(repository.repo) |
|
|
|
|
|
target = repository.repo |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
if packages == nil then |
|
|
io.stderr:write("Error while trying to receive package list for " .. target .. "\n") |
|
|
io.stderr:write("Error while trying to receive package list for " .. target .. "\n") |
|
|
return |
|
|
return |
|
|
elseif type(lPacks) == "table" then |
|
|
|
|
|
for k in pairs(lPacks) do |
|
|
|
|
|
if not k.hidden then |
|
|
|
|
|
table.insert(packages, k) |
|
|
|
|
|
end |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
elseif type(packages) == "table" then |
|
|
|
|
|
for package in pairs(packages) do |
|
|
|
|
|
if not package.hidden then |
|
|
|
|
|
table.insert(packageTable, package) |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
--[[ |
|
|
|
|
|
local lRepos = readFromFile(2) |
|
|
|
|
|
if lRepos then |
|
|
|
|
|
for _, j in pairs(lRepos.repos) do |
|
|
|
|
|
for k in pairs(j) do |
|
|
|
|
|
if not k.hidden then |
|
|
|
|
|
table.insert(packages, k) |
|
|
|
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
end |
|
|
|
|
|
]] |
|
|
|
|
|
else |
|
|
else |
|
|
local lPacks = {} |
|
|
|
|
|
local tPacks = readFromFile(1) |
|
|
|
|
|
for i in pairs(tPacks) do |
|
|
|
|
|
table.insert(lPacks, i) |
|
|
|
|
|
|
|
|
local localPackageTable = {} |
|
|
|
|
|
local localPackages = readFromLocalInstallFile() |
|
|
|
|
|
for localPackage in pairs(localPackages) do |
|
|
|
|
|
table.insert(localPackageTable, localPackage) |
|
|
end |
|
|
end |
|
|
packages = lPacks |
|
|
|
|
|
|
|
|
packageTable = localPackageTable |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
if filter then |
|
|
if filter then |
|
|
local lPacks = {} |
|
|
|
|
|
for i, j in ipairs(packages) do |
|
|
|
|
|
if (#j >= #filter) and string.find(j, filter, 1, true) ~= nil then |
|
|
|
|
|
table.insert(lPacks, j) |
|
|
|
|
|
|
|
|
local packages = {} |
|
|
|
|
|
for _, package in ipairs(packageTable) do |
|
|
|
|
|
if (#package >= #filter) and string.find(package, filter, 1, true) ~= nil then |
|
|
|
|
|
table.insert(packages, package) |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
packages = lPacks |
|
|
|
|
|
|
|
|
packageTable = packages |
|
|
end |
|
|
end |
|
|
table.sort(packages, compare) |
|
|
|
|
|
return packages |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
table.sort(packageTable, compare) |
|
|
|
|
|
return packageTable |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
local function printPackages(tPacks) |
|
|
|
|
|
if tPacks == nil or not tPacks[1] then |
|
|
|
|
|
|
|
|
local function printPackages(packages) |
|
|
|
|
|
|
|
|
|
|
|
if packages == nil or not packages[1] then |
|
|
print("No package matching specified filter found.") |
|
|
print("No package matching specified filter found.") |
|
|
return |
|
|
return |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
term.clear() |
|
|
term.clear() |
|
|
local xRes, yRes = gpu.getResolution() |
|
|
local xRes, yRes = gpu.getResolution() |
|
|
print("--SPM {ENV} Package list--") |
|
|
print("--SPM {ENV} Package list--") |
|
|
local xCur, yCur = term.getCursor() |
|
|
local xCur, yCur = term.getCursor() |
|
|
for _, j in ipairs(tPacks) do |
|
|
|
|
|
term.write(j .. "\n") |
|
|
|
|
|
|
|
|
for _, package in ipairs(packages) do |
|
|
|
|
|
term.write(package .. "\n") |
|
|
yCur = yCur + 1 |
|
|
yCur = yCur + 1 |
|
|
if yCur > yRes - 1 then |
|
|
if yCur > yRes - 1 then |
|
|
term.write("[Press any key to continue]") |
|
|
term.write("[Press any key to continue]") |
|
@ -230,44 +246,36 @@ local function printPackages(tPacks) |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
local function getInformation(pack) |
|
|
|
|
|
local success, repos = pcall(getRepos) |
|
|
|
|
|
if not success or repos == -1 then |
|
|
|
|
|
|
|
|
local function getInformation(requestedPackage) |
|
|
|
|
|
local success, repositories = pcall(getRepos) |
|
|
|
|
|
|
|
|
|
|
|
if not success or repositories == -1 then |
|
|
io.stderr:write("Unable to connect to the Internet.\n") |
|
|
io.stderr:write("Unable to connect to the Internet.\n") |
|
|
return |
|
|
return |
|
|
end |
|
|
end |
|
|
for _, j in pairs(repos) do |
|
|
|
|
|
local lPacks |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, repository in pairs(repositories) do |
|
|
|
|
|
local packages |
|
|
local target |
|
|
local target |
|
|
if j.src then |
|
|
|
|
|
lPacks = getPackages(j.src) |
|
|
|
|
|
target = j.src |
|
|
|
|
|
elseif j.repo then |
|
|
|
|
|
lPacks = getGithubPackages(j.repo) |
|
|
|
|
|
target = "https://raw.githubusercontent.com/" .. j.repo |
|
|
|
|
|
end |
|
|
|
|
|
if lPacks == nil then |
|
|
|
|
|
io.stderr:write("Error while trying to receive package list for " .. target .. "\n") |
|
|
|
|
|
elseif type(lPacks) == "table" then |
|
|
|
|
|
for k in pairs(lPacks) do |
|
|
|
|
|
if k == pack then |
|
|
|
|
|
return lPacks[k], target |
|
|
|
|
|
end |
|
|
|
|
|
end |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if repository.src then |
|
|
|
|
|
packages = getPackages(repository.src) |
|
|
|
|
|
target = repository.src |
|
|
|
|
|
elseif repository.repo then |
|
|
|
|
|
packages = getGithubPackages(repository.repo) |
|
|
|
|
|
target = githubContentRoot .. repository.repo |
|
|
end |
|
|
end |
|
|
--[[ |
|
|
|
|
|
local lRepos = readFromFile(2) |
|
|
|
|
|
if lRepos then |
|
|
|
|
|
for i, j in pairs(lRepos.repos) do |
|
|
|
|
|
for k in pairs(j) do |
|
|
|
|
|
if k == pack then |
|
|
|
|
|
return j[k], i |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if packages == nil then |
|
|
|
|
|
io.stderr:write("Error while trying to receive package list for " .. target .. "\n") |
|
|
|
|
|
elseif type(packages) == "table" then |
|
|
|
|
|
for package in pairs(packages) do |
|
|
|
|
|
if package == requestedPackage then |
|
|
|
|
|
return packages[package], target |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
]] |
|
|
|
|
|
return nil |
|
|
return nil |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
@ -276,196 +284,230 @@ local function provideInfo(pack) |
|
|
printUsage() |
|
|
printUsage() |
|
|
return |
|
|
return |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
pack = string.lower(pack) |
|
|
pack = string.lower(pack) |
|
|
local info = getInformation(pack) |
|
|
local info = getInformation(pack) |
|
|
if not info then |
|
|
if not info then |
|
|
print("Package does not exist") |
|
|
print("Package does not exist") |
|
|
return |
|
|
return |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
local done = false |
|
|
local done = false |
|
|
print("--Information about package '" .. pack .. "'--") |
|
|
print("--Information about package '" .. pack .. "'--") |
|
|
if info.name then |
|
|
if info.name then |
|
|
print("Name: " .. info.name) |
|
|
print("Name: " .. info.name) |
|
|
done = true |
|
|
done = true |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
if info.version then |
|
|
|
|
|
print("Version: " .. info.version) |
|
|
|
|
|
done = true |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
if info.description then |
|
|
if info.description then |
|
|
print("Description: " .. info.description) |
|
|
print("Description: " .. info.description) |
|
|
done = true |
|
|
done = true |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
if info.authors then |
|
|
if info.authors then |
|
|
print("Authors: " .. info.authors) |
|
|
print("Authors: " .. info.authors) |
|
|
done = true |
|
|
done = true |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
if info.note then |
|
|
if info.note then |
|
|
print("Note: " .. info.note) |
|
|
print("Note: " .. info.note) |
|
|
done = true |
|
|
done = true |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
if not done then |
|
|
if not done then |
|
|
print("No information provided.") |
|
|
print("No information provided.") |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
local function installPackage(pack, path, update) |
|
|
|
|
|
update = update or false |
|
|
|
|
|
if not pack then |
|
|
|
|
|
|
|
|
local function installPackage(requestedPackage, installPath, doUpdate) |
|
|
|
|
|
doUpdate = doUpdate or false |
|
|
|
|
|
|
|
|
|
|
|
if not requestedPackage then |
|
|
printUsage() |
|
|
printUsage() |
|
|
return |
|
|
return |
|
|
end |
|
|
end |
|
|
if not path and not update then |
|
|
|
|
|
local lConfig = readFromFile(2) |
|
|
|
|
|
path = lConfig.path or "/usr" |
|
|
|
|
|
print("Installing package to " .. path .. "...") |
|
|
|
|
|
elseif not update then |
|
|
|
|
|
path = shell.resolve(path) |
|
|
|
|
|
print("Installing package to " .. path .. "...") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not installPath and not doUpdate then |
|
|
|
|
|
local localConfig = readLocalConfigFile() |
|
|
|
|
|
installPath = localConfig.path or "/usr" |
|
|
|
|
|
print("Installing package to " .. installPath .. "...") |
|
|
|
|
|
elseif not doUpdate then |
|
|
|
|
|
installPath = shell.resolve(installPath) |
|
|
|
|
|
print("Installing package to " .. installPath .. "...") |
|
|
end |
|
|
end |
|
|
pack = string.lower(pack) |
|
|
|
|
|
|
|
|
|
|
|
local tPacks = readFromFile(1) |
|
|
|
|
|
if not tPacks then |
|
|
|
|
|
|
|
|
requestedPackage = string.lower(requestedPackage) |
|
|
|
|
|
|
|
|
|
|
|
local locallyInstalledPackages = readFromLocalInstallFile() |
|
|
|
|
|
|
|
|
|
|
|
if not locallyInstalledPackages then |
|
|
io.stderr:write("Error while trying to read local package names") |
|
|
io.stderr:write("Error while trying to read local package names") |
|
|
return |
|
|
return |
|
|
elseif tPacks[1] == -1 then |
|
|
|
|
|
table.remove(tPacks, 1) |
|
|
|
|
|
|
|
|
elseif locallyInstalledPackages[1] == -1 then |
|
|
|
|
|
table.remove(locallyInstalledPackages, 1) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
local info, repo = getInformation(pack) |
|
|
|
|
|
if not info then |
|
|
|
|
|
|
|
|
local packageInfo, repositoryPath = getInformation(requestedPackage) |
|
|
|
|
|
if not packageInfo then |
|
|
print("Package does not exist") |
|
|
print("Package does not exist") |
|
|
return |
|
|
return |
|
|
end |
|
|
end |
|
|
if update then |
|
|
|
|
|
print("Updating package " .. pack) |
|
|
|
|
|
path = nil |
|
|
|
|
|
for i, j in pairs(info.files) do |
|
|
|
|
|
for k, v in pairs(tPacks[pack]) do |
|
|
|
|
|
if k == i then |
|
|
|
|
|
path = string.gsub(fs.path(v), j .. "/?$", "/") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if doUpdate then |
|
|
|
|
|
print("Updating package " .. requestedPackage) |
|
|
|
|
|
installPath = nil |
|
|
|
|
|
for filePath, fileInstallPath in pairs(packageInfo.files) do |
|
|
|
|
|
for installedFilePath, fileLocalInstallPath in pairs(locallyInstalledPackages[requestedPackage]) do |
|
|
|
|
|
if installedFilePath == filePath then |
|
|
|
|
|
installPath = string.gsub(fs.path(fileLocalInstallPath), fileInstallPath .. "/?$", "/") |
|
|
break |
|
|
break |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
if path then |
|
|
|
|
|
|
|
|
if installPath then |
|
|
break |
|
|
break |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
path = shell.resolve(string.gsub(path, "^/?", "/"), nil) |
|
|
|
|
|
|
|
|
installPath = shell.resolve(string.gsub(installPath, "^/?", "/"), nil) |
|
|
end |
|
|
end |
|
|
if not update and fs.exists(path) then |
|
|
|
|
|
if not fs.isDirectory(path) then |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not doUpdate and fs.exists(installPath) then |
|
|
|
|
|
if not fs.isDirectory(installPath) then |
|
|
if options.f then |
|
|
if options.f then |
|
|
path = fs.concat(fs.path(path), pack) |
|
|
|
|
|
fs.makeDirectory(path) |
|
|
|
|
|
|
|
|
installPath = fs.concat(fs.path(installPath), requestedPackage) |
|
|
|
|
|
fs.makeDirectory(installPath) |
|
|
else |
|
|
else |
|
|
print("Path points to a file, needs to be a directory.") |
|
|
print("Path points to a file, needs to be a directory.") |
|
|
return |
|
|
return |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
elseif not update then |
|
|
|
|
|
|
|
|
elseif not doUpdate then |
|
|
if options.f then |
|
|
if options.f then |
|
|
fs.makeDirectory(path) |
|
|
|
|
|
|
|
|
fs.makeDirectory(installPath) |
|
|
else |
|
|
else |
|
|
print("Directory does not exist.") |
|
|
print("Directory does not exist.") |
|
|
return |
|
|
return |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
if tPacks[pack] and (not update) then |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if locallyInstalledPackages[requestedPackage] and (not doUpdate) then |
|
|
print("Package has already been installed") |
|
|
print("Package has already been installed") |
|
|
return |
|
|
return |
|
|
elseif not tPacks[pack] and update then |
|
|
|
|
|
|
|
|
elseif not locallyInstalledPackages[requestedPackage] and doUpdate then |
|
|
print("Package has not been installed.") |
|
|
print("Package has not been installed.") |
|
|
print("If it has, uninstall it manually and reinstall it.") |
|
|
print("If it has, uninstall it manually and reinstall it.") |
|
|
return |
|
|
return |
|
|
end |
|
|
end |
|
|
if update then |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if doUpdate then |
|
|
term.write("Removing old files...") |
|
|
term.write("Removing old files...") |
|
|
for i, j in pairs(tPacks[pack]) do |
|
|
|
|
|
fs.remove(j) |
|
|
|
|
|
|
|
|
for installedFilePath, fileLocalInstallPath in pairs(locallyInstalledPackages[requestedPackage]) do |
|
|
|
|
|
fs.remove(fileLocalInstallPath) |
|
|
end |
|
|
end |
|
|
term.write("Done.\n") |
|
|
term.write("Done.\n") |
|
|
end |
|
|
end |
|
|
tPacks[pack] = {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
locallyInstalledPackages[requestedPackage] = {} |
|
|
term.write("Installing Files...") |
|
|
term.write("Installing Files...") |
|
|
for i, j in pairs(info.files) do |
|
|
|
|
|
local nPath |
|
|
|
|
|
if string.find(j, "^//") then |
|
|
|
|
|
local lPath = string.sub(j, 2) |
|
|
|
|
|
if not fs.exists(lPath) then |
|
|
|
|
|
fs.makeDirectory(lPath) |
|
|
|
|
|
end |
|
|
|
|
|
nPath = fs.concat(lPath, string.gsub(i, ".+(/.-)$", "%1"), nil) |
|
|
|
|
|
|
|
|
for filePath, requestedInstallPath in pairs(packageInfo.files) do |
|
|
|
|
|
local installedPath |
|
|
|
|
|
|
|
|
|
|
|
if string.find(requestedInstallPath, "^//") then |
|
|
|
|
|
local localInstalledPath = string.sub(requestedInstallPath, 2) |
|
|
|
|
|
if not fs.exists(localInstalledPath) then |
|
|
|
|
|
fs.makeDirectory(localInstalledPath) |
|
|
|
|
|
end |
|
|
|
|
|
installedPath = fs.concat(localInstalledPath, string.gsub(filePath, ".+(/.-)$", "%1"), nil) |
|
|
else |
|
|
else |
|
|
local lPath = fs.concat(path, j) |
|
|
|
|
|
if not fs.exists(lPath) then |
|
|
|
|
|
fs.makeDirectory(lPath) |
|
|
|
|
|
|
|
|
local localInstalledPath = fs.concat(installPath, requestedInstallPath) |
|
|
|
|
|
if not fs.exists(localInstalledPath) then |
|
|
|
|
|
fs.makeDirectory(localInstalledPath) |
|
|
|
|
|
end |
|
|
|
|
|
installedPath = fs.concat(installPath, requestedInstallPath, string.gsub(filePath, ".+(/.-)$", "%1"), nil) |
|
|
end |
|
|
end |
|
|
nPath = fs.concat(path, j, string.gsub(i, ".+(/.-)$", "%1"), nil) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if packageInfo.minified or options.m then |
|
|
|
|
|
filePath = string.gsub(filePath, "(.+)\.(.+)$", "%1\.min\.%2") |
|
|
end |
|
|
end |
|
|
local success = pcall(downloadFile, repo .. "/" .. i, nPath) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local success = pcall(downloadFile, repositoryPath .. "/" .. filePath, installedPath) |
|
|
if success then |
|
|
if success then |
|
|
tPacks[pack][i] = nPath |
|
|
|
|
|
|
|
|
locallyInstalledPackages[requestedPackage][filePath] = installedPath |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
if info.dependencies then |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if packageInfo.dependencies then |
|
|
term.write("Done.\nInstalling Dependencies...") |
|
|
term.write("Done.\nInstalling Dependencies...") |
|
|
for i, j in pairs(info.dependencies) do |
|
|
|
|
|
local nPath |
|
|
|
|
|
if string.find(j, "^//") then |
|
|
|
|
|
nPath = string.sub(j, 2) |
|
|
|
|
|
|
|
|
for packageDependency, dependencyPath in pairs(packageInfo.dependencies) do |
|
|
|
|
|
local installedDependencyPath |
|
|
|
|
|
|
|
|
|
|
|
if string.find(dependencyPath, "^//") then |
|
|
|
|
|
installedDependencyPath = string.sub(dependencyPath, 2) |
|
|
else |
|
|
else |
|
|
nPath = fs.concat(path, j, string.gsub(i, ".+(/.-)$", "%1"), nil) |
|
|
|
|
|
|
|
|
installedDependencyPath = fs.concat(installPath, dependencyPath, string.gsub(packageDependency, ".+(/.-)$", "%1"), nil) |
|
|
end |
|
|
end |
|
|
if string.lower(string.sub(i, 1, 4)) == "http" then |
|
|
|
|
|
local success = pcall(downloadFile, i, nPath) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if string.lower(string.sub(packageDependency, 1, 4)) == "http" then |
|
|
|
|
|
local success = pcall(downloadFile, packageDependency, installedDependencyPath) |
|
|
if success then |
|
|
if success then |
|
|
tPacks[pack][i] = nPath |
|
|
|
|
|
|
|
|
locallyInstalledPackages[requestedPackage][packageDependency] = installedDependencyPath |
|
|
end |
|
|
end |
|
|
else |
|
|
else |
|
|
local depInfo = getInformation(string.lower(i)) |
|
|
|
|
|
if not depInfo then |
|
|
|
|
|
term.write("\nDependency package " .. i .. " does not exist.") |
|
|
|
|
|
|
|
|
local dependencyInfo = getInformation(string.lower(packageDependency)) |
|
|
|
|
|
if not dependencyInfo then |
|
|
|
|
|
term.write("\nDependency package " .. packageDependency .. " does not exist.") |
|
|
end |
|
|
end |
|
|
installPackage(string.lower(i), fs.concat(path, j)) |
|
|
|
|
|
|
|
|
installPackage(string.lower(packageDependency), fs.concat(installPath, dependencyPath)) |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
term.write("Done.\n") |
|
|
term.write("Done.\n") |
|
|
saveToFile(tPacks) |
|
|
|
|
|
print("Successfully installed package " .. pack) |
|
|
|
|
|
|
|
|
saveToInstalledPackagesFile(locallyInstalledPackages) |
|
|
|
|
|
print("Successfully installed package " .. requestedPackage) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
local function uninstallPackage(pack) |
|
|
|
|
|
local info, repo = getInformation(pack) |
|
|
|
|
|
if not info then |
|
|
|
|
|
|
|
|
local function uninstallPackage(requestedPackage) |
|
|
|
|
|
local packageInformation, repositoryLocation = getInformation(requestedPackage) |
|
|
|
|
|
if not packageInformation then |
|
|
print("Package does not exist") |
|
|
print("Package does not exist") |
|
|
return |
|
|
return |
|
|
end |
|
|
end |
|
|
local tFiles = readFromFile(1) |
|
|
|
|
|
if not tFiles then |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local locallyInstalledFiles = readFromLocalInstallFile() |
|
|
|
|
|
if not locallyInstalledFiles then |
|
|
io.stderr:write("Error while trying to read package names") |
|
|
io.stderr:write("Error while trying to read package names") |
|
|
return |
|
|
return |
|
|
elseif tFiles[1] == -1 then |
|
|
|
|
|
table.remove(tFiles, 1) |
|
|
|
|
|
|
|
|
elseif locallyInstalledFiles[1] == -1 then |
|
|
|
|
|
table.remove(locallyInstalledFiles, 1) |
|
|
end |
|
|
end |
|
|
if not tFiles[pack] then |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not locallyInstalledFiles[requestedPackage] then |
|
|
print("Package has not been installed.") |
|
|
print("Package has not been installed.") |
|
|
print("If it has, you have to remove it manually.") |
|
|
print("If it has, you have to remove it manually.") |
|
|
return |
|
|
return |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
term.write("Removing package files...") |
|
|
term.write("Removing package files...") |
|
|
for i, j in pairs(tFiles[pack]) do |
|
|
|
|
|
|
|
|
for i, j in pairs(locallyInstalledFiles[requestedPackage]) do |
|
|
fs.remove(j) |
|
|
fs.remove(j) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
term.write("Done\nRemoving references...") |
|
|
term.write("Done\nRemoving references...") |
|
|
tFiles[pack] = nil |
|
|
|
|
|
saveToFile(tFiles) |
|
|
|
|
|
|
|
|
locallyInstalledFiles[requestedPackage] = nil |
|
|
|
|
|
saveToInstalledPackagesFile(locallyInstalledFiles) |
|
|
term.write("Done.\n") |
|
|
term.write("Done.\n") |
|
|
print("Successfully uninstalled package " .. pack) |
|
|
|
|
|
|
|
|
print("Successfully uninstalled package " .. requestedPackage) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
local function updatePackage(pack) |
|
|
local function updatePackage(pack) |
|
|
if pack == "all" then |
|
|
if pack == "all" then |
|
|
print("Updating everything...") |
|
|
print("Updating everything...") |
|
|
local tFiles = readFromFile(1) |
|
|
|
|
|
|
|
|
local tFiles = readFromLocalInstallFile() |
|
|
if not tFiles then |
|
|
if not tFiles then |
|
|
io.stderr:write("Error while trying to read package names") |
|
|
io.stderr:write("Error while trying to read package names") |
|
|
return |
|
|
return |
|
|