Browse Source

Working on implementing non github sources into spm

environments/production/deployments/4
Drew Short 7 years ago
parent
commit
2f1c57dc68
  1. 25
      gruntfile.js
  2. 15
      src/programs.cfg
  3. 5
      src/repos.cfg
  4. 245
      src/spm/spm.lua
  5. 0
      src/warricksothr/license
  6. 0
      src/warricksothr/license.min
  7. 0
      src/warricksothr/reactor_control/reactor_control.lua

25
gruntfile.js

@ -8,7 +8,7 @@ module.exports = function (grunt) {
files: [{ files: [{
expand: true, expand: true,
cwd: "./src", cwd: "./src",
src: ["**/license*"],
src: ["**/license*", "**/*.lua", "*.cfg"],
dest: "dist/", dest: "dist/",
filter: 'isFile' filter: 'isFile'
}] }]
@ -20,31 +20,11 @@ module.exports = function (grunt) {
grunt.loadNpmTasks("grunt-contrib-copy"); grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks('grunt-file-append'); grunt.loadNpmTasks('grunt-file-append');
grunt.registerTask("add-rename-lua-module-tasks", "Finds and adds tasks to rename all main.lua to match their parent directory", function () {
grunt.file.expand({filter: 'isDirectory'}, "src/*").forEach(function (dir) {
var module_name = dir.substr(dir.lastIndexOf('/') + 1);
if (module_name !== 'lib') {
var copy_task = {};
try {
copy_task = grunt.config.get('copy');
} catch (exception) {
console.log("No copy config exists, generating empty one.");
}
copy_task[module_name] = {
src: [dir + '/**/main.lua'],
dest: 'dist/' + module_name + '/' + module_name + '.lua'
};
console.log("Added copy task for module [" + module_name + "]");
grunt.config.set('copy', copy_task);
}
});
});
grunt.registerTask("minify-lua-modules", "minifies lua modules", function () { grunt.registerTask("minify-lua-modules", "minifies lua modules", function () {
const fs = require('fs'); const fs = require('fs');
const luamin = require('luamin'); const luamin = require('luamin');
const util = require('util'); const util = require('util');
grunt.file.expand({filter: 'isDirectory'}, "dist/*").forEach(function (dir) {
grunt.file.expand({filter: 'isDirectory'}, "dist/**/*").forEach(function (dir) {
grunt.file.expand({filter: 'isFile'}, dir + "/*.lua").forEach(function (file) { grunt.file.expand({filter: 'isFile'}, dir + "/*.lua").forEach(function (file) {
const directory = file.substr(0, file.lastIndexOf('/')); const directory = file.substr(0, file.lastIndexOf('/'));
const file_name = file.substr(file.lastIndexOf('/') + 1); const file_name = file.substr(file.lastIndexOf('/') + 1);
@ -67,7 +47,6 @@ module.exports = function (grunt) {
grunt.registerTask("default", [ grunt.registerTask("default", [
"clean", "clean",
"add-rename-lua-module-tasks",
"copy", "copy",
"minify-lua-modules" "minify-lua-modules"
]); ]);

15
src/programs.cfg

@ -0,0 +1,15 @@
{
["spm"] = {
files = {
["spm/spm.lua"] = "/"
},
dependencies = {},
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",
hidden = false,
repo = "",
version = "0.1"
}
}

5
src/repos.cfg

@ -0,0 +1,5 @@
{
["Sothr's Software"] = {
src = "https://sothr.com/download/oc/releases"
}
}

245
src/spm/main.lua → src/spm/spm.lua

@ -1,6 +1,7 @@
--[[ --[[
OpenPrograms package manager, browser and downloader, for easy access to many programs
Author: Vexatos
Sothr Package Manager, browser and downloader, for easy access to many programs
Author: Vexatos, WarrickSothr
Forked and modified from: https://github.com/Wuerfel21/OpenComputers/blob/master/src/main/resources/assets/opencomputers/loot/OPPM/oppm.lua
]] ]]
local component = require("component") local component = require("component")
local event = require("event") local event = require("event")
@ -20,7 +21,8 @@ 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://raw.githubusercontent.com/OpenPrograms/openprograms.github.io/master/repos.cfg"
local repoLocationConfig = "https://sothr.com/download/oc/releases/repos.cfg"
local args, options = shell.parse(...) local args, options = shell.parse(...)
@ -46,7 +48,7 @@ local function getContent(url)
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
@ -60,8 +62,16 @@ local function getRepos()
return serial.unserialize(sRepos) return serial.unserialize(sRepos)
end end
local function getPackages(repo)
local success, sPackages = pcall(getContent,"https://raw.githubusercontent.com/"..repo.."/master/programs.cfg")
local function getPackages(src)
local success, sPackages = pcall(getContent, src .. "/programs.cfg")
if not success or not sPackages then
return -1
end
return serial.unserialize(sPackages)
end
local function getGithubPackages(repo)
local success, sPackages = pcall(getContent, "https://raw.githubusercontent.com/" .. repo .. "/master/programs.cfg")
if not success or not sPackages then if not success or not sPackages then
return -1 return -1
end end
@ -69,20 +79,20 @@ local function getPackages(repo)
end end
--For sorting table values by alphabet --For sorting table values by alphabet
local function compare(a,b)
for i=1,math.min(#a,#b) do
if a:sub(i,i)~=b:sub(i,i) then
return a:sub(i,i) < b:sub(i,i)
local function compare(a, b)
for i = 1, math.min(#a, #b) do
if a:sub(i, i) ~= b:sub(i, i) then
return a:sub(i, i) < b:sub(i, i)
end end
end end
return #a < #b return #a < #b
end end
local function downloadFile(url,path,force)
local function downloadFile(url, path, force)
if options.f or force then if options.f or force then
wget("-fq",url,path)
wget("-fq", url, path)
else else
wget("-q",url,path)
wget("-q", url, path)
end end
end end
@ -91,32 +101,32 @@ local function readFromFile(fNum)
if fNum == 1 then if fNum == 1 then
path = "/etc/opdata.svd" path = "/etc/opdata.svd"
elseif fNum == 2 then elseif fNum == 2 then
path = "/etc/oppm.cfg"
path = "/etc/spm.cfg"
if not fs.exists(path) then if not fs.exists(path) then
local tProcess = process.running() local tProcess = process.running()
path = fs.concat(fs.path(shell.resolve(tProcess)),"/etc/oppm.cfg")
path = fs.concat(fs.path(shell.resolve(tProcess)), "/etc/spm.cfg")
end end
end end
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 sPacks = file:read("*a")
file:close() file:close()
return serial.unserialize(sPacks) or {-1}
return serial.unserialize(sPacks) or { -1 }
end end
local function saveToFile(tPacks) local function saveToFile(tPacks)
local file,msg = io.open("/etc/opdata.svd","wb")
local file, msg = io.open("/etc/opdata.svd", "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(tPacks)
@ -133,35 +143,42 @@ local function listPackages(filter)
print("Receiving Package list...") print("Receiving Package list...")
if not options.i then if not options.i then
local success, repos = pcall(getRepos) local success, repos = pcall(getRepos)
if not success or repos==-1 then
if not success or repos == -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 repos == 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
if j.repo then
print("Checking Repository "..j.repo)
local lPacks = getPackages(j.repo)
if lPacks==nil then
io.stderr:write("Error while trying to receive package list for " .. j.repo.."\n")
return
elseif type(lPacks) == "table" then
for k in pairs(lPacks) do
if not k.hidden then
table.insert(packages,k)
end
for _, j in pairs(repos) do
local lPacks
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
io.stderr:write("Error while trying to receive package list for " .. target .. "\n")
return
elseif type(lPacks) == "table" then
for k in pairs(lPacks) do
if not k.hidden then
table.insert(packages, k)
end end
end end
end end
end end
local lRepos = readFromFile(2) local lRepos = readFromFile(2)
if lRepos then if lRepos then
for _,j in pairs(lRepos.repos) do
for _, j in pairs(lRepos.repos) do
for k in pairs(j) do for k in pairs(j) do
if not k.hidden then if not k.hidden then
table.insert(packages,k)
table.insert(packages, k)
end end
end end
end end
@ -170,42 +187,42 @@ local function listPackages(filter)
local lPacks = {} local lPacks = {}
local tPacks = readFromFile(1) local tPacks = readFromFile(1)
for i in pairs(tPacks) do for i in pairs(tPacks) do
table.insert(lPacks,i)
table.insert(lPacks, i)
end end
packages = lPacks packages = lPacks
end end
if filter then if filter then
local lPacks = {} 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)
for i, j in ipairs(packages) do
if (#j >= #filter) and string.find(j, filter, 1, true) ~= nil then
table.insert(lPacks, j)
end end
end end
packages = lPacks packages = lPacks
end end
table.sort(packages,compare)
table.sort(packages, compare)
return packages return packages
end end
local function printPackages(tPacks) local function printPackages(tPacks)
if tPacks==nil or not tPacks[1] then
if tPacks == nil or not tPacks[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("--OpenPrograms Package list--") print("--OpenPrograms Package list--")
local xCur,yCur = term.getCursor()
for _,j in ipairs(tPacks) do
term.write(j.."\n")
yCur = yCur+1
if yCur>yRes-1 then
local xCur, yCur = term.getCursor()
for _, j in ipairs(tPacks) do
term.write(j .. "\n")
yCur = yCur + 1
if yCur > yRes - 1 then
term.write("[Press any key to continue]") term.write("[Press any key to continue]")
local event = event.pull("key_down") local event = event.pull("key_down")
if event then if event then
term.clear() term.clear()
print("--OpenPrograms Package list--") print("--OpenPrograms Package list--")
xCur,yCur = term.getCursor()
xCur, yCur = term.getCursor()
end end
end end
end end
@ -213,30 +230,36 @@ end
local function getInformation(pack) local function getInformation(pack)
local success, repos = pcall(getRepos) local success, repos = pcall(getRepos)
if not success or repos==-1 then
if not success or repos == -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
if j.repo then
local lPacks = getPackages(j.repo)
if lPacks==nil then
io.stderr:write("Error while trying to receive package list for "..j.repo.."\n")
elseif type(lPacks) == "table" then
for k in pairs(lPacks) do
if k==pack then
return lPacks[k],j.repo
end
for _, j in pairs(repos) do
local lPacks
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 end
end end
end end
local lRepos = readFromFile(2) local lRepos = readFromFile(2)
if lRepos then if lRepos then
for i,j in pairs(lRepos.repos) do
for i, j in pairs(lRepos.repos) do
for k in pairs(j) do for k in pairs(j) do
if k==pack then
return j[k],i
if k == pack then
return j[k], i
end end
end end
end end
@ -256,21 +279,21 @@ local function provideInfo(pack)
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.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
@ -278,7 +301,7 @@ local function provideInfo(pack)
end end
end end
local function installPackage(pack,path,update)
local function installPackage(pack, path, update)
update = update or false update = update or false
if not pack then if not pack then
printUsage() printUsage()
@ -287,10 +310,10 @@ local function installPackage(pack,path,update)
if not path and not update then if not path and not update then
local lConfig = readFromFile(2) local lConfig = readFromFile(2)
path = lConfig.path or "/usr" path = lConfig.path or "/usr"
print("Installing package to "..path.."...")
print("Installing package to " .. path .. "...")
elseif not update then elseif not update then
path = shell.resolve(path) path = shell.resolve(path)
print("Installing package to "..path.."...")
print("Installing package to " .. path .. "...")
end end
pack = string.lower(pack) pack = string.lower(pack)
@ -298,22 +321,22 @@ local function installPackage(pack,path,update)
if not tPacks then if not tPacks 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 tPacks[1] == -1 then
table.remove(tPacks, 1)
end end
local info,repo = getInformation(pack)
local info, repo = getInformation(pack)
if not info then if not info then
print("Package does not exist") print("Package does not exist")
return return
end end
if update then if update then
print("Updating package "..pack)
print("Updating package " .. pack)
path = nil 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.."/?$","/")
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 .. "/?$", "/")
break break
end end
end end
@ -321,12 +344,12 @@ local function installPackage(pack,path,update)
break break
end end
end end
path = shell.resolve(string.gsub(path,"^/?","/"),nil)
path = shell.resolve(string.gsub(path, "^/?", "/"), nil)
end end
if not update and fs.exists(path) then if not update and fs.exists(path) then
if not fs.isDirectory(path) then if not fs.isDirectory(path) then
if options.f then if options.f then
path = fs.concat(fs.path(path),pack)
path = fs.concat(fs.path(path), pack)
fs.makeDirectory(path) fs.makeDirectory(path)
else else
print("Path points to a file, needs to be a directory.") print("Path points to a file, needs to be a directory.")
@ -351,63 +374,63 @@ local function installPackage(pack,path,update)
end end
if update then if update then
term.write("Removing old files...") term.write("Removing old files...")
for i,j in pairs(tPacks[pack]) do
for i, j in pairs(tPacks[pack]) do
fs.remove(j) fs.remove(j)
end end
term.write("Done.\n") term.write("Done.\n")
end end
tPacks[pack] = {} tPacks[pack] = {}
term.write("Installing Files...") term.write("Installing Files...")
for i,j in pairs(info.files) do
for i, j in pairs(info.files) do
local nPath local nPath
if string.find(j,"^//") then
local lPath = string.sub(j,2)
if string.find(j, "^//") then
local lPath = string.sub(j, 2)
if not fs.exists(lPath) then if not fs.exists(lPath) then
fs.makeDirectory(lPath) fs.makeDirectory(lPath)
end end
nPath = fs.concat(lPath,string.gsub(i,".+(/.-)$","%1"),nil)
nPath = fs.concat(lPath, string.gsub(i, ".+(/.-)$", "%1"), nil)
else else
local lPath = fs.concat(path,j)
local lPath = fs.concat(path, j)
if not fs.exists(lPath) then if not fs.exists(lPath) then
fs.makeDirectory(lPath) fs.makeDirectory(lPath)
end end
nPath = fs.concat(path,j,string.gsub(i,".+(/.-)$","%1"),nil)
nPath = fs.concat(path, j, string.gsub(i, ".+(/.-)$", "%1"), nil)
end end
local success = pcall(downloadFile,"https://raw.githubusercontent.com/"..repo.."/"..i,nPath)
local success = pcall(downloadFile, "https://raw.githubusercontent.com/" .. repo .. "/" .. i, nPath)
if success then if success then
tPacks[pack][i] = nPath tPacks[pack][i] = nPath
end end
end end
if info.dependencies then if info.dependencies then
term.write("Done.\nInstalling Dependencies...") term.write("Done.\nInstalling Dependencies...")
for i,j in pairs(info.dependencies) do
for i, j in pairs(info.dependencies) do
local nPath local nPath
if string.find(j,"^//") then
nPath = string.sub(j,2)
if string.find(j, "^//") then
nPath = string.sub(j, 2)
else else
nPath = fs.concat(path,j,string.gsub(i,".+(/.-)$","%1"),nil)
nPath = fs.concat(path, j, string.gsub(i, ".+(/.-)$", "%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(i, 1, 4)) == "http" then
local success = pcall(downloadFile, i, nPath)
if success then if success then
tPacks[pack][i] = nPath tPacks[pack][i] = nPath
end end
else else
local depInfo = getInformation(string.lower(i)) local depInfo = getInformation(string.lower(i))
if not depInfo then if not depInfo then
term.write("\nDependency package "..i.." does not exist.")
term.write("\nDependency package " .. i .. " does not exist.")
end end
installPackage(string.lower(i),fs.concat(path,j))
installPackage(string.lower(i), fs.concat(path, j))
end end
end end
end end
term.write("Done.\n") term.write("Done.\n")
saveToFile(tPacks) saveToFile(tPacks)
print("Successfully installed package "..pack)
print("Successfully installed package " .. pack)
end end
local function uninstallPackage(pack) local function uninstallPackage(pack)
local info,repo = getInformation(pack)
local info, repo = getInformation(pack)
if not info then if not info then
print("Package does not exist") print("Package does not exist")
return return
@ -416,8 +439,8 @@ local function uninstallPackage(pack)
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
elseif tFiles[1]==-1 then
table.remove(tFiles,1)
elseif tFiles[1] == -1 then
table.remove(tFiles, 1)
end end
if not tFiles[pack] then if not tFiles[pack] then
print("Package has not been installed.") print("Package has not been installed.")
@ -425,36 +448,36 @@ local function uninstallPackage(pack)
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(tFiles[pack]) do
fs.remove(j) fs.remove(j)
end end
term.write("Done\nRemoving references...") term.write("Done\nRemoving references...")
tFiles[pack]=nil
tFiles[pack] = nil
saveToFile(tFiles) saveToFile(tFiles)
term.write("Done.\n") term.write("Done.\n")
print("Successfully uninstalled package "..pack)
print("Successfully uninstalled package " .. pack)
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 = readFromFile(1)
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
elseif tFiles[1]==-1 then
table.remove(tFiles,1)
elseif tFiles[1] == -1 then
table.remove(tFiles, 1)
end end
local done = false local done = false
for i in pairs(tFiles) do for i in pairs(tFiles) do
installPackage(i,nil,true)
installPackage(i, nil, true)
done = true done = true
end end
if not done then if not done then
print("No package has been installed so far.") print("No package has been installed so far.")
end end
else else
installPackage(args[2],nil,true)
installPackage(args[2], nil, true)
end end
end end
@ -464,7 +487,7 @@ if args[1] == "list" then
elseif args[1] == "info" then elseif args[1] == "info" then
provideInfo(args[2]) provideInfo(args[2])
elseif args[1] == "install" then elseif args[1] == "install" then
installPackage(args[2],args[3],false)
installPackage(args[2], args[3], false)
elseif args[1] == "update" then elseif args[1] == "update" then
updatePackage(args[2]) updatePackage(args[2])
elseif args[1] == "uninstall" then elseif args[1] == "uninstall" then

0
src/license → src/warricksothr/license

0
src/license.min → src/warricksothr/license.min

0
src/reactor_control/main.lua → src/warricksothr/reactor_control/reactor_control.lua

Loading…
Cancel
Save