Compare commits

...

11 Commits

  1. 5
      src/bootstrap.moon
  2. 4
      src/programs.cfg
  3. 3
      src/repos.cfg
  4. 7
      src/spm/spm.cfg
  5. 148
      src/spm/spm.moon

5
src/bootstrap.moon

@ -13,8 +13,13 @@ if not component.isAvailable("internet")
downloadSrc = "{URL_BASE}/spm/spm.min.lua"
saveLocation = "/tmp/spm.lua"
downloadCfgSrc = "{URL_BASE}/spm/spm.cfg"
saveCfgLocation = "/etc/spm.cfg"
print("Downloading Temporary SPM")
wget("-qf", downloadSrc, saveLocation)
if not fs.exists(saveCfgLocation)
wget("-qf", downloadCfgSrc, saveCfgLocation)
spm = loadfile(saveLocation)

4
src/programs.cfg

@ -7,10 +7,10 @@
name = "Sothr Package Manager",
description = "A Modified Package Manager For OpenOS",
authors = "WarrickSothr",
note = "SPM operates similarly to OPPM, with slight modifications to referential repositories",
note = "SPM operates in the spirit of OPPM, with significant modifications, performance improvements, and working with referential repositories",
hidden = false,
repo = "",
version = "0.2.1",
version = "0.3.6",
minified = {MINIFIED}
}
}

3
src/repos.cfg

@ -4,5 +4,8 @@
},
["Warrick's Software"] = {
src = "{URL_BASE}/warricksothr"
},
["OPPM Repositories"] = {
link = "https://raw.githubusercontent.com/OpenPrograms/openprograms.github.io/master/repos.cfg"
}
}

7
src/spm/spm.cfg

@ -0,0 +1,7 @@
{
--default installation path
path="/usr",
--Additional repositories and packages go here, for correct package syntax, check https://github.com/OpenPrograms/Vexatos-Programs/blob/master/oppm/etc/example-config.cfg
repos={
}
}

148
src/spm/spm.moon

@ -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,17 +13,51 @@ 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)
defaultRepoLocationConfig = "{URL_BASE}/repos.cfg"
githubContentRoot = "https://raw.githubusercontent.com/"
repoLocationConfig = "{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, isLegacy) =>
@name = name
@src = src
@isLegacy = isLegacy
getPackagePath: =>
if @isLegacy
return @src .. "/master/programs.cfg"
@src .. "/programs.cfg"
getPackages: =>
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(...)
printUsage = ->
@ -51,26 +88,47 @@ getContent = (url) ->
return content
-- Request repository information
getRepositories = ->
success, raw_repositories = pcall(getContent, repoLocationConfig)
getRepositories = (repoLocation) ->
print("Retrieving Repository " .. 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
return serial.unserialize(raw_repositories)
deserialized_repositories = serial.unserialize(raw_repositories)
repositories = {}
for repositoryName, repository in pairs(deserialized_repositories)
if repository.link != nil
linked_repositories = getRepositories(repository.link)
for linkedRepositoryName, linkedRepository in pairs(linked_repositories)
repositories[linkedRepositoryName] = linkedRepository
continue
if repository.src == nil and repository.repo == nil
print("Repository malformed/unsupported: " .. repositoryName)
continue
isLegacy = false
src = repository.src
if src == nil
src = "https://raw.githubusercontent.com/" .. repository.repo
isLegacy = true
repositories[repositoryName] = Repository(repositoryName, src, isLegacy)
repositories
-- Get Packages for src
getPackages = (src) ->
success, sPackages = pcall(getContent, src .. "/programs.cfg")
success, packages = pcall(getContent, src)
if not success or not sPackages
if not success or not packages
return -1
return serial.unserialize(sPackages)
getGithubPackages = (repo) ->
return getPackages(githubContentRoot .. repo .. "/master")
return serial.unserialize(packages)
--For sorting table values by alphabet
compare = (a, b) ->
@ -80,6 +138,7 @@ compare = (a, b) ->
return #a < #b
-- Download a file from a remote location
downloadFile = (url, path, force) ->
if options.f or force
wget("-fq", url, path)
@ -89,6 +148,7 @@ downloadFile = (url, path, force) ->
return true
return false
-- Read serialized table data from a file
readFromFile = (path) ->
if not fs.exists(fs.path(path))
fs.makeDirectory(fs.path(path))
@ -105,9 +165,11 @@ readFromFile = (path) ->
file\close()
return serial.unserialize(serializedTableData) or { -1 }
-- Read the locally installed package list
readFromLocalInstallFile = ->
return readFromFile(localInstalledPackagesFile)
-- Read the local configuration file
readLocalConfigFile = ->
path = localConfigFile
if not fs.exists(path)
@ -115,6 +177,7 @@ readLocalConfigFile = ->
else
return readFromFile(path)
-- Save the installed packages table to a local file
saveToInstalledPackagesFile = (installedPackages) ->
file, msg = io.open(localInstalledPackagesFile, "wb")
@ -127,6 +190,7 @@ saveToInstalledPackagesFile = (installedPackages) ->
file\write(sPacks)
file\close()
-- List all packages
listPackages = (filter) ->
filter = filter or false
@ -136,30 +200,22 @@ listPackages = (filter) ->
packageTable = {}
print("Receiving Package list...")
if not options.i
success, repositories = pcall(getRepositories)
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")
return
for _, repository in pairs(repositories)
packages = -1
target = -1
if repository.src
print("Checking Repository " .. repository.src)
packages = getPackages(repository.src)
target = repository.src
elseif repository.repo
print("Checking Repository " .. repository.repo)
packages = getGithubPackages(repository.repo)
target = repository.repo
print("Checking Repository " .. repository.src)
packages = repository\getPackages!
if packages == nil
io.stderr\write("Error while trying to receive package list for " .. target .. "\n")
io.stderr\write("Error while trying to receive package list for " .. repository.src .. "\n")
return
elseif type(packages) == "table"
for package in pairs(packages)
@ -183,8 +239,8 @@ listPackages = (filter) ->
table.sort(packageTable, compare)
return packageTable
-- Pretty print a package table
printPackages = (packages) ->
if packages == nil or not packages[1]
print("No package matching specified filter found.")
return
@ -204,33 +260,27 @@ printPackages = (packages) ->
print("--SPM {ENV} Package list--")
xCur, yCur = term.getCursor()
-- Retrieve package information
getInformation = (requestedPackage) ->
success, repositories = pcall(getRepositories)
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)
packages = -1
target = -1
if repository.src
packages = getPackages(repository.src)
target = repository.src
elseif repository.repo
packages = getGithubPackages(repository.repo)
target = githubContentRoot .. repository.repo
packages = repository\getPackages!
if packages == nil
io.stderr\write("Error while trying to receive package list for " .. target .. "\n")
io.stderr\write("Error while trying to receive package list for " .. repository.src .. "\n")
elseif type(packages) == "table"
for package in pairs(packages)
if package == requestedPackage
return packages[package], target
return packages[package], repository.src
return nil
-- uhhhhhh
provideInfo = (pack) ->
if not pack
printUsage()
@ -239,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
@ -294,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
@ -331,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
@ -397,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()
@ -408,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
@ -431,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()
@ -442,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

Loading…
Cancel
Save