|
|
@ -1,3 +1,6 @@ |
|
|
|
-- Variables for component names that are called more than once |
|
|
|
internet_component = "internet" |
|
|
|
|
|
|
|
component = require("component") |
|
|
|
event = require("event") |
|
|
|
fs = require("filesystem") |
|
|
@ -10,31 +13,50 @@ wget = loadfile("/bin/wget.lua") |
|
|
|
|
|
|
|
gpu = component.gpu |
|
|
|
|
|
|
|
if not component.isAvailable("internet") |
|
|
|
if not component.isAvailable(internet_component) |
|
|
|
io.stderr\write("This program requires an internet card to run.") |
|
|
|
return |
|
|
|
|
|
|
|
internet = require("internet") |
|
|
|
internet = require(internet_component) |
|
|
|
|
|
|
|
githubContentRoot = "https://raw.githubusercontent.com/" |
|
|
|
defaultRepoLocationConfig = "{URL_BASE}/repos.cfg" |
|
|
|
|
|
|
|
localInstalledPackagesFile = "/etc/spdata.svd" |
|
|
|
localConfigFile = "/etc/spm.cfg" |
|
|
|
|
|
|
|
-- Common Error Messages |
|
|
|
err_internet_connection = "Unable to connect to the Internet.\n" |
|
|
|
err_package_does_not_exist = "Package does not exist" |
|
|
|
err_package_has_not_been_installed = "Package has not been installed." |
|
|
|
|
|
|
|
class Repository |
|
|
|
new: (name, src, isGithub) => |
|
|
|
new: (name, src, isLegacy) => |
|
|
|
@name = name |
|
|
|
@src = src |
|
|
|
@isGithub = isGithub |
|
|
|
@isLegacy = isLegacy |
|
|
|
|
|
|
|
getRepoPath: => |
|
|
|
if @isGithub |
|
|
|
return @src .. "/master" |
|
|
|
@src |
|
|
|
getPackagePath: => |
|
|
|
if @isLegacy |
|
|
|
return @src .. "/master/programs.cfg" |
|
|
|
@src .. "/programs.cfg" |
|
|
|
|
|
|
|
getPackages: => |
|
|
|
getPackages(@\getRepoPath!) |
|
|
|
getPackages(@\getPackagePath!) |
|
|
|
|
|
|
|
|
|
|
|
class Package |
|
|
|
new: (name, longName, files, dependencies, description, authors, note, hidden, repo, version, minified) => |
|
|
|
@name = name |
|
|
|
@longName = longName |
|
|
|
@files = files |
|
|
|
@dependencies = dependencies |
|
|
|
@description = description |
|
|
|
@authors = authors |
|
|
|
@note = note |
|
|
|
@hidden = hidden |
|
|
|
@repo = version |
|
|
|
@minified = minified |
|
|
|
|
|
|
|
|
|
|
|
args, options = shell.parse(...) |
|
|
|
|
|
|
@ -71,7 +93,7 @@ getRepositories = (repoLocation) -> |
|
|
|
success, raw_repositories = pcall(getContent, repoLocation) |
|
|
|
|
|
|
|
if not success |
|
|
|
io.stderr\write("Could not connect to the Internet. Please ensure you have an Internet connection.") |
|
|
|
io.stderr\write(err_internet_connection) |
|
|
|
return -1 |
|
|
|
|
|
|
|
deserialized_repositories = serial.unserialize(raw_repositories) |
|
|
@ -89,18 +111,19 @@ getRepositories = (repoLocation) -> |
|
|
|
print("Repository malformed/unsupported: " .. repositoryName) |
|
|
|
continue |
|
|
|
|
|
|
|
isLegacy = false |
|
|
|
src = repository.src |
|
|
|
isGithub = false |
|
|
|
if src == nil |
|
|
|
src = githubContentRoot .. repository.repo |
|
|
|
isGithub = true |
|
|
|
repositories[repositoryName] = Repository(repositoryName, src, isGithub) |
|
|
|
src = "https://raw.githubusercontent.com/" .. repository.repo |
|
|
|
isLegacy = true |
|
|
|
|
|
|
|
repositories[repositoryName] = Repository(repositoryName, src, isLegacy) |
|
|
|
|
|
|
|
repositories |
|
|
|
|
|
|
|
-- Get Packages for src |
|
|
|
getPackages = (src) -> |
|
|
|
success, packages = pcall(getContent, src .. "/programs.cfg") |
|
|
|
success, packages = pcall(getContent, src) |
|
|
|
|
|
|
|
if not success or not packages |
|
|
|
return -1 |
|
|
@ -180,7 +203,7 @@ listPackages = (filter) -> |
|
|
|
success, repositories = pcall(getRepositories, defaultRepoLocationConfig) |
|
|
|
|
|
|
|
if not success or repositories == -1 |
|
|
|
io.stderr\write("Unable to connect to the Internet.\n") |
|
|
|
io.stderr\write(err_internet_connection) |
|
|
|
return |
|
|
|
elseif repositories == nil |
|
|
|
print("Error while trying to receive repository list") |
|
|
@ -242,7 +265,7 @@ getInformation = (requestedPackage) -> |
|
|
|
success, repositories = pcall(getRepositories, defaultRepoLocationConfig) |
|
|
|
|
|
|
|
if not success or repositories == -1 |
|
|
|
io.stderr\write("Unable to connect to the Internet.\n") |
|
|
|
io.stderr\write(err_internet_connection) |
|
|
|
return |
|
|
|
|
|
|
|
for _, repository in pairs(repositories) |
|
|
@ -266,7 +289,7 @@ provideInfo = (pack) -> |
|
|
|
pack = string.lower(pack) |
|
|
|
info = getInformation(pack) |
|
|
|
if not info |
|
|
|
print("Package does not exist") |
|
|
|
print(err_package_does_not_exist) |
|
|
|
return |
|
|
|
|
|
|
|
done = false |
|
|
@ -321,7 +344,7 @@ installPackage = (requestedPackage, installPath, doUpdate) -> |
|
|
|
|
|
|
|
packageInfo, repositoryPath = getInformation(requestedPackage) |
|
|
|
if not packageInfo |
|
|
|
print("Package does not exist") |
|
|
|
print(err_package_does_not_exist) |
|
|
|
return |
|
|
|
|
|
|
|
if doUpdate |
|
|
@ -358,7 +381,7 @@ installPackage = (requestedPackage, installPath, doUpdate) -> |
|
|
|
print("Package has already been installed") |
|
|
|
return |
|
|
|
elseif not locallyInstalledPackages[requestedPackage] and doUpdate |
|
|
|
print("Package has not been installed.") |
|
|
|
print(err_package_has_not_been_installed) |
|
|
|
print("If it has, uninstall it manually and reinstall it.") |
|
|
|
return |
|
|
|
|
|
|
@ -424,7 +447,7 @@ installPackage = (requestedPackage, installPath, doUpdate) -> |
|
|
|
copyPackage = (requestedPackage, copyLocation) -> |
|
|
|
packageInformation, repositoryLocation = getInformation(requestedPackage) |
|
|
|
if not packageInformation |
|
|
|
print("Package does not exist") |
|
|
|
print(err_package_does_not_exist) |
|
|
|
return |
|
|
|
|
|
|
|
locallyInstalledFiles = readFromLocalInstallFile() |
|
|
@ -435,7 +458,7 @@ copyPackage = (requestedPackage, copyLocation) -> |
|
|
|
table.remove(locallyInstalledFiles, 1) |
|
|
|
|
|
|
|
if not locallyInstalledFiles[requestedPackage] |
|
|
|
print("Package has not been installed.") |
|
|
|
print(err_package_has_not_been_installed) |
|
|
|
print("It must be installed to be copied.") |
|
|
|
return |
|
|
|
|
|
|
@ -458,7 +481,7 @@ copyPackage = (requestedPackage, copyLocation) -> |
|
|
|
uninstallPackage = (requestedPackage) -> |
|
|
|
packageInformation, repositoryLocation = getInformation(requestedPackage) |
|
|
|
if not packageInformation |
|
|
|
print("Package does not exist") |
|
|
|
print(err_package_does_not_exist) |
|
|
|
return |
|
|
|
|
|
|
|
locallyInstalledFiles = readFromLocalInstallFile() |
|
|
@ -469,7 +492,7 @@ uninstallPackage = (requestedPackage) -> |
|
|
|
table.remove(locallyInstalledFiles, 1) |
|
|
|
|
|
|
|
if not locallyInstalledFiles[requestedPackage] |
|
|
|
print("Package has not been installed.") |
|
|
|
print(err_package_has_not_been_installed) |
|
|
|
print("If it has, you have to remove it manually.") |
|
|
|
return |
|
|
|
|
|
|
|