Bumped to 4.0

To solve Packaging scriptlets assume global 'arg' in Lua environment
https://bugzilla.redhat.com/show_bug.cgi?id=1892224
This commit is contained in:
Jiri 2021-04-30 10:52:50 +02:00
parent 988593295e
commit efdd06373d
2 changed files with 310 additions and 305 deletions

View File

@ -6,9 +6,9 @@
Name: copy-jdk-configs Name: copy-jdk-configs
# hash relevant to version tag # hash relevant to version tag
%global htag bf480d4217342a54d3f1103365d21f6e399c4932 %global htag 88d3ed89f30d8b0eb4877d860fa8d951f224f156
Version: 3.9 Version: 4.0
Release: 4.0.pre.0.bf480d4217342a54d3f1103365d21f6e399c4932%{?dist} Release: 0%{?dist}
Summary: JDKs configuration files copier Summary: JDKs configuration files copier
License: BSD License: BSD
@ -72,7 +72,7 @@ rm "%{rpm_state_dir}/%{file}" 2> /dev/null || :
%license LICENSE %license LICENSE
%changelog %changelog
* Thu Apr 29 2021 Fedora Release Engineering <releng@fedoraproject.org> - 3.9-4.0.pre.0.bf480d4217342a54d3f1103365d21f6e399c4932%{?dist} * Thu Apr 29 2021 Fedora Release Engineering <releng@fedoraproject.org> - 4.0-0
- bumped to 4.0 to resolve remvoed rpm 4.17 removing arg from global table - bumped to 4.0 to resolve remvoed rpm 4.17 removing arg from global table
* Tue Jan 26 2021 Fedora Release Engineering <releng@fedoraproject.org> - 3.7-8 * Tue Jan 26 2021 Fedora Release Engineering <releng@fedoraproject.org> - 3.7-8

View File

@ -7,29 +7,29 @@
local M = {} local M = {}
if (os.getenv("debug") == "true") then if (os.getenv("debug") == "true") then
debug = true; debug = true;
else else
debug = false; debug = false;
end end
local function debugOneLinePrint(string) local function debugOneLinePrint(string)
if (debug) then if (debug) then
print(string) print(string)
end; end ;
end end
function getPath(str,sep) function getPath(str, sep)
sep=sep or '/' sep = sep or '/'
return str:match("(.*"..sep..")") return str:match("(.*" .. sep .. ")")
end end
function splitToTable(source, pattern) function splitToTable(source, pattern)
local i1 = string.gmatch(source, pattern) local i1 = string.gmatch(source, pattern)
local l1 = {} local l1 = {}
for i in i1 do for i in i1 do
table.insert(l1, i) table.insert(l1, i)
end end
return l1 return l1
end end
local function slurp(path) local function slurp(path)
@ -40,27 +40,27 @@ local function slurp(path)
end end
function trim(s) function trim(s)
return (s:gsub("^%s*(.-)%s*$", "%1")) return (s:gsub("^%s*(.-)%s*$", "%1"))
end end
local function dirWithParents(path) local function dirWithParents(path)
local s = "" local s = ""
local dirs = splitToTable(path, "[^/]+") local dirs = splitToTable(path, "[^/]+")
for i,d in pairs(dirs) do for i, d in pairs(dirs) do
if (i == #dirs) then if (i == #dirs) then
break break
end
s = s .. "/" .. d
local stat2 = posix.stat(s, "type");
if (stat2 == nil) then
debugOneLinePrint(s .. " does not exists, creating")
if (not dry) then
posix.mkdir(s)
end
else
debugOneLinePrint(s .. " exists,not creating")
end
end end
s = s.."/"..d
local stat2 = posix.stat(s, "type");
if (stat2 == nil) then
debugOneLinePrint(s.." does not exists, creating")
if (not dry) then
posix.mkdir(s)
end
else
debugOneLinePrint(s.." exists,not creating")
end
end
end end
@ -71,283 +71,288 @@ end
-- for readability not indented, todo, indent once tuned -- for readability not indented, todo, indent once tuned
function M.mainProgram(arg) function M.mainProgram(arg)
debugOneLinePrint("cjc: lua debug on") debugOneLinePrint("cjc: lua debug on")
local caredFiles = {"jre/lib/calendars.properties", local caredFiles = { "jre/lib/calendars.properties",
"jre/lib/content-types.properties", "jre/lib/content-types.properties",
"jre/lib/flavormap.properties", "jre/lib/flavormap.properties",
"jre/lib/logging.properties", "jre/lib/logging.properties",
"jre/lib/net.properties", "jre/lib/net.properties",
"jre/lib/psfontj2d.properties", "jre/lib/psfontj2d.properties",
"jre/lib/sound.properties", "jre/lib/sound.properties",
"jre/lib/deployment.properties", "jre/lib/deployment.properties",
"jre/lib/deployment.config", "jre/lib/deployment.config",
"jre/lib/security/US_export_policy.jar", "jre/lib/security/US_export_policy.jar",
"jre/lib/security/unlimited/US_export_policy.jar", "jre/lib/security/unlimited/US_export_policy.jar",
"jre/lib/security/limited/US_export_policy.jar", "jre/lib/security/limited/US_export_policy.jar",
"jre/lib/security/policy/unlimited/US_export_policy.jar", "jre/lib/security/policy/unlimited/US_export_policy.jar",
"jre/lib/security/policy/limited/US_export_policy.jar", "jre/lib/security/policy/limited/US_export_policy.jar",
"jre/lib/security/java.policy", "jre/lib/security/java.policy",
"jre/lib/security/java.security", "jre/lib/security/java.security",
"jre/lib/security/local_policy.jar", "jre/lib/security/local_policy.jar",
"jre/lib/security/unlimited/local_policy.jar", "jre/lib/security/unlimited/local_policy.jar",
"jre/lib/security/limited/local_policy.jar", "jre/lib/security/limited/local_policy.jar",
"jre/lib/security/policy/unlimited/local_policy.jar", "jre/lib/security/policy/unlimited/local_policy.jar",
"jre/lib/security/policy/limited/local_policy.jar", "jre/lib/security/policy/limited/local_policy.jar",
"jre/lib/security/nss.cfg", "jre/lib/security/nss.cfg",
"jre/lib/security/cacerts", "jre/lib/security/cacerts",
"jre/lib/security/blacklisted.certs", "jre/lib/security/blacklisted.certs",
"jre/lib/security/jssecacerts", "jre/lib/security/jssecacerts",
"jre/lib/security/trusted.certs", "jre/lib/security/trusted.certs",
"jre/lib/security/trusted.jssecerts", "jre/lib/security/trusted.jssecerts",
"jre/lib/security/trusted.clientcerts", "jre/lib/security/trusted.clientcerts",
"jre/lib/ext", "jre/lib/ext",
"jre/lib/security/blacklist", "jre/lib/security/blacklist",
"jre/lib/security/javaws.policy", "jre/lib/security/javaws.policy",
"jre/lib/security/nss.fips.cfg", "jre/lib/security/nss.fips.cfg",
"lib/security", "lib/security",
"conf", "conf",
"lib/ext"} "lib/ext" }
-- before import to allow run from spec -- before import to allow run from spec
if (arg[1] == "--list") then if (arg[1] == "--list") then
for i,file in pairs(caredFiles) do for i, file in pairs(caredFiles) do
print(file) print(file)
end end
return 0; return 0;
end end
-- yum install lua-posix -- yum install lua-posix
local posix = require "posix" local posix = require "posix"
-- the one we are installing -- the one we are installing
local currentjvm = nil local currentjvm = nil
local jvmdir = nil local jvmdir = nil
local jvmDestdir = nil local jvmDestdir = nil
local origname = nil local origname = nil
local origjavaver = nil local origjavaver = nil
local arch = nil local arch = nil
local temp = nil; local temp = nil;
local dry = false; local dry = false;
for i=1,#arg,2 do for i = 1, #arg, 2 do
if (arg[i] == "--help" or arg[i] == "-h") then if (arg[i] == "--help" or arg[i] == "-h") then
print("all but jvmDestdir and debug are mandatory") print("all but jvmDestdir and debug are mandatory")
print(" --currentjvm") print(" --currentjvm")
print(" NVRA of currently installed java") print(" NVRA of currently installed java")
print(" --jvmdir") print(" --jvmdir")
print(" Directory where to find this kind of virtual machine. Generally /usr/lib/jvm") print(" Directory where to find this kind of virtual machine. Generally /usr/lib/jvm")
print(" --origname") print(" --origname")
print(" convinient switch to determine jdk. Generally java-1.X.0-vendor") print(" convinient switch to determine jdk. Generally java-1.X.0-vendor")
print(" --origjavaver") print(" --origjavaver")
print(" convinient switch to determine jdk's version. Generally 1.X.0") print(" convinient switch to determine jdk's version. Generally 1.X.0")
print(" --arch") print(" --arch")
print(" convinient switch to determine jdk's arch") print(" convinient switch to determine jdk's arch")
print(" --jvmDestdir") print(" --jvmDestdir")
print(" Migration/testing switch. Target Mostly same as jvmdir, but you may wont to copy ouside it.") print(" Migration/testing switch. Target Mostly same as jvmdir, but you may wont to copy ouside it.")
print(" --debug") print(" --debug or $debug")
print(" Enables printing out whats going on. true/false. False by default") print(" Enables printing out whats going on. true/false. False by default")
print(" --temp") print(" --temp")
print(" optional file to save intermediate result - directory configs were copied from") print(" optional file to save intermediate result - directory configs were copied from")
print(" --dry") print(" --dry")
print(" true/fase if true, then no changes will be written to disk except one tmp file. False by default") print(" true/fase if true, then no changes will be written to disk except one tmp file. False by default")
print(" **** specil parasm ****") print(" **** specil parasm ****")
print(" --list") print(" --list")
print(" if present on cmdline, list all cared files and exists") print(" if present on cmdline, list all cared files and exists")
os.exit(0) os.exit(0)
end end
if (arg[i] == "--currentjvm") then if (arg[i] == "--currentjvm") then
currentjvm=arg[i+1] currentjvm = arg[i + 1]
end end
if (arg[i] == "--jvmdir") then if (arg[i] == "--jvmdir") then
jvmdir=arg[i+1] jvmdir = arg[i + 1]
end end
if (arg[i] == "--origname") then if (arg[i] == "--origname") then
origname=arg[i+1] origname = arg[i + 1]
end end
if (arg[i] == "--origjavaver") then if (arg[i] == "--origjavaver") then
origjavaver=arg[i+1] origjavaver = arg[i + 1]
end end
if (arg[i] == "--arch") then if (arg[i] == "--arch") then
arch=arg[i+1] arch = arg[i + 1]
end end
if (arg[i] == "--jvmDestdir") then if (arg[i] == "--jvmDestdir") then
jvmDestdir=arg[i+1] jvmDestdir = arg[i + 1]
end end
if (arg[i] == "--debug") then if (arg[i] == "--debug") then
--no string, boolean, workaround --no string, boolean, workaround
if (arg[i+1] == "true") then if (arg[i + 1] == "true") then
debug = true debug = true
end end
end end
if (arg[i] == "--dry") then if (arg[i] == "--dry") then
--no string, boolean, workaround --no string, boolean, workaround
if (arg[i+1] == "true") then if (arg[i + 1] == "true") then
dry = true dry = true
end end
end end
if (arg[i] == "--temp") then if (arg[i] == "--temp") then
temp=arg[i+1] temp = arg[i + 1]
end end
end end
if (jvmDestdir == nil) then if (jvmDestdir == nil) then
jvmDestdir = jvmdir jvmDestdir = jvmdir
end end
if (debug) then
if (debug) then print("--currentjvm:");
print("--currentjvm:"); print(currentjvm);
print(currentjvm); print("--jvmdir:");
print("--jvmdir:"); print(jvmdir);
print(jvmdir); print("--jvmDestdir:");
print("--jvmDestdir:"); print(jvmDestdir);
print(jvmDestdir); print("--origname:");
print("--origname:"); print(origname);
print(origname); print("--origjavaver:");
print("--origjavaver:"); print(origjavaver);
print(origjavaver); print("--arch:");
print("--arch:"); print(arch);
print(arch); print("--debug:");
print("--debug:"); print(debug);
print(debug); end
end
--trasnform substitute names to lua patterns
--trasnform substitute names to lua patterns local name = string.gsub(string.gsub(origname, "%-", "%%-"), "%.", "%%.")
local name = string.gsub(string.gsub(origname, "%-", "%%-"), "%.", "%%.") local javaver = string.gsub(origjavaver, "%.", "%%.")
local javaver = string.gsub(origjavaver, "%.", "%%.")
local jvms = { }
local jvms = { }
debugOneLinePrint("started")
debugOneLinePrint("started")
foundJvms = posix.dir(jvmdir);
if (foundJvms == nil) then
foundJvms = posix.dir(jvmdir); debugOneLinePrint("no, or nothing in " .. jvmdir .. " exit")
if (foundJvms == nil) then return
debugOneLinePrint("no, or nothing in "..jvmdir.." exit") end
return
end debugOneLinePrint("found " .. #foundJvms .. " jvms")
debugOneLinePrint("found "..#foundJvms.." jvms") for i, p in pairs(foundJvms) do
-- regex similar to %{_jvmdir}/%{name}-%{javaver}*%{_arch} bash command
for i,p in pairs(foundJvms) do if (string.find(p, name .. "%-" .. javaver .. ".*" .. arch) ~= nil) then
-- regex similar to %{_jvmdir}/%{name}-%{javaver}*%{_arch} bash command debugOneLinePrint("matched: " .. p)
if (string.find(p, name.."%-"..javaver..".*"..arch) ~= nil ) then if (currentjvm == p) then
debugOneLinePrint("matched: "..p) debugOneLinePrint("this jdk is already installed. exiting lua script")
if (currentjvm == p) then return
debugOneLinePrint("this jdk is already installed. exiting lua script") end ;
return if (string.match(p, ".*-debug$")) then
end ; print(p .. " matched but seems to be debug variant. Skipping")
if (string.match(p, ".*-debug$")) then else
print(p.." matched but seems to be debug variant. Skipping") table.insert(jvms, p)
else end
table.insert(jvms, p) else
end debugOneLinePrint("NOT matched: " .. p)
else end
debugOneLinePrint("NOT matched: "..p) end
end
end if (#jvms <= 0) then
debugOneLinePrint("no matching jdk in " .. jvmdir .. " exit")
if (#jvms <=0) then return
debugOneLinePrint("no matching jdk in "..jvmdir.." exit") end ;
return
end; debugOneLinePrint("matched " .. #jvms .. " jdk in " .. jvmdir)
debugOneLinePrint("matched "..#jvms.." jdk in "..jvmdir) --full names are like java-1.7.0-openjdk-1.7.0.60-2.4.5.1.fc20.x86_64
table.sort(jvms, function(a, b)
--full names are like java-1.7.0-openjdk-1.7.0.60-2.4.5.1.fc20.x86_64 -- version-sort
table.sort(jvms , function(a,b) -- split on non word: . -
-- version-sort local l1 = splitToTable(a, "[^%.-]+")
-- split on non word: . - local l2 = splitToTable(b, "[^%.-]+")
local l1 = splitToTable(a, "[^%.-]+") for x = 1, math.min(#l1, #l2) do
local l2 = splitToTable(b, "[^%.-]+") local l1x = tonumber(l1[x])
for x = 1, math.min(#l1, #l2) do local l2x = tonumber(l2[x])
local l1x = tonumber(l1[x]) if (l1x ~= nil and l2x ~= nil) then
local l2x = tonumber(l2[x]) --if hunks are numbers, go with them
if (l1x ~= nil and l2x ~= nil)then if (l1x < l2x) then
--if hunks are numbers, go with them return true;
if (l1x < l2x) then return true; end end
if (l1x > l2x) then return false; end if (l1x > l2x) then
else return false;
if (l1[x] < l2[x]) then return true; end end
if (l1[x] > l2[x]) then return false; end else
end if (l1[x] < l2[x]) then
-- if hunks are equals then move to another pair of hunks return true;
end end
return a<b if (l1[x] > l2[x]) then
return false;
end) end
end
if (debug) then -- if hunks are equals then move to another pair of hunks
print("sorted lsit of jvms") end
for i,file in pairs(jvms) do return a < b
print(file)
end end)
end
if (debug) then
latestjvm = jvms[#jvms] print("sorted lsit of jvms")
for i, file in pairs(jvms) do
if ( temp ~= nil ) then print(file)
src=jvmdir.."/"..latestjvm end
debugOneLinePrint("temp declared as "..temp.." saving used dir of "..src) end
file = io.open (temp, "w")
file:write(src) latestjvm = jvms[#jvms]
file:close()
end if (temp ~= nil) then
src = jvmdir .. "/" .. latestjvm
debugOneLinePrint("temp declared as " .. temp .. " saving used dir of " .. src)
local readlinkOutput=os.tmpname() file = io.open(temp, "w")
file:write(src)
for i,file in pairs(caredFiles) do file:close()
local SOURCE=jvmdir.."/"..latestjvm.."/"..file end
local DEST=jvmDestdir.."/"..currentjvm.."/"..file
debugOneLinePrint("going to copy "..SOURCE) local readlinkOutput = os.tmpname()
debugOneLinePrint("to "..DEST)
local stat1 = posix.stat(SOURCE, "type"); for i, file in pairs(caredFiles) do
if (stat1 ~= nil) then local SOURCE = jvmdir .. "/" .. latestjvm .. "/" .. file
debugOneLinePrint(SOURCE.." exists") local DEST = jvmDestdir .. "/" .. currentjvm .. "/" .. file
dirWithParents(DEST) debugOneLinePrint("going to copy " .. SOURCE)
-- Copy with -a to keep everything intact debugOneLinePrint("to " .. DEST)
local exe = "cp".." -ar "..SOURCE.." "..DEST local stat1 = posix.stat(SOURCE, "type");
local linkExe = "readlink".." -f "..SOURCE.." > "..readlinkOutput if (stat1 ~= nil) then
debugOneLinePrint("executing "..linkExe) debugOneLinePrint(SOURCE .. " exists")
os.remove(readlinkOutput) dirWithParents(DEST)
os.execute(linkExe) -- Copy with -a to keep everything intact
local link=trim(slurp(readlinkOutput)) local exe = "cp" .. " -ar " .. SOURCE .. " " .. DEST
debugOneLinePrint(" ...link is "..link) local linkExe = "readlink" .. " -f " .. SOURCE .. " > " .. readlinkOutput
if (not ((link) == (SOURCE))) then debugOneLinePrint("executing " .. linkExe)
debugOneLinePrint("WARNING link "..link.." where file "..SOURCE.." expected!") os.remove(readlinkOutput)
debugOneLinePrint("Will try to copy link target rather then link itself!") os.execute(linkExe)
--replacing any NVRA by future NVRA (still execting to have NVRA for any multiple-installable targets local link = trim(slurp(readlinkOutput))
-- lua stubbornly consider dash as inteval. Replacing by dot to match X-Y more correct as X.Y rather then not at all debugOneLinePrint(" ...link is " .. link)
local linkDest=string.gsub(link, latestjvm:gsub("-", "."), currentjvm) if (not ((link) == (SOURCE))) then
debugOneLinePrint("attempting to copy "..link.." to "..linkDest) debugOneLinePrint("WARNING link " .. link .. " where file " .. SOURCE .. " expected!")
if (link == linkDest) then debugOneLinePrint("Will try to copy link target rather then link itself!")
debugOneLinePrint("Those are identical files! Nothing to do!") --replacing any NVRA by future NVRA (still execting to have NVRA for any multiple-installable targets
else -- lua stubbornly consider dash as inteval. Replacing by dot to match X-Y more correct as X.Y rather then not at all
local exe2 = "cp".." -ar "..link.." "..linkDest local linkDest = string.gsub(link, latestjvm:gsub("-", "."), currentjvm)
dirWithParents(linkDest) debugOneLinePrint("attempting to copy " .. link .. " to " .. linkDest)
debugOneLinePrint("executing "..exe2) if (link == linkDest) then
if (not dry) then debugOneLinePrint("Those are identical files! Nothing to do!")
os.execute(exe2) else
local exe2 = "cp" .. " -ar " .. link .. " " .. linkDest
dirWithParents(linkDest)
debugOneLinePrint("executing " .. exe2)
if (not dry) then
os.execute(exe2)
end
end
else
debugOneLinePrint("executing " .. exe)
if (not dry) then
os.execute(exe)
end
end
else
debugOneLinePrint(SOURCE .. " does not exists")
end end
end
else
debugOneLinePrint("executing "..exe)
if (not dry) then
os.execute(exe)
end
end end
else
debugOneLinePrint(SOURCE.." does not exists")
end
end
end --unindented main function end --unindented main function
if (arg == nil) then if (arg == nil) then
debugOneLinePrint("arg variable is nil, you have to call mainProgram manually") -- this can actually not be invoked, as the debug is set via arg debugOneLinePrint("arg variable is nil, you have to call mainProgram manually") -- this can actually not be invoked, as the debug is set via arg
else else
M.mainProgram(arg) M.mainProgram(arg)
end end
return M return M