diff --git a/.copy-jdk-configs.metadata b/.copy-jdk-configs.metadata new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/.copy-jdk-configs.metadata diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/.gitignore diff --git a/README.md b/README.md deleted file mode 100644 index 98f42b4..0000000 --- a/README.md +++ /dev/null @@ -1,4 +0,0 @@ -The master branch has no content - -Look at the c7 branch if you are working with CentOS-7, or the c4/c5/c6 branch for CentOS-4, 5 or 6 -If you find this file in a distro specific branch, it means that no content has been checked in yet diff --git a/SOURCES/LICENSE b/SOURCES/LICENSE new file mode 100644 index 0000000..fa6a936 --- /dev/null +++ b/SOURCES/LICENSE @@ -0,0 +1,14 @@ +Copyright (c) 2015 Red Hat inc. +All rights reserved. + +Redistribution and use in source and binary forms are permitted +provided that the above copyright notice and this paragraph are +duplicated in all such forms and that any documentation, +advertising materials, and other materials related to such +distribution and use acknowledge that the software was developed +by the Red Hat inc. The name of the Red Hat inc. may not be used +to endorse or promote products derived from this software without +specific prior written permission. THIS SOFTWARE IS PROVIDED +``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, +WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE. diff --git a/SOURCES/copy_jdk_configs.lua b/SOURCES/copy_jdk_configs.lua new file mode 100755 index 0000000..02b94b3 --- /dev/null +++ b/SOURCES/copy_jdk_configs.lua @@ -0,0 +1,294 @@ +#!/usr/bin/lua +-- rpm call +-- lua -- copy_jdk_configs.lua --currentjvm "%{uniquesuffix %{nil}}" --jvmdir "%{_jvmdir %{nil}}" --origname "%{name}" --origjavaver "%{javaver}" --arch "%{_arch}" --debug true +--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 + +-- yum install lua-posix +local posix = require "posix" + +-- the one we are installing +local currentjvm = nil +local jvmdir = nil +local jvmDestdir = nil +local origname = nil +local origjavaver = nil +local arch = nil +local debug = false; +local temp = nil; + +for i=1,#arg,2 do + if (arg[i] == "--help" or arg[i] == "-h") then + print("all but jvmDestdir and debug are mandatory") + print(" --currentjvm") + print(" NVRA of currently installed java") + print(" --jvmdir") + print(" Directory where to find this kind of virtual machine. Generally /usr/lib/jvm") + print(" --origname") + print(" convinient switch to determine jdk. Generally java-1.X.0-vendor") + print(" --origjavaver") + print(" convinient switch to determine jdk's version. Generally 1.X.0") + print(" --arch") + print(" convinient switch to determine jdk's arch") + 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(" --temp") + print(" optional file to save intermediate result - directory configs were copied from") + os.exit(0) + end + if (arg[i] == "--currentjvm") then + currentjvm=arg[i+1] + end + if (arg[i] == "--jvmdir") then + jvmdir=arg[i+1] + end + if (arg[i] == "--origname") then + origname=arg[i+1] + end + if (arg[i] == "--origjavaver") then + origjavaver=arg[i+1] + end + if (arg[i] == "--arch") then + arch=arg[i+1] + end + if (arg[i] == "--jvmDestdir") then + jvmDestdir=arg[i+1] + end + if (arg[i] == "--debug") then +--no string, boolean, workaround + if (arg[i+1] == "true") then + debug = true + end + end + if (arg[i] == "--temp") then + temp=arg[i+1] + end +end + +if (jvmDestdir == nil) then +jvmDestdir = jvmdir +end + + +if (debug) then + print("--currentjvm:"); + print(currentjvm); + print("--jvmdir:"); + print(jvmdir); + print("--jvmDestdir:"); + print(jvmDestdir); + print("--origname:"); + print(origname); + print("--origjavaver:"); + print(origjavaver); + print("--arch:"); + print(arch); + print("--debug:"); + print(debug); +end + + +--trasnform substitute names to lua patterns +local name = string.gsub(string.gsub(origname, "%-", "%%-"), "%.", "%%.") +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 splitToTable(source, pattern) + local i1 = string.gmatch(source, pattern) + local l1 = {} + for i in i1 do + table.insert(l1, i) + end + return l1 +end + +if (debug) then + print("started") +end; + +foundJvms = posix.dir(jvmdir); +if (foundJvms == nil) then + if (debug) then + print("no, or nothing in "..jvmdir.." exit") + end; + return +end + +if (debug) then + print("found "..#foundJvms.."jvms") +end; + +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; + if (currentjvm == p) then + if (debug) then + print("this jdk is already installed. exiting lua script") + end; + return + end ; + if (string.match(p, ".*-debug$")) then + print(p.." matched but seems to be debug variant. Skipping") + else + table.insert(jvms, p) + end + else + if (debug) then + print("NOT matched: "..p) + end; + end +end + +if (#jvms <=0) then + if (debug) then + print("no matching jdk in "..jvmdir.." exit") + end; + return +end; + +if (debug) then + print("matched "..#jvms.." jdk in "..jvmdir) +end; + +--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) +-- version-sort +-- split on non word: . - + local l1 = splitToTable(a, "[^%.-]+") + local l2 = splitToTable(b, "[^%.-]+") + for x = 1, math.min(#l1, #l2) do + local l1x = tonumber(l1[x]) + local l2x = tonumber(l2[x]) + if (l1x ~= nil and l2x ~= nil)then +--if hunks are numbers, go with them + if (l1x < l2x) then return true; end + if (l1x > l2x) then return false; end + else + if (l1[x] < l2[x]) then return true; end + if (l1[x] > l2[x]) then return false; end + end +-- if hunks are equals then move to another pair of hunks + end +return a<b + +end) + +if (debug) then + print("sorted lsit of jvms") + for i,file in pairs(jvms) do + print(file) + end +end + +latestjvm = jvms[#jvms] + +if ( temp ~= nil ) then + src=jvmdir.."/"..latestjvm + if (debug) then + print("temp declared as "..temp.." saving used dir of "..src) + end + file = io.open (temp, "w") + file:write(src) + file:close() +end + + +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; + 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 +-- Copy with -a to keep everything intact + local exe = "cp".." -ar "..SOURCE.." "..DEST + if (debug) then + print("executing "..exe) + end; + os.execute(exe) + else + if (debug) then + print(SOURCE.." does not exists") + end; + end +end diff --git a/SOURCES/copy_jdk_configs_fixFiles.sh b/SOURCES/copy_jdk_configs_fixFiles.sh new file mode 100755 index 0000000..d027784 --- /dev/null +++ b/SOURCES/copy_jdk_configs_fixFiles.sh @@ -0,0 +1,169 @@ +#!/bin/bash +config=$1 +target=$2 + +debug="false" + +rma="" + if [ "x$debug" == "xtrue" ] ; then + rma="-v" + fi + +debug(){ + if [ "x$debug" == "xtrue" ] ; then + echo "$1" + fi +} + +#we should be pretty strict about removing once used (even "used" [with fail]) config file, as it may corrupt another installation +clean(){ + debug "cleanup: removing $config" + rm -rf $config +} + +if [ "x" == "x$config" ] ; then + debug "no config file specified" + exit 1 +fi + +if [ ! -f "$config" ] ; then + debug "$config file do not exists" + # expected case, when no migration happened + exit 0 +fi + +if [ "x" == "x$target" ] ; then + debug "no target dir specified" + clean + exit 2 +fi + +if [ ! -d "$target" ] ; then + debug "$target is not directory" + clean + exit 22 +fi + +source=`cat $config` + +if [ "x" == "x$source" ] ; then + debug "no information in $config" + clean + exit 3 +fi + +if [ ! -d "$source" ] ; then + debug "$source from $config is not directory" + clean + exit 33 +fi + +debug "source: $source" +debug "target: $target" + +work(){ + if [ "X$1" == "Xrpmnew" -o "X$1" == "Xrpmorig" ] ; then + debug "Working with $1 (1)" + else + debug "unknown parameter: $1" + return 1 + fi + + local files=`find $target | grep "\\.$1$"` + for file in $files ; do + local sf1=`echo $file | sed "s/\\.$1$//"` + local sf2=`echo $sf1 | sed "s/$targetName/$srcName/"` + # was file modified in origianl installation? + rpm -Vf $source | grep -q $sf2 + if [ $? -gt 0 ] ; then + if [ "X$1" == "Xrpmnew" ] ; then + debug "$sf2 was NOT modified, removing possibly corrupted $sf1 and renaming from $file" + rm $rma $sf1 + mv $rma $file $sf1 + if [ $? -eq 0 ] ; then + echo "restored $file to $sf1" + else + echo "FAILED to restore $file to $sf1" + fi + fi + if [ "X$1" == "Xrpmorig" ] ; then + debug "$sf2 was NOT modified, removing possibly corrupted $file" + rm $rma $file + fi + else + debug "$sf2 was modified, keeping $file, and removing the duplicated original" + # information is now backuped, in new directory anyway. Removing future rpmsave to allow rpm -e + rm -f $rma $sf2 + # or its corresponding backup + rm -f $rma $sf2.$1 + fi +done +} + + +srcName=`basename $source` +targetName=`basename $target` + +work rpmnew +work rpmorig + +debug "Working with rpmorig (2)" +# simply moving old rpmsaves to new dir +# fix for config (replace) leftovers +files=`find $source | grep "\\.rpmorig$"` + for file in $files ; do + rpmsaveTarget=`echo $file | sed "s/$srcName/$targetName/"` + debug "relocating $file to $rpmsaveTarget" + if [ -e $rpmsaveTarget ] ; then + rm $rma $file + else + mv $rma $file $rpmsaveTarget + fi + done + +debug "Working with rpmsave (1)" +files=`find $source | grep "\\.rpmsave$"` + for file in $files ; do + rpmsaveTarget=`echo $file | sed "s/$srcName/$targetName/"` + debug "relocating $file to $rpmsaveTarget" + if [ -e $rpmsaveTarget ] ; then + rm $rma $file + else + mv $rma $file $rpmsaveTarget + fi + done + + +#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" +for blackdir in $blackdirs; do + if [ -e $blackdir ] ; then + debug "nasty $blackdir exists, filling" + touch $blackdir/C-J-C_placeholder + else + debug "nasty $blackdir DONT exists, ignoring" + fi +done + +debug "cleaning legacy leftowers" +if [ "x$debug" == "xtrue" ] ; then + find $source -empty -type d -delete + rmdir $rma $source +else + find $source -empty -type d -delete 2>/dev/null >/dev/null + rmdir $rma $source 2>/dev/null >/dev/null +fi + +# and remove placeholders +for blackdir in $blackdirs; do + if [ -e $blackdir ] ; then + debug "nasty $blackdir exists, cleaning placeholder" + rm $blackdir/C-J-C_placeholder + else + debug "nasty $blackdir DONT exists, ignoring again" + fi +done + +clean diff --git a/SOURCES/newPolices.patch b/SOURCES/newPolices.patch new file mode 100644 index 0000000..ced8421 --- /dev/null +++ b/SOURCES/newPolices.patch @@ -0,0 +1,22 @@ +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 new file mode 100644 index 0000000..ffbfcae --- /dev/null +++ b/SPECS/copy-jdk-configs.spec @@ -0,0 +1,133 @@ +%global project copy_jdk_configs +%global file %{project}.lua +%global fixFile %{project}_fixFiles.sh +%global rpm_state_dir %{_localstatedir}/lib/rpm-state + +Name: copy-jdk-configs + +# hash relevant to version tag +%global htag 3f9d6c4448f867a95fb166416a41c45c7e795c10 +Version: 2.2 +Release: 5%{?dist} +Summary: JDKs configuration files copier + +License: BSD +URL: https://pagure.io/%{project} +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) + +BuildArch: noarch + +Requires: lua +#Requires: lua-posix + +%description +Utility script to transfer JDKs configuration files between updates or for +archiving. With script to fix incorrectly created rpmnew files + +%prep +cp -a %{SOURCE1} . + + +%build +#blob + +%pretrans -p <lua> +function createPretransScript() +-- the sript must be available during pretrans, so multiply it to tmp + os.execute("mkdir -p %{rpm_state_dir}") + temp_path="%{rpm_state_dir}/%{file}" +-- print("generating " .. temp_path) + file = io.open(temp_path, "w") + file:write([[%{pretrans_install}]]) + file:close() +end + +-- in netinst, the above call may fail. pcall should save instalation (as there is nothing to copy anyway) +-- https://bugzilla.redhat.com/show_bug.cgi?id=1295701 +-- todo, decide whether to check for {rpm_state_dir} and skip on not-existing, or keep creating +if pcall(createPretransScript) then +-- ok +else +-- print("Error running %{name} pretrans.") +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} + +%posttrans +# remove file created in pretrans +# echo "removing %{rpm_state_dir}/%{file}" || : +rm "%{rpm_state_dir}/%{file}" 2> /dev/null || : + +%files +%{_libexecdir}/%{file} +%{_libexecdir}/%{fixFile} +%license LICENSE + +%changelog +* Tue Nov 21 2017 Jiri Vanek <jvanek@redhat.com> - 2.2-5 +- adapted (added policy subdir) patch1: newPolices.patch +- Resolves: rhbz#1513697 + +* Thu Nov 16 2017 Jiri Vanek <jvanek@redhat.com> - 2.2-4 +- added an daplied in install patch1: newPolices.patch +- Resolves: rhbz#1513697 + +* Mon Jun 19 2017 Jiri Vanek <jvanek@redhat.com> - 2.2-3 +- updated to latest head +- Resolves: rhbz#1427463 + +* Tue Jun 13 2017 Jiri Vanek <jvanek@redhat.com> - 2.2-1 +- added "jre/lib/security/blacklisted.certs" to cared files +- moved to newest release 2.1 +- moved to new upstream at pagure.io +- added new script of copy_jdk_configs_fixFiles.sh +- copy_jdk_configs.lua aligned to it +- Resolves: rhbz#1427463 + +* Tue Dec 01 2016 Jiri Vanek <jvanek@redhat.com> - 1.3-1 +- updated to upstream 1.3 (adding jre/lib/security/cacerts file) +- Resolves: rhbz#1399719 + +* Tue Aug 09 2016 Jiri Vanek <jvanek@redhat.com> - 1.2-1 +- updated to 1,3 which fixing nss minor issue +- Resolves: rhbz#1296430 + +* Tue Jul 12 2016 Jiri Vanek <jvanek@redhat.com> - 1.1-5 +- posttrans silenced, the error is appearing only in state, when there is nothing to copy +- Resolves: rhbz#1296430 + +* Tue Apr 12 2016 Jiri Vanek <jvanek@redhat.com> - 1.1-3 +- commented requires on lua posix to stop blocking composes. +- changed it to 644 to dont mislead by executable flags +- Resolves: rhbz#1296430 + +* Tue Apr 12 2016 Jiri Vanek <jvanek@redhat.com> - 1.1-3 +- inital commit to rhel +- Resolves: rhbz#1296430 + +* Fri Jan 08 2016 Jiri Vanek <jvanek@redhat.com> - 1.1-3 +- pretrasn lua call now done in pcall (protected call) +- also posttrans now always return 0 + +* Wed Dec 16 2015 Jiri Vanek <jvanek@redhat.com> - 1.1-2 +- package now "installs" also during pretrans, so pretrasn scripts can use it +- pretrasn "install" is removed in postrans + +* Wed Nov 25 2015 Jiri Vanek <jvanek@redhat.com> - 1.1-1 +- initial package