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:
parent
988593295e
commit
efdd06373d
@ -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
|
||||||
|
@ -15,12 +15,12 @@ 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)
|
||||||
@ -46,19 +46,19 @@ 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
|
end
|
||||||
s = s.."/"..d
|
s = s .. "/" .. d
|
||||||
local stat2 = posix.stat(s, "type");
|
local stat2 = posix.stat(s, "type");
|
||||||
if (stat2 == nil) then
|
if (stat2 == nil) then
|
||||||
debugOneLinePrint(s.." does not exists, creating")
|
debugOneLinePrint(s .. " does not exists, creating")
|
||||||
if (not dry) then
|
if (not dry) then
|
||||||
posix.mkdir(s)
|
posix.mkdir(s)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
debugOneLinePrint(s.." exists,not creating")
|
debugOneLinePrint(s .. " exists,not creating")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -71,8 +71,8 @@ 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",
|
||||||
@ -106,30 +106,30 @@ local caredFiles = {"jre/lib/calendars.properties",
|
|||||||
"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")
|
||||||
@ -144,7 +144,7 @@ for i=1,#arg,2 do
|
|||||||
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")
|
||||||
@ -156,46 +156,45 @@ for i=1,#arg,2 do
|
|||||||
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:");
|
||||||
@ -210,137 +209,143 @@ if (debug) then
|
|||||||
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);
|
||||||
foundJvms = posix.dir(jvmdir);
|
if (foundJvms == nil) then
|
||||||
if (foundJvms == nil) then
|
debugOneLinePrint("no, or nothing in " .. jvmdir .. " exit")
|
||||||
debugOneLinePrint("no, or nothing in "..jvmdir.." exit")
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
debugOneLinePrint("found "..#foundJvms.." jvms")
|
debugOneLinePrint("found " .. #foundJvms .. " jvms")
|
||||||
|
|
||||||
for i,p in pairs(foundJvms) do
|
for i, p in pairs(foundJvms) do
|
||||||
-- regex similar to %{_jvmdir}/%{name}-%{javaver}*%{_arch} bash command
|
-- regex similar to %{_jvmdir}/%{name}-%{javaver}*%{_arch} bash command
|
||||||
if (string.find(p, name.."%-"..javaver..".*"..arch) ~= nil ) then
|
if (string.find(p, name .. "%-" .. javaver .. ".*" .. arch) ~= nil) then
|
||||||
debugOneLinePrint("matched: "..p)
|
debugOneLinePrint("matched: " .. p)
|
||||||
if (currentjvm == p) then
|
if (currentjvm == p) then
|
||||||
debugOneLinePrint("this jdk is already installed. exiting lua script")
|
debugOneLinePrint("this jdk is already installed. exiting lua script")
|
||||||
return
|
return
|
||||||
end ;
|
end ;
|
||||||
if (string.match(p, ".*-debug$")) then
|
if (string.match(p, ".*-debug$")) then
|
||||||
print(p.." matched but seems to be debug variant. Skipping")
|
print(p .. " matched but seems to be debug variant. Skipping")
|
||||||
else
|
else
|
||||||
table.insert(jvms, p)
|
table.insert(jvms, p)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
debugOneLinePrint("NOT matched: "..p)
|
debugOneLinePrint("NOT matched: " .. p)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if (#jvms <=0) then
|
if (#jvms <= 0) then
|
||||||
debugOneLinePrint("no matching jdk in "..jvmdir.." exit")
|
debugOneLinePrint("no matching jdk in " .. jvmdir .. " exit")
|
||||||
return
|
return
|
||||||
end;
|
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
|
--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)
|
table.sort(jvms, function(a, b)
|
||||||
-- version-sort
|
-- version-sort
|
||||||
-- split on non word: . -
|
-- split on non word: . -
|
||||||
local l1 = splitToTable(a, "[^%.-]+")
|
local l1 = splitToTable(a, "[^%.-]+")
|
||||||
local l2 = splitToTable(b, "[^%.-]+")
|
local l2 = splitToTable(b, "[^%.-]+")
|
||||||
for x = 1, math.min(#l1, #l2) do
|
for x = 1, math.min(#l1, #l2) do
|
||||||
local l1x = tonumber(l1[x])
|
local l1x = tonumber(l1[x])
|
||||||
local l2x = tonumber(l2[x])
|
local l2x = tonumber(l2[x])
|
||||||
if (l1x ~= nil and l2x ~= nil)then
|
if (l1x ~= nil and l2x ~= nil) then
|
||||||
--if hunks are numbers, go with them
|
--if hunks are numbers, go with them
|
||||||
if (l1x < l2x) then return true; end
|
if (l1x < l2x) then
|
||||||
if (l1x > l2x) then return false; end
|
return true;
|
||||||
|
end
|
||||||
|
if (l1x > l2x) then
|
||||||
|
return false;
|
||||||
|
end
|
||||||
else
|
else
|
||||||
if (l1[x] < l2[x]) then return true; end
|
if (l1[x] < l2[x]) then
|
||||||
if (l1[x] > l2[x]) then return false; end
|
return true;
|
||||||
end
|
end
|
||||||
-- if hunks are equals then move to another pair of hunks
|
if (l1[x] > l2[x]) then
|
||||||
|
return false;
|
||||||
end
|
end
|
||||||
return a<b
|
end
|
||||||
|
-- if hunks are equals then move to another pair of hunks
|
||||||
|
end
|
||||||
|
return a < b
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if (debug) then
|
if (debug) then
|
||||||
print("sorted lsit of jvms")
|
print("sorted lsit of jvms")
|
||||||
for i,file in pairs(jvms) do
|
for i, file in pairs(jvms) do
|
||||||
print(file)
|
print(file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
latestjvm = jvms[#jvms]
|
latestjvm = jvms[#jvms]
|
||||||
|
|
||||||
if ( temp ~= nil ) then
|
if (temp ~= nil) then
|
||||||
src=jvmdir.."/"..latestjvm
|
src = jvmdir .. "/" .. latestjvm
|
||||||
debugOneLinePrint("temp declared as "..temp.." saving used dir of "..src)
|
debugOneLinePrint("temp declared as " .. temp .. " saving used dir of " .. src)
|
||||||
file = io.open (temp, "w")
|
file = io.open(temp, "w")
|
||||||
file:write(src)
|
file:write(src)
|
||||||
file:close()
|
file:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local readlinkOutput = os.tmpname()
|
||||||
|
|
||||||
local readlinkOutput=os.tmpname()
|
for i, file in pairs(caredFiles) do
|
||||||
|
local SOURCE = jvmdir .. "/" .. latestjvm .. "/" .. file
|
||||||
for i,file in pairs(caredFiles) do
|
local DEST = jvmDestdir .. "/" .. currentjvm .. "/" .. file
|
||||||
local SOURCE=jvmdir.."/"..latestjvm.."/"..file
|
debugOneLinePrint("going to copy " .. SOURCE)
|
||||||
local DEST=jvmDestdir.."/"..currentjvm.."/"..file
|
debugOneLinePrint("to " .. DEST)
|
||||||
debugOneLinePrint("going to copy "..SOURCE)
|
|
||||||
debugOneLinePrint("to "..DEST)
|
|
||||||
local stat1 = posix.stat(SOURCE, "type");
|
local stat1 = posix.stat(SOURCE, "type");
|
||||||
if (stat1 ~= nil) then
|
if (stat1 ~= nil) then
|
||||||
debugOneLinePrint(SOURCE.." exists")
|
debugOneLinePrint(SOURCE .. " exists")
|
||||||
dirWithParents(DEST)
|
dirWithParents(DEST)
|
||||||
-- Copy with -a to keep everything intact
|
-- Copy with -a to keep everything intact
|
||||||
local exe = "cp".." -ar "..SOURCE.." "..DEST
|
local exe = "cp" .. " -ar " .. SOURCE .. " " .. DEST
|
||||||
local linkExe = "readlink".." -f "..SOURCE.." > "..readlinkOutput
|
local linkExe = "readlink" .. " -f " .. SOURCE .. " > " .. readlinkOutput
|
||||||
debugOneLinePrint("executing "..linkExe)
|
debugOneLinePrint("executing " .. linkExe)
|
||||||
os.remove(readlinkOutput)
|
os.remove(readlinkOutput)
|
||||||
os.execute(linkExe)
|
os.execute(linkExe)
|
||||||
local link=trim(slurp(readlinkOutput))
|
local link = trim(slurp(readlinkOutput))
|
||||||
debugOneLinePrint(" ...link is "..link)
|
debugOneLinePrint(" ...link is " .. link)
|
||||||
if (not ((link) == (SOURCE))) then
|
if (not ((link) == (SOURCE))) then
|
||||||
debugOneLinePrint("WARNING link "..link.." where file "..SOURCE.." expected!")
|
debugOneLinePrint("WARNING link " .. link .. " where file " .. SOURCE .. " expected!")
|
||||||
debugOneLinePrint("Will try to copy link target rather then link itself!")
|
debugOneLinePrint("Will try to copy link target rather then link itself!")
|
||||||
--replacing any NVRA by future NVRA (still execting to have NVRA for any multiple-installable targets
|
--replacing any NVRA by future NVRA (still execting to have NVRA for any multiple-installable targets
|
||||||
-- lua stubbornly consider dash as inteval. Replacing by dot to match X-Y more correct as X.Y rather then not at all
|
-- lua stubbornly consider dash as inteval. Replacing by dot to match X-Y more correct as X.Y rather then not at all
|
||||||
local linkDest=string.gsub(link, latestjvm:gsub("-", "."), currentjvm)
|
local linkDest = string.gsub(link, latestjvm:gsub("-", "."), currentjvm)
|
||||||
debugOneLinePrint("attempting to copy "..link.." to "..linkDest)
|
debugOneLinePrint("attempting to copy " .. link .. " to " .. linkDest)
|
||||||
if (link == linkDest) then
|
if (link == linkDest) then
|
||||||
debugOneLinePrint("Those are identical files! Nothing to do!")
|
debugOneLinePrint("Those are identical files! Nothing to do!")
|
||||||
else
|
else
|
||||||
local exe2 = "cp".." -ar "..link.." "..linkDest
|
local exe2 = "cp" .. " -ar " .. link .. " " .. linkDest
|
||||||
dirWithParents(linkDest)
|
dirWithParents(linkDest)
|
||||||
debugOneLinePrint("executing "..exe2)
|
debugOneLinePrint("executing " .. exe2)
|
||||||
if (not dry) then
|
if (not dry) then
|
||||||
os.execute(exe2)
|
os.execute(exe2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
debugOneLinePrint("executing "..exe)
|
debugOneLinePrint("executing " .. exe)
|
||||||
if (not dry) then
|
if (not dry) then
|
||||||
os.execute(exe)
|
os.execute(exe)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
debugOneLinePrint(SOURCE.." does not exists")
|
debugOneLinePrint(SOURCE .. " does not exists")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
end --unindented main function
|
end --unindented main function
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user