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/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..b93477c --- /dev/null +++ b/SOURCES/copy_jdk_configs.lua @@ -0,0 +1,324 @@ +#!/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 + +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", + "jre/lib/security/blacklist", + "jre/lib/security/javaws.policy", + "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" + +-- 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; +local dry = false; + +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. 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 + 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] == "--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 +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 + +local function debugOneLinePrint(string) + if (debug) then + print(string) + end; +end + + +--trasnform substitute names to lua patterns +local name = string.gsub(string.gsub(origname, "%-", "%%-"), "%.", "%%.") +local javaver = string.gsub(origjavaver, "%.", "%%.") + +local jvms = { } + +function getPath(str,sep) + sep=sep or '/' + return str:match("(.*"..sep..")") +end + +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 + +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 + debugOneLinePrint("no, or nothing in "..jvmdir.." exit") + return +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 + debugOneLinePrint("matched: "..p) + if (currentjvm == p) then + debugOneLinePrint("this jdk is already installed. exiting lua script") + 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 + debugOneLinePrint("NOT matched: "..p) + end +end + +if (#jvms <=0) then + debugOneLinePrint("no matching jdk in "..jvmdir.." exit") + return +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) +-- 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 "..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 + debugOneLinePrint(SOURCE.." does not exists") + end +end diff --git a/SOURCES/copy_jdk_configs_fixFiles.sh b/SOURCES/copy_jdk_configs_fixFiles.sh new file mode 100755 index 0000000..964f607 --- /dev/null +++ b/SOURCES/copy_jdk_configs_fixFiles.sh @@ -0,0 +1,224 @@ +#!/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 + + +listLinks(){ + find $1 -type l -print0 | xargs -0 ls -ld | sed "s; \+-> \+;_->_;g" | sed "s;.* $1;$1;" +} + +printIfExists(){ + if [ -e $ffileCandidate ] ; then + echo $1 + else + # stdout can be captured, therefore stderr + debug "skipping not-existing link-target-dir $1" 1>&2 + fi +} + +createListOfLinksTargetsDirectories(){ + pushd $source >/dev/null 2>&1 + local links=`listLinks $1` + for x in $links ; do + echo "$x" | grep "jre-abrt" > /dev/null + if [ $? -eq 0 ] ; then + continue + fi + 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? + printIfExists $ffileCandidate + else + printIfExists `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)" + else + debug "unknown parameter: $1" + return 1 + fi + + 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/"` + # 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" + mv $rma -f $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 $sourceSearchPath | 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 $sourceSearchPath | 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 +#warning: file /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.171-2.6.13.2.el7.x86_64/jre/lib/amd64/xawt: 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 $source/jre/lib/locale/*/LC_MESSAGE $source/jre/lib/*/xawt" +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 $sourceSearchPath -empty -type d -delete + rmdir $rma $sourceSearchPath +else + find $sourceSearchPath -empty -type d -delete 2>/dev/null >/dev/null + rmdir $rma $sourceSearchPath 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/SPECS/copy-jdk-configs.spec b/SPECS/copy-jdk-configs.spec new file mode 100644 index 0000000..6d6c08d --- /dev/null +++ b/SPECS/copy-jdk-configs.spec @@ -0,0 +1,136 @@ +%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 ed45a7dce13fab490529d4d13a064d379c8f66e7 +Version: 3.3 +Release: 10%{?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} + +# 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 +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} +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 +* Mon Apr 30 2018 Jiri Vanek - 3.3-10 +- added javaws.policy and blacklist +- Resolves: rhbz#1573163 + +* Wed Apr 25 2018 Jiri Vanek - 3.3-3 +- fixes issue when java.security for openjdk7 was erased +- Resolves: rhbz#1573163 + +* 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 +- Resolves: rhbz#1427463 + +* Tue Jun 13 2017 Jiri Vanek - 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 + +* Thu Dec 01 2016 Jiri Vanek - 1.3-1 +- updated to upstream 1.3 (adding jre/lib/security/cacerts file) +- Resolves: rhbz#1399719 + +* Tue Aug 09 2016 Jiri Vanek - 1.2-1 +- updated to 1,3 which fixing nss minor issue +- Resolves: rhbz#1296430 + +* Tue Jul 12 2016 Jiri Vanek - 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 - 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 - 1.1-3 +- inital commit to rhel +- Resolves: rhbz#1296430 + +* Fri Jan 08 2016 Jiri Vanek - 1.1-3 +- pretrasn lua call now done in pcall (protected call) +- also posttrans now always return 0 + +* Wed Dec 16 2015 Jiri Vanek - 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 - 1.1-1 +- initial package