Updated to 2.0

This commit is contained in:
Jiri 2017-01-20 11:21:01 +01:00
parent 5ab2a1f2e5
commit e26b095daf
3 changed files with 122 additions and 8 deletions

View File

@ -1,17 +1,21 @@
%global project copy_jdk_configs %global project copy_jdk_configs
%global file %{project}.lua %global file %{project}.lua
%global fixFile %{project}_fixFiles.sh
%global rpm_state_dir %{_localstatedir}/lib/rpm-state %global rpm_state_dir %{_localstatedir}/lib/rpm-state
Name: copy-jdk-configs Name: copy-jdk-configs
Version: 1.1 # hash relevant to version tag
Release: 3%{?dist} %global htag 3f9d6c4448f867a95fb166416a41c45c7e795c10
Version: 2.0
Release: 1%{?dist}
Summary: JDKs configuration files copier Summary: JDKs configuration files copier
License: BSD License: BSD
URL: https://hg.fedorahosted.org/hg/%{project} URL: https://pagure.io/%{project}
Source0: https://hg.fedorahosted.org/hg/copy_jdk_configs/raw-file/%{project}-%{version}/%{file} Source0: %{URL}/blob/%{htag}/f/%{file}
Source1: https://hg.fedorahosted.org/hg/copy_jdk_configs/raw-file/%{project}-%{version}/LICENSE 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) # 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) %global pretrans_install %(cat %{SOURCE0} | sed s/%%/%%%%/g | sed s/\\^%%%%/^%%/g)
@ -23,7 +27,7 @@ Requires: lua-posix
%description %description
Utility script to transfer JDKs configuration files between updates or for Utility script to transfer JDKs configuration files between updates or for
archiving. archiving. With script to fix incorrectly created rpmnew files
%prep %prep
cp -a %{SOURCE1} . cp -a %{SOURCE1} .
@ -55,6 +59,7 @@ end
%install %install
mkdir -p $RPM_BUILD_ROOT/%{_libexecdir} mkdir -p $RPM_BUILD_ROOT/%{_libexecdir}
cp -a %{SOURCE0} $RPM_BUILD_ROOT/%{_libexecdir}/%{file} cp -a %{SOURCE0} $RPM_BUILD_ROOT/%{_libexecdir}/%{file}
cp -a %{SOURCE2} $RPM_BUILD_ROOT/%{_libexecdir}/%{fixFile}
%posttrans %posttrans
# remove file created in pretrans # remove file created in pretrans
@ -63,9 +68,16 @@ rm "%{rpm_state_dir}/%{file}" || :
%files %files
%{_libexecdir}/%{file} %{_libexecdir}/%{file}
%{_libexecdir}/%{fixFile}
%license LICENSE %license LICENSE
%changelog %changelog
* Fri Jan 20 2017 Jiri Vanek <jvanek@redhat.com> - 2.0-1
- moved to new upstream at pagure.io
- moved to newest release 2.0
- added new script of copy_jdk_configs_fixFiles.sh
- copy_jdk_configs.lua aligned to it
* Fri Jan 08 2016 Jiri Vanek <jvanek@redhat.com> - 1.1-3 * Fri Jan 08 2016 Jiri Vanek <jvanek@redhat.com> - 1.1-3
- pretrasn lua call now done in pcall (protected call) - pretrasn lua call now done in pcall (protected call)
- also posttrans now always return 0 - also posttrans now always return 0

View File

@ -15,6 +15,7 @@ local origname = nil
local origjavaver = nil local origjavaver = nil
local arch = nil local arch = nil
local debug = false; local debug = false;
local temp = nil;
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
@ -33,6 +34,8 @@ for i=1,#arg,2 do
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")
print(" Enables printing out whats going on. true/false") 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) os.exit(0)
end end
if (arg[i] == "--currentjvm") then if (arg[i] == "--currentjvm") then
@ -59,9 +62,12 @@ for i=1,#arg,2 do
debug = true debug = true
end end
end end
if (arg[i] == "--temp") then
temp=arg[i+1]
end
end end
if (jvmDestdir == nill) then if (jvmDestdir == nil) then
jvmDestdir = jvmdir jvmDestdir = jvmdir
end end
@ -103,7 +109,8 @@ local caredFiles = {"jre/lib/calendars.properties",
"jre/lib/security/java.policy", "jre/lib/security/java.policy",
"jre/lib/security/java.security", "jre/lib/security/java.security",
"jre/lib/security/local_policy.jar", "jre/lib/security/local_policy.jar",
"jre/lib/security/nss.cfg,", "jre/lib/security/nss.cfg",
"jre/lib/security/cacerts",
"jre/lib/ext"} "jre/lib/ext"}
function splitToTable(source, pattern) function splitToTable(source, pattern)
@ -194,6 +201,16 @@ end
latestjvm = jvms[#jvms] 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 for i,file in pairs(caredFiles) do
local SOURCE=jvmdir.."/"..latestjvm.."/"..file local SOURCE=jvmdir.."/"..latestjvm.."/"..file

85
copy_jdk_configs_fixFiles.sh Executable file
View File

@ -0,0 +1,85 @@
#!/bin/bash
config=$1
target=$2
debug="false"
#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
}
debug(){
if [ "x$debug" == "xtrue" ] ; then
echo "$1"
fi
}
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"
srcName=`basename $source`
targetName=`basename $target`
files=`find $target | grep "\\.rpmnew$"`
for file in $files ; do
sf1=`echo $file | sed "s/\\.rpmnew$//"`
sf2=`echo $sf1 | sed "s/$targetName/$srcName/"`
# was file modified in origianl installation?
rpm -Vf $source | grep -q $sf2
if [ $? -gt 0 ] ; then
debug "$sf2 was NOT modified, removing possibly corrupted $sf1 and renaming $file"
rm $sf1
mv $file $sf1
if [ $? -eq 0 ] ; then
echo "restored $file to $sf1"
else
echo "FAILED to restore $file to $sf1"
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 $sf2
# or its corresponding backup
rm $sf2.rpmnew
fi
done
clean