1
0
mirror of https://github.com/AR2000AR/openComputers_codes.git synced 2025-09-08 14:41:14 +02:00

[pm-get] allow same version update/install

This commit is contained in:
2023-04-13 16:09:33 +02:00
parent e4c8bc5ff2
commit 5d567d38a9
3 changed files with 41 additions and 12 deletions

Binary file not shown.

View File

@@ -16,12 +16,23 @@ local SOURCE_DIR = SOURCE_FILE .. ".d/"
local REPO_MANIFEST_CACHE = CONFIG_DIR .. "manifests.cache"
local AUTO_INSTALLED = CONFIG_DIR .. "autoInstalled"
--=============================================================================
---@type table<string>,table<progOpts>
local args, opts = shell.parse(...)
local mode = table.remove(args, 1)
--=============================================================================
local reposRuntimeCache
--=============================================================================
---@alias progOpts
---| 'autoremove'
---| 'purge'
---| 'allow-same-version'
--=============================================================================
local f = string.format
@@ -223,7 +234,11 @@ local function install(package, markAuto, buildDepTree)
os.exit(1)
end
io.open(f("%s/%s", DOWNLOAD_DIR, targetManifest.archiveName), "w"):write(data):close()
local _, code = shell.execute(f("pm install %s", f("%s/%s", DOWNLOAD_DIR, targetManifest.archiveName)))
local pmOptions = ""
if (opts["allow-same-version"]) then
pmOptions = "--allow-same-version"
end
local _, code = shell.execute(f("pm install %s %s", pmOptions, f("%s/%s", DOWNLOAD_DIR, targetManifest.archiveName)))
filesystem.remove(f("%s/%s", DOWNLOAD_DIR, targetManifest.archiveName))
if (markAuto) then
io.open(AUTO_INSTALLED, "a"):write(targetManifest.package):close()
@@ -274,6 +289,7 @@ local function printHelp()
printf("opts :")
printf("\t--autoremove : also remove dependencies non longer required")
printf("\t--purge : purge removed packages")
printf("\t--allow-same-version : allow the same package version to be installed over the currently installed one")
end
--=============================================================================
@@ -284,6 +300,7 @@ else
printferr("Need a internet card")
end
--Remove uninstalled files from autoInstalled file
if (filesystem.exists(AUTO_INSTALLED)) then
do
local tokeep = {}
@@ -296,9 +313,6 @@ if (filesystem.exists(AUTO_INSTALLED)) then
end
end
local args, opts = shell.parse(...)
local mode = table.remove(args, 1)
if (mode == "update") then
print("Updating repository cache")
update()
@@ -377,14 +391,29 @@ elseif (mode == "autoremove") then
elseif (mode == "upgrade") then
local installed = pm.getInstalled(false)
local toUpgrade = {}
for pkg, manifest in pairs(installed) do
if (manifest.version == "oppm") then
printf("Found oppm version for %q.", pkg)
table.insert(toUpgrade, pkg)
else
local remoteManifest = getPacket(pkg)
if (remoteManifest and (remoteManifest.version == "oppm" or compareVersion(remoteManifest.version, manifest.version))) then
if (args[1]) then
if (pm.isInstalled(args[1])) then
table.insert(toUpgrade, args[1])
local manifest = assert(pm.getManifestFromInstalled(args[1]))
if (manifest.dependencies) then
for dep, ver in pairs(manifest.dependencies) do
local remoteManifest = getPacket(dep) --TODO : add target repo
if (remoteManifest and (remoteManifest.version == "oppm" or compareVersion(remoteManifest.version, manifest.version) or opts["allow-same-version"])) then
table.insert(toUpgrade, dep)
end
end
end
end
else
for pkg, manifest in pairs(installed) do
if (manifest.version == "oppm") then
printf("Found oppm version for %q.", pkg)
table.insert(toUpgrade, pkg)
else
local remoteManifest = getPacket(pkg)
if (remoteManifest and (remoteManifest.version == "oppm" or compareVersion(remoteManifest.version, manifest.version))) then
table.insert(toUpgrade, pkg)
end
end
end
end

View File

@@ -332,7 +332,7 @@
dependencies = {
["pm"] = "/"
},
version = "1.2.2"
version = "1.3.0"
name = "pm get",
description = "Download and install package for pm",
authors = "AR2000AR",