diff --git a/SOURCES/copy_jdk_configs.lua b/SOURCES/copy_jdk_configs.lua index 02b94b3..1ec1321 100755 --- a/SOURCES/copy_jdk_configs.lua +++ b/SOURCES/copy_jdk_configs.lua @@ -4,6 +4,43 @@ --test call --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 +local caredFiles = {"jre/lib/calendars.properties", + "jre/lib/content-types.properties", + "jre/lib/flavormap.properties", + "jre/lib/logging.properties", + "jre/lib/net.properties", + "jre/lib/psfontj2d.properties", + "jre/lib/sound.properties", + "jre/lib/deployment.properties", + "jre/lib/deployment.config", + "jre/lib/security/US_export_policy.jar", + "jre/lib/security/unlimited/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/limited/US_export_policy.jar", + "jre/lib/security/java.policy", + "jre/lib/security/java.security", + "jre/lib/security/local_policy.jar", + "jre/lib/security/unlimited/local_policy.jar", + "jre/lib/security/limited/local_policy.jar", + "jre/lib/security/policy/unlimited/local_policy.jar", + "jre/lib/security/policy/limited/local_policy.jar", + "jre/lib/security/nss.cfg", + "jre/lib/security/cacerts", + "jre/lib/security/blacklisted.certs", + "jre/lib/ext", + "lib/security", + "conf", + "lib/ext"} + +-- before import to allow run from spec +if (arg[1] == "--list") then + for i,file in pairs(caredFiles) do + print(file) + end + return 0; +end + -- yum install lua-posix local posix = require "posix" @@ -16,6 +53,7 @@ local origjavaver = nil local arch = nil local debug = false; local temp = nil; +local dry = false; for i=1,#arg,2 do if (arg[i] == "--help" or arg[i] == "-h") then @@ -33,9 +71,14 @@ for i=1,#arg,2 do print(" --jvmDestdir") print(" Migration/testing switch. Target Mostly same as jvmdir, but you may wont to copy ouside it.") print(" --debug") - print(" Enables printing out whats going on. true/false") + print(" Enables printing out whats going on. true/false. False by default") print(" --temp") print(" optional file to save intermediate result - directory configs were copied from") + print(" --dry") + print(" true/fase if true, then no changes will be written to disk except one tmp file. False by default") + print(" **** specil parasm ****") + print(" --list") + print(" if present on cmdline, list all cared files and exists") os.exit(0) end if (arg[i] == "--currentjvm") then @@ -62,6 +105,12 @@ for i=1,#arg,2 do debug = true end end + if (arg[i] == "--dry") then +--no string, boolean, workaround + if (arg[i+1] == "true") then + dry = true + end + end if (arg[i] == "--temp") then temp=arg[i+1] end @@ -89,6 +138,12 @@ if (debug) then print(debug); end +local function debugOneLinePrint(string) + if (debug) then + print(string) + end; +end + --trasnform substitute names to lua patterns local name = string.gsub(string.gsub(origname, "%-", "%%-"), "%.", "%%.") @@ -96,55 +151,10 @@ local javaver = string.gsub(origjavaver, "%.", "%%.") local jvms = { } -local caredFiles = {"jre/lib/calendars.properties", - "jre/lib/content-types.properties", - "jre/lib/flavormap.properties", - "jre/lib/logging.properties", - "jre/lib/net.properties", - "jre/lib/psfontj2d.properties", - "jre/lib/sound.properties", - "jre/lib/deployment.properties", - "jre/lib/deployment.config", - "jre/lib/security/US_export_policy.jar", - "jre/lib/security/java.policy", - "jre/lib/security/java.security", - "jre/lib/security/local_policy.jar", - "jre/lib/security/nss.cfg", - "jre/lib/security/cacerts", - "jre/lib/security/blacklisted.certs", - "jre/lib/ext", - "lib/calendars.properties", - "lib/content-types.properties", - "lib/flavormap.properties", - "lib/logging.properties", - "lib/net.properties", - "lib/psfontj2d.properties", - "lib/sound.properties", - "lib/deployment.properties", - "lib/deployment.config", - "lib/security/US_export_policy.jar", - "lib/security/java.policy", - "lib/security/java.security", - "lib/security/local_policy.jar", - "lib/security/nss.cfg", - "lib/security/cacerts", - "lib/security/blacklisted.certs", - "lib/security/default.policy", - "conf/security/policy/limited/exempt_local.policy", - "conf/security/policy/limited/default_local.policy", - "conf/security/policy/limited/default_US_export.policy", - "conf/security/policy/unlimited/default_local.policy", - "conf/security/policy/unlimited/default_US_export.policy", - "conf/security/java.policy", - "conf/security/java.security", - "conf/logging.properties", - "conf/security/nss.cfg", - "conf/management/jmxremote.access", - "conf/management/jmxremote.password.template", - "conf/management/management.properties", - "conf/net.properties", - "conf/sound.properties", - "lib/ext"} +function getPath(str,sep) + sep=sep or '/' + return str:match("(.*"..sep..")") +end function splitToTable(source, pattern) local i1 = string.gmatch(source, pattern) @@ -155,32 +165,55 @@ function splitToTable(source, pattern) return l1 end -if (debug) then - print("started") -end; +local function slurp(path) + local f = io.open(path) + local s = f:read("*a") + f:close() + return s +end + +function trim(s) + return (s:gsub("^%s*(.-)%s*$", "%1")) +end + +local function dirWithParents(path) + local s = "" + local dirs = splitToTable(path, "[^/]+") + for i,d in pairs(dirs) do + if (i == #dirs) then + 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 + + +debugOneLinePrint("started") + foundJvms = posix.dir(jvmdir); if (foundJvms == nil) then - if (debug) then - print("no, or nothing in "..jvmdir.." exit") - end; + debugOneLinePrint("no, or nothing in "..jvmdir.." exit") return end -if (debug) then - print("found "..#foundJvms.."jvms") -end; +debugOneLinePrint("found "..#foundJvms.."jvms") for i,p in pairs(foundJvms) do -- regex similar to %{_jvmdir}/%{name}-%{javaver}*%{_arch} bash command if (string.find(p, name.."%-"..javaver..".*"..arch) ~= nil ) then - if (debug) then - print("matched: "..p) - end; + debugOneLinePrint("matched: "..p) if (currentjvm == p) then - if (debug) then - print("this jdk is already installed. exiting lua script") - end; + debugOneLinePrint("this jdk is already installed. exiting lua script") return end ; if (string.match(p, ".*-debug$")) then @@ -189,22 +222,16 @@ for i,p in pairs(foundJvms) do table.insert(jvms, p) end else - if (debug) then - print("NOT matched: "..p) - end; + debugOneLinePrint("NOT matched: "..p) end end if (#jvms <=0) then - if (debug) then - print("no matching jdk in "..jvmdir.." exit") - end; + debugOneLinePrint("no matching jdk in "..jvmdir.." exit") return end; -if (debug) then - print("matched "..#jvms.." jdk in "..jvmdir) -end; +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) @@ -240,55 +267,56 @@ latestjvm = jvms[#jvms] if ( temp ~= nil ) then src=jvmdir.."/"..latestjvm - if (debug) then - print("temp declared as "..temp.." saving used dir of "..src) - end + debugOneLinePrint("temp declared as "..temp.." saving used dir of "..src) file = io.open (temp, "w") file:write(src) file:close() end +local readlinkOutput=os.tmpname() + for i,file in pairs(caredFiles) do local SOURCE=jvmdir.."/"..latestjvm.."/"..file local DEST=jvmDestdir.."/"..currentjvm.."/"..file - if (debug) then - print("going to copy "..SOURCE) - print("to "..DEST) - end; + debugOneLinePrint("going to copy "..SOURCE) + debugOneLinePrint("to "..DEST) local stat1 = posix.stat(SOURCE, "type"); if (stat1 ~= nil) then - if (debug) then - print(SOURCE.." exists") - end; - local s = "" - local dirs = splitToTable(DEST, "[^/]+") - for i,d in pairs(dirs) do - if (i == #dirs) then - break - end - s = s.."/"..d - local stat2 = posix.stat(s, "type"); - if (stat2 == nil) then - if (debug) then - print(s.." does not exists, creating") - end; - posix.mkdir(s) - else - if (debug) then - print(s.." exists,not creating") - end; - end - end + debugOneLinePrint(SOURCE.." exists") + dirWithParents(DEST) -- Copy with -a to keep everything intact local exe = "cp".." -ar "..SOURCE.." "..DEST - if (debug) then - print("executing "..exe) - end; - os.execute(exe) + local linkExe = "readlink".." -f "..SOURCE.." > "..readlinkOutput + debugOneLinePrint("executing "..linkExe) + os.remove(readlinkOutput) + os.execute(linkExe) + local link=trim(slurp(readlinkOutput)) + debugOneLinePrint(" ...link is "..link) + if (not ((link) == (SOURCE))) then + debugOneLinePrint("WARNING link "..link.." where file "..SOURCE.." expected!") + 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 +-- 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) + debugOneLinePrint("attempting to copy "..link.." to "..linkDest) + if (link == linkDest) then + debugOneLinePrint("Those are identical files! Nothing to do!") + 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 - if (debug) then - print(SOURCE.." does not exists") - end; + debugOneLinePrint(SOURCE.." does not exists") end end diff --git a/SOURCES/copy_jdk_configs_fixFiles.sh b/SOURCES/copy_jdk_configs_fixFiles.sh index d027784..767e2c3 100755 --- a/SOURCES/copy_jdk_configs_fixFiles.sh +++ b/SOURCES/copy_jdk_configs_fixFiles.sh @@ -58,9 +58,51 @@ if [ ! -d "$source" ] ; then exit 33 fi + +listLinks(){ + find $1 -type l -print0 | xargs -0 ls -ld | sed "s;.* $1;$1;" | sed "s; \+;_;g" +} + +createListOfLinksTargetsDirectories(){ + pushd $source >/dev/null 2>&1 + local links=`listLinks $1` + for x in $links ; do + local ffileCandidate=$(echo $x | sed "s/.*_->_//") ; +# ignoring relative paths as they may lead who know where later +# there can be simlink relative to position, so push is not catching all + if [ "$ffileCandidate" != "${ffileCandidate#/}" ] ; then + if [ -d $ffileCandidate ] ; then +# should we accept the links to directories themselves? + echo $ffileCandidate + else + dirname $ffileCandidate + fi + fi + done | sort | uniq + popd >/dev/null 2>&1 +} + +sourceLinks=`listLinks $source` +targetLinks=`listLinks $target` +sourceLinksDirsTarget=`createListOfLinksTargetsDirectories $source` +targetLinksDirsTarget=`createListOfLinksTargetsDirectories $target` + debug "source: $source" debug "target: $target" +debug "sourceLinks: +$sourceLinks" +debug "targetLinks: +$targetLinks" + +debug "sourceLinksDirsTarget: +$sourceLinksDirsTarget" +debug "targetLinksDirsTarget: +$targetLinksDirsTarget" + +sourceSearchPath="$source $sourceLinksDirsTarget" +targetSearchPath="$target $targetLinksDirsTarget" + work(){ if [ "X$1" == "Xrpmnew" -o "X$1" == "Xrpmorig" ] ; then debug "Working with $1 (1)" @@ -69,7 +111,7 @@ work(){ return 1 fi - local files=`find $target | grep "\\.$1$"` + local files=`find $targetSearchPath | grep "\\.$1$"` for file in $files ; do local sf1=`echo $file | sed "s/\\.$1$//"` local sf2=`echo $sf1 | sed "s/$targetName/$srcName/"` @@ -110,7 +152,7 @@ work rpmorig debug "Working with rpmorig (2)" # simply moving old rpmsaves to new dir # fix for config (replace) leftovers -files=`find $source | grep "\\.rpmorig$"` +files=`find $sourceSearchPath | grep "\\.rpmorig$"` for file in $files ; do rpmsaveTarget=`echo $file | sed "s/$srcName/$targetName/"` debug "relocating $file to $rpmsaveTarget" @@ -122,7 +164,7 @@ files=`find $source | grep "\\.rpmorig$"` done debug "Working with rpmsave (1)" -files=`find $source | grep "\\.rpmsave$"` +files=`find $sourceSearchPath | grep "\\.rpmsave$"` for file in $files ; do rpmsaveTarget=`echo $file | sed "s/$srcName/$targetName/"` debug "relocating $file to $rpmsaveTarget" @@ -137,7 +179,7 @@ files=`find $source | grep "\\.rpmsave$"` #warning: file /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64-debug/jre/lib/applet: remove failed: No such file or directory #warning: file /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64-debug/jre/lib/amd64/client: remove failed: No such file or directory #those dirs might be mepty by installtion, filling to not be rmeoved later -blackdirs="$source/jre/lib/applet $source/jre/lib/*/client" +blackdirs="$source/jre/lib/applet $source/jre/lib/*/client $source/jre/lib/locale/*/LC_MESSAGE" for blackdir in $blackdirs; do if [ -e $blackdir ] ; then debug "nasty $blackdir exists, filling" @@ -149,11 +191,11 @@ done debug "cleaning legacy leftowers" if [ "x$debug" == "xtrue" ] ; then - find $source -empty -type d -delete - rmdir $rma $source + find $sourceSearchPath -empty -type d -delete + rmdir $rma $sourceSearchPath else - find $source -empty -type d -delete 2>/dev/null >/dev/null - rmdir $rma $source 2>/dev/null >/dev/null + find $sourceSearchPath -empty -type d -delete 2>/dev/null >/dev/null + rmdir $rma $sourceSearchPath 2>/dev/null >/dev/null fi # and remove placeholders diff --git a/SOURCES/newPolices.patch b/SOURCES/newPolices.patch deleted file mode 100644 index ced8421..0000000 --- a/SOURCES/newPolices.patch +++ /dev/null @@ -1,22 +0,0 @@ -diff --git a/copy_jdk_configs.lua b/copy_jdk_configs.lua -index 801c4d0..426efb3 100755 ---- a/copy_jdk_configs.lua -+++ b/copy_jdk_configs.lua -@@ -14,9 +14,17 @@ local caredFiles = {"jre/lib/calendars.properties", - "jre/lib/deployment.properties", - "jre/lib/deployment.config", - "jre/lib/security/US_export_policy.jar", -+ "jre/lib/security/unlimited/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/limited/US_export_policy.jar", - "jre/lib/security/java.policy", - "jre/lib/security/java.security", - "jre/lib/security/local_policy.jar", -+ "jre/lib/security/unlimited/local_policy.jar", -+ "jre/lib/security/limited/local_policy.jar", -+ "jre/lib/security/policy/unlimited/local_policy.jar", -+ "jre/lib/security/policy/limited/local_policy.jar", - "jre/lib/security/nss.cfg", - "jre/lib/security/cacerts", - "jre/lib/security/blacklisted.certs", diff --git a/SPECS/copy-jdk-configs.spec b/SPECS/copy-jdk-configs.spec index ffbfcae..9c6018d 100644 --- a/SPECS/copy-jdk-configs.spec +++ b/SPECS/copy-jdk-configs.spec @@ -6,9 +6,9 @@ Name: copy-jdk-configs # hash relevant to version tag -%global htag 3f9d6c4448f867a95fb166416a41c45c7e795c10 -Version: 2.2 -Release: 5%{?dist} +%global htag f1cd4541f89ac601873ee16d6aa3b3cb1497f0d5 +Version: 3.3 +Release: 2%{?dist} Summary: JDKs configuration files copier License: BSD @@ -17,8 +17,6 @@ Source0: %{URL}/blob/%{htag}/f/%{file} Source1: %{URL}/blob/%{htag}/f/LICENSE Source2: %{URL}/blob/%{htag}/f/%{fixFile} -Patch1: newPolices.patch - # we need to duplicate msot of the percents in that script so they survive rpm expansion (even in that sed they have to be duplicated) %global pretrans_install %(cat %{SOURCE0} | sed s/%%/%%%%/g | sed s/\\^%%%%/^%%/g) @@ -61,11 +59,6 @@ end %install mkdir -p $RPM_BUILD_ROOT/%{_libexecdir} cp -a %{SOURCE0} $RPM_BUILD_ROOT/%{_libexecdir}/%{file} -pushd $RPM_BUILD_ROOT/%{_libexecdir}/ -patch -p1 < %{PATCH1} -rm -f *.orig -rm -f *.rej -popd chmod 644 $RPM_BUILD_ROOT/%{_libexecdir}/%{file} cp -a %{SOURCE2} $RPM_BUILD_ROOT/%{_libexecdir}/%{fixFile} @@ -80,13 +73,15 @@ rm "%{rpm_state_dir}/%{file}" 2> /dev/null || : %license LICENSE %changelog -* Tue Nov 21 2017 Jiri Vanek - 2.2-5 -- adapted (added policy subdir) patch1: newPolices.patch -- Resolves: rhbz#1513697 - -* Thu Nov 16 2017 Jiri Vanek - 2.2-4 -- added an daplied in install patch1: newPolices.patch -- Resolves: rhbz#1513697 +* Fri Nov 03 2017 Jiri Vanek - 3.3-2 +- added another subdirs for policies files +- Resolves: rhbz#1503647 +- Resolves: rhbz#1503668 + +* Fri Nov 03 2017 Jiri Vanek - 3.3-1 +- updated to 3.3 +- Resolves: rhbz#1503647 +- Resolves: rhbz#1503668 * Mon Jun 19 2017 Jiri Vanek - 2.2-3 - updated to latest head