|
|
b2e8bb |
#!/usr/bin/lua
|
|
|
b2e8bb |
-- rpm call
|
|
|
b2e8bb |
-- lua -- copy_jdk_configs.lua --currentjvm "%{uniquesuffix %{nil}}" --jvmdir "%{_jvmdir %{nil}}" --origname "%{name}" --origjavaver "%{javaver}" --arch "%{_arch}" --debug true
|
|
|
b2e8bb |
--test call
|
|
|
b2e8bb |
--lua -- copy_jdk_configs.lua --currentjvm "java-1.8.0-openjdk-1.8.0.65-3.b17.fc22.x86_64" --jvmdir "/usr/lib/jvm" --origname "java-1.8.0-openjdk" --origjavaver "1.8.0" --arch "x86_64" --debug true --jvmDestdir /home/jvanek/Desktop
|
|
|
b2e8bb |
|
|
|
b2e8bb |
-- yum install lua-posix
|
|
|
b2e8bb |
local posix = require "posix"
|
|
|
b2e8bb |
|
|
|
b2e8bb |
-- the one we are installing
|
|
|
b2e8bb |
local currentjvm = nil
|
|
|
b2e8bb |
local jvmdir = nil
|
|
|
b2e8bb |
local jvmDestdir = nil
|
|
|
b2e8bb |
local origname = nil
|
|
|
b2e8bb |
local origjavaver = nil
|
|
|
b2e8bb |
local arch = nil
|
|
|
b2e8bb |
local debug = false;
|
|
|
9ff854 |
local temp = nil;
|
|
|
b2e8bb |
|
|
|
b2e8bb |
for i=1,#arg,2 do
|
|
|
b2e8bb |
if (arg[i] == "--help" or arg[i] == "-h") then
|
|
|
b2e8bb |
print("all but jvmDestdir and debug are mandatory")
|
|
|
b2e8bb |
print(" --currentjvm")
|
|
|
b2e8bb |
print(" NVRA of currently installed java")
|
|
|
b2e8bb |
print(" --jvmdir")
|
|
|
b2e8bb |
print(" Directory where to find this kind of virtual machine. Generally /usr/lib/jvm")
|
|
|
b2e8bb |
print(" --origname")
|
|
|
b2e8bb |
print(" convinient switch to determine jdk. Generally java-1.X.0-vendor")
|
|
|
b2e8bb |
print(" --origjavaver")
|
|
|
b2e8bb |
print(" convinient switch to determine jdk's version. Generally 1.X.0")
|
|
|
b2e8bb |
print(" --arch")
|
|
|
b2e8bb |
print(" convinient switch to determine jdk's arch")
|
|
|
b2e8bb |
print(" --jvmDestdir")
|
|
|
b2e8bb |
print(" Migration/testing switch. Target Mostly same as jvmdir, but you may wont to copy ouside it.")
|
|
|
b2e8bb |
print(" --debug")
|
|
|
b2e8bb |
print(" Enables printing out whats going on. true/false")
|
|
|
9ff854 |
print(" --temp")
|
|
|
9ff854 |
print(" optional file to save intermediate result - directory configs were copied from")
|
|
|
b2e8bb |
os.exit(0)
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
if (arg[i] == "--currentjvm") then
|
|
|
b2e8bb |
currentjvm=arg[i+1]
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
if (arg[i] == "--jvmdir") then
|
|
|
b2e8bb |
jvmdir=arg[i+1]
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
if (arg[i] == "--origname") then
|
|
|
b2e8bb |
origname=arg[i+1]
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
if (arg[i] == "--origjavaver") then
|
|
|
b2e8bb |
origjavaver=arg[i+1]
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
if (arg[i] == "--arch") then
|
|
|
b2e8bb |
arch=arg[i+1]
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
if (arg[i] == "--jvmDestdir") then
|
|
|
b2e8bb |
jvmDestdir=arg[i+1]
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
if (arg[i] == "--debug") then
|
|
|
b2e8bb |
--no string, boolean, workaround
|
|
|
b2e8bb |
if (arg[i+1] == "true") then
|
|
|
b2e8bb |
debug = true
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
end
|
|
|
9ff854 |
if (arg[i] == "--temp") then
|
|
|
9ff854 |
temp=arg[i+1]
|
|
|
9ff854 |
end
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
|
|
|
9ff854 |
if (jvmDestdir == nil) then
|
|
|
b2e8bb |
jvmDestdir = jvmdir
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
|
|
|
b2e8bb |
|
|
|
b2e8bb |
if (debug) then
|
|
|
b2e8bb |
print("--currentjvm:");
|
|
|
b2e8bb |
print(currentjvm);
|
|
|
b2e8bb |
print("--jvmdir:");
|
|
|
b2e8bb |
print(jvmdir);
|
|
|
b2e8bb |
print("--jvmDestdir:");
|
|
|
b2e8bb |
print(jvmDestdir);
|
|
|
b2e8bb |
print("--origname:");
|
|
|
b2e8bb |
print(origname);
|
|
|
b2e8bb |
print("--origjavaver:");
|
|
|
b2e8bb |
print(origjavaver);
|
|
|
b2e8bb |
print("--arch:");
|
|
|
b2e8bb |
print(arch);
|
|
|
b2e8bb |
print("--debug:");
|
|
|
b2e8bb |
print(debug);
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
|
|
|
b2e8bb |
|
|
|
b2e8bb |
--trasnform substitute names to lua patterns
|
|
|
b2e8bb |
local name = string.gsub(string.gsub(origname, "%-", "%%-"), "%.", "%%.")
|
|
|
b2e8bb |
local javaver = string.gsub(origjavaver, "%.", "%%.")
|
|
|
b2e8bb |
|
|
|
b2e8bb |
local jvms = { }
|
|
|
b2e8bb |
|
|
|
b2e8bb |
local caredFiles = {"jre/lib/calendars.properties",
|
|
|
b2e8bb |
"jre/lib/content-types.properties",
|
|
|
b2e8bb |
"jre/lib/flavormap.properties",
|
|
|
b2e8bb |
"jre/lib/logging.properties",
|
|
|
b2e8bb |
"jre/lib/net.properties",
|
|
|
b2e8bb |
"jre/lib/psfontj2d.properties",
|
|
|
b2e8bb |
"jre/lib/sound.properties",
|
|
|
b2e8bb |
"jre/lib/deployment.properties",
|
|
|
b2e8bb |
"jre/lib/deployment.config",
|
|
|
b2e8bb |
"jre/lib/security/US_export_policy.jar",
|
|
|
b2e8bb |
"jre/lib/security/java.policy",
|
|
|
b2e8bb |
"jre/lib/security/java.security",
|
|
|
b2e8bb |
"jre/lib/security/local_policy.jar",
|
|
|
b2e8bb |
"jre/lib/security/nss.cfg",
|
|
|
9ff854 |
"jre/lib/security/cacerts",
|
|
|
9ff854 |
"jre/lib/security/blacklisted.certs",
|
|
|
9ff854 |
"jre/lib/ext",
|
|
|
9ff854 |
"lib/calendars.properties",
|
|
|
9ff854 |
"lib/content-types.properties",
|
|
|
9ff854 |
"lib/flavormap.properties",
|
|
|
9ff854 |
"lib/logging.properties",
|
|
|
9ff854 |
"lib/net.properties",
|
|
|
9ff854 |
"lib/psfontj2d.properties",
|
|
|
9ff854 |
"lib/sound.properties",
|
|
|
9ff854 |
"lib/deployment.properties",
|
|
|
9ff854 |
"lib/deployment.config",
|
|
|
9ff854 |
"lib/security/US_export_policy.jar",
|
|
|
9ff854 |
"lib/security/java.policy",
|
|
|
9ff854 |
"lib/security/java.security",
|
|
|
9ff854 |
"lib/security/local_policy.jar",
|
|
|
9ff854 |
"lib/security/nss.cfg",
|
|
|
9ff854 |
"lib/security/cacerts",
|
|
|
9ff854 |
"lib/security/blacklisted.certs",
|
|
|
9ff854 |
"lib/security/default.policy",
|
|
|
9ff854 |
"conf/security/policy/limited/exempt_local.policy",
|
|
|
9ff854 |
"conf/security/policy/limited/default_local.policy",
|
|
|
9ff854 |
"conf/security/policy/limited/default_US_export.policy",
|
|
|
9ff854 |
"conf/security/policy/unlimited/default_local.policy",
|
|
|
9ff854 |
"conf/security/policy/unlimited/default_US_export.policy",
|
|
|
9ff854 |
"conf/security/java.policy",
|
|
|
9ff854 |
"conf/security/java.security",
|
|
|
9ff854 |
"conf/logging.properties",
|
|
|
9ff854 |
"conf/security/nss.cfg",
|
|
|
9ff854 |
"conf/management/jmxremote.access",
|
|
|
9ff854 |
"conf/management/jmxremote.password.template",
|
|
|
9ff854 |
"conf/management/management.properties",
|
|
|
9ff854 |
"conf/net.properties",
|
|
|
9ff854 |
"conf/sound.properties",
|
|
|
9ff854 |
"lib/ext"}
|
|
|
b2e8bb |
|
|
|
b2e8bb |
function splitToTable(source, pattern)
|
|
|
b2e8bb |
local i1 = string.gmatch(source, pattern)
|
|
|
b2e8bb |
local l1 = {}
|
|
|
b2e8bb |
for i in i1 do
|
|
|
b2e8bb |
table.insert(l1, i)
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
return l1
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
|
|
|
b2e8bb |
if (debug) then
|
|
|
b2e8bb |
print("started")
|
|
|
b2e8bb |
end;
|
|
|
b2e8bb |
|
|
|
b2e8bb |
foundJvms = posix.dir(jvmdir);
|
|
|
b2e8bb |
if (foundJvms == nil) then
|
|
|
b2e8bb |
if (debug) then
|
|
|
b2e8bb |
print("no, or nothing in "..jvmdir.." exit")
|
|
|
b2e8bb |
end;
|
|
|
b2e8bb |
return
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
|
|
|
b2e8bb |
if (debug) then
|
|
|
b2e8bb |
print("found "..#foundJvms.."jvms")
|
|
|
b2e8bb |
end;
|
|
|
b2e8bb |
|
|
|
b2e8bb |
for i,p in pairs(foundJvms) do
|
|
|
b2e8bb |
-- regex similar to %{_jvmdir}/%{name}-%{javaver}*%{_arch} bash command
|
|
|
b2e8bb |
if (string.find(p, name.."%-"..javaver..".*"..arch) ~= nil ) then
|
|
|
b2e8bb |
if (debug) then
|
|
|
b2e8bb |
print("matched: "..p)
|
|
|
b2e8bb |
end;
|
|
|
b2e8bb |
if (currentjvm == p) then
|
|
|
b2e8bb |
if (debug) then
|
|
|
b2e8bb |
print("this jdk is already installed. exiting lua script")
|
|
|
b2e8bb |
end;
|
|
|
b2e8bb |
return
|
|
|
b2e8bb |
end ;
|
|
|
9ff854 |
if (string.match(p, ".*-debug$")) then
|
|
|
9ff854 |
print(p.." matched but seems to be debug variant. Skipping")
|
|
|
9ff854 |
else
|
|
|
9ff854 |
table.insert(jvms, p)
|
|
|
9ff854 |
end
|
|
|
b2e8bb |
else
|
|
|
b2e8bb |
if (debug) then
|
|
|
b2e8bb |
print("NOT matched: "..p)
|
|
|
b2e8bb |
end;
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
|
|
|
b2e8bb |
if (#jvms <=0) then
|
|
|
b2e8bb |
if (debug) then
|
|
|
b2e8bb |
print("no matching jdk in "..jvmdir.." exit")
|
|
|
b2e8bb |
end;
|
|
|
b2e8bb |
return
|
|
|
b2e8bb |
end;
|
|
|
b2e8bb |
|
|
|
b2e8bb |
if (debug) then
|
|
|
b2e8bb |
print("matched "..#jvms.." jdk in "..jvmdir)
|
|
|
b2e8bb |
end;
|
|
|
b2e8bb |
|
|
|
b2e8bb |
--full names are like java-1.7.0-openjdk-1.7.0.60-2.4.5.1.fc20.x86_64
|
|
|
b2e8bb |
table.sort(jvms , function(a,b)
|
|
|
b2e8bb |
-- version-sort
|
|
|
b2e8bb |
-- split on non word: . -
|
|
|
b2e8bb |
local l1 = splitToTable(a, "[^%.-]+")
|
|
|
b2e8bb |
local l2 = splitToTable(b, "[^%.-]+")
|
|
|
b2e8bb |
for x = 1, math.min(#l1, #l2) do
|
|
|
b2e8bb |
local l1x = tonumber(l1[x])
|
|
|
b2e8bb |
local l2x = tonumber(l2[x])
|
|
|
b2e8bb |
if (l1x ~= nil and l2x ~= nil)then
|
|
|
b2e8bb |
--if hunks are numbers, go with them
|
|
|
b2e8bb |
if (l1x < l2x) then return true; end
|
|
|
b2e8bb |
if (l1x > l2x) then return false; end
|
|
|
b2e8bb |
else
|
|
|
b2e8bb |
if (l1[x] < l2[x]) then return true; end
|
|
|
b2e8bb |
if (l1[x] > l2[x]) then return false; end
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
-- if hunks are equals then move to another pair of hunks
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
return a
|
|
|
b2e8bb |
|
|
|
b2e8bb |
end)
|
|
|
b2e8bb |
|
|
|
b2e8bb |
if (debug) then
|
|
|
b2e8bb |
print("sorted lsit of jvms")
|
|
|
b2e8bb |
for i,file in pairs(jvms) do
|
|
|
b2e8bb |
print(file)
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
|
|
|
b2e8bb |
latestjvm = jvms[#jvms]
|
|
|
9ff854 |
|
|
|
9ff854 |
if ( temp ~= nil ) then
|
|
|
9ff854 |
src=jvmdir.."/"..latestjvm
|
|
|
9ff854 |
if (debug) then
|
|
|
9ff854 |
print("temp declared as "..temp.." saving used dir of "..src)
|
|
|
9ff854 |
end
|
|
|
9ff854 |
file = io.open (temp, "w")
|
|
|
9ff854 |
file:write(src)
|
|
|
9ff854 |
file:close()
|
|
|
9ff854 |
end
|
|
|
b2e8bb |
|
|
|
b2e8bb |
|
|
|
b2e8bb |
for i,file in pairs(caredFiles) do
|
|
|
b2e8bb |
local SOURCE=jvmdir.."/"..latestjvm.."/"..file
|
|
|
b2e8bb |
local DEST=jvmDestdir.."/"..currentjvm.."/"..file
|
|
|
b2e8bb |
if (debug) then
|
|
|
b2e8bb |
print("going to copy "..SOURCE)
|
|
|
b2e8bb |
print("to "..DEST)
|
|
|
b2e8bb |
end;
|
|
|
b2e8bb |
local stat1 = posix.stat(SOURCE, "type");
|
|
|
b2e8bb |
if (stat1 ~= nil) then
|
|
|
b2e8bb |
if (debug) then
|
|
|
b2e8bb |
print(SOURCE.." exists")
|
|
|
b2e8bb |
end;
|
|
|
b2e8bb |
local s = ""
|
|
|
b2e8bb |
local dirs = splitToTable(DEST, "[^/]+")
|
|
|
b2e8bb |
for i,d in pairs(dirs) do
|
|
|
b2e8bb |
if (i == #dirs) then
|
|
|
b2e8bb |
break
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
s = s.."/"..d
|
|
|
b2e8bb |
local stat2 = posix.stat(s, "type");
|
|
|
b2e8bb |
if (stat2 == nil) then
|
|
|
b2e8bb |
if (debug) then
|
|
|
b2e8bb |
print(s.." does not exists, creating")
|
|
|
b2e8bb |
end;
|
|
|
b2e8bb |
posix.mkdir(s)
|
|
|
b2e8bb |
else
|
|
|
b2e8bb |
if (debug) then
|
|
|
b2e8bb |
print(s.." exists,not creating")
|
|
|
b2e8bb |
end;
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
-- Copy with -a to keep everything intact
|
|
|
b2e8bb |
local exe = "cp".." -ar "..SOURCE.." "..DEST
|
|
|
b2e8bb |
if (debug) then
|
|
|
b2e8bb |
print("executing "..exe)
|
|
|
b2e8bb |
end;
|
|
|
b2e8bb |
os.execute(exe)
|
|
|
b2e8bb |
else
|
|
|
b2e8bb |
if (debug) then
|
|
|
b2e8bb |
print(SOURCE.." does not exists")
|
|
|
b2e8bb |
end;
|
|
|
b2e8bb |
end
|
|
|
b2e8bb |
end
|