|
|
1efe36 |
#!/bin/bash
|
|
|
1efe36 |
config=$1
|
|
|
1efe36 |
target=$2
|
|
|
1efe36 |
|
|
|
f603c0 |
debug(){
|
|
|
1efe36 |
if [ "x$debug" == "xtrue" ] ; then
|
|
|
f603c0 |
echo "$@"
|
|
|
1efe36 |
fi
|
|
|
f603c0 |
}
|
|
|
1efe36 |
|
|
|
f603c0 |
debug "cjc: bash debug is on"
|
|
|
f603c0 |
|
|
|
f603c0 |
cmdvDebug() {
|
|
|
1efe36 |
if [ "x$debug" == "xtrue" ] ; then
|
|
|
f603c0 |
"$@" -v
|
|
|
f603c0 |
else
|
|
|
f603c0 |
"$@" 1>/dev/null 2>&1
|
|
|
1efe36 |
fi
|
|
|
1efe36 |
}
|
|
|
1efe36 |
|
|
|
f603c0 |
mvDebug() {
|
|
|
f603c0 |
cmdvDebug mv "$@"
|
|
|
f603c0 |
}
|
|
|
f603c0 |
|
|
|
f603c0 |
rmDebug() {
|
|
|
f603c0 |
cmdvDebug rm "$@"
|
|
|
f603c0 |
}
|
|
|
f603c0 |
|
|
|
f603c0 |
rmdirDebug() {
|
|
|
f603c0 |
cmdvDebug rmdir "$@"
|
|
|
f603c0 |
}
|
|
|
f603c0 |
|
|
|
1efe36 |
#we should be pretty strict about removing once used (even "used" [with fail]) config file, as it may corrupt another installation
|
|
|
1efe36 |
clean(){
|
|
|
1efe36 |
debug "cleanup: removing $config"
|
|
|
f603c0 |
rmDebug -rf $config
|
|
|
1efe36 |
}
|
|
|
1efe36 |
|
|
|
1efe36 |
if [ "x" == "x$config" ] ; then
|
|
|
1efe36 |
debug "no config file specified"
|
|
|
1efe36 |
exit 1
|
|
|
1efe36 |
fi
|
|
|
1efe36 |
|
|
|
1efe36 |
if [ ! -f "$config" ] ; then
|
|
|
1efe36 |
debug "$config file do not exists"
|
|
|
1efe36 |
# expected case, when no migration happened
|
|
|
1efe36 |
exit 0
|
|
|
1efe36 |
fi
|
|
|
1efe36 |
|
|
|
1efe36 |
if [ "x" == "x$target" ] ; then
|
|
|
1efe36 |
debug "no target dir specified"
|
|
|
1efe36 |
clean
|
|
|
1efe36 |
exit 2
|
|
|
1efe36 |
fi
|
|
|
1efe36 |
|
|
|
1efe36 |
if [ ! -d "$target" ] ; then
|
|
|
1efe36 |
debug "$target is not directory"
|
|
|
1efe36 |
clean
|
|
|
1efe36 |
exit 22
|
|
|
1efe36 |
fi
|
|
|
1efe36 |
|
|
|
1efe36 |
source=`cat $config`
|
|
|
1efe36 |
|
|
|
1efe36 |
if [ "x" == "x$source" ] ; then
|
|
|
1efe36 |
debug "no information in $config"
|
|
|
1efe36 |
clean
|
|
|
1efe36 |
exit 3
|
|
|
1efe36 |
fi
|
|
|
1efe36 |
|
|
|
1efe36 |
if [ ! -d "$source" ] ; then
|
|
|
1efe36 |
debug "$source from $config is not directory"
|
|
|
1efe36 |
clean
|
|
|
1efe36 |
exit 33
|
|
|
1efe36 |
fi
|
|
|
1efe36 |
|
|
|
1efe36 |
|
|
|
1efe36 |
listLinks(){
|
|
|
1efe36 |
find $1 -type l -print0 | xargs -0 ls -ld | sed "s; \+-> \+;_->_;g" | sed "s;.* $1;$1;"
|
|
|
1efe36 |
}
|
|
|
1efe36 |
|
|
|
1efe36 |
printIfExists(){
|
|
|
1efe36 |
if [ -e $ffileCandidate ] ; then
|
|
|
1efe36 |
echo $1
|
|
|
1efe36 |
else
|
|
|
1efe36 |
# stdout can be captured, therefore stderr
|
|
|
1efe36 |
debug "skipping not-existing link-target-dir $1" 1>&2
|
|
|
1efe36 |
fi
|
|
|
1efe36 |
}
|
|
|
1efe36 |
|
|
|
1efe36 |
createListOfLinksTargetsDirectories(){
|
|
|
1efe36 |
pushd $source >/dev/null 2>&1
|
|
|
1efe36 |
local links=`listLinks $1`
|
|
|
1efe36 |
for x in $links ; do
|
|
|
1efe36 |
echo "$x" | grep "jre-abrt" > /dev/null
|
|
|
1efe36 |
if [ $? -eq 0 ] ; then
|
|
|
1efe36 |
continue
|
|
|
1efe36 |
fi
|
|
|
1efe36 |
local ffileCandidate=$(echo $x | sed "s/.*_->_//") ;
|
|
|
1efe36 |
# ignoring relative paths as they may lead who know where later
|
|
|
1efe36 |
# there can be simlink relative to position, so push is not catching all
|
|
|
1efe36 |
if [ "$ffileCandidate" != "${ffileCandidate#/}" ] ; then
|
|
|
1efe36 |
if [ -d $ffileCandidate ] ; then
|
|
|
1efe36 |
# should we accept the links to directories themselves?
|
|
|
1efe36 |
printIfExists $ffileCandidate
|
|
|
1efe36 |
else
|
|
|
1efe36 |
printIfExists `dirname $ffileCandidate`
|
|
|
1efe36 |
fi
|
|
|
1efe36 |
fi
|
|
|
1efe36 |
done | sort | uniq
|
|
|
1efe36 |
popd >/dev/null 2>&1
|
|
|
1efe36 |
}
|
|
|
1efe36 |
|
|
|
1efe36 |
sourceLinks=`listLinks $source`
|
|
|
1efe36 |
targetLinks=`listLinks $target`
|
|
|
1efe36 |
sourceLinksDirsTarget=`createListOfLinksTargetsDirectories $source`
|
|
|
1efe36 |
targetLinksDirsTarget=`createListOfLinksTargetsDirectories $target`
|
|
|
1efe36 |
|
|
|
1efe36 |
debug "source: $source"
|
|
|
1efe36 |
debug "target: $target"
|
|
|
1efe36 |
|
|
|
1efe36 |
debug "sourceLinks:
|
|
|
1efe36 |
$sourceLinks"
|
|
|
1efe36 |
debug "targetLinks:
|
|
|
1efe36 |
$targetLinks"
|
|
|
1efe36 |
|
|
|
1efe36 |
debug "sourceLinksDirsTarget:
|
|
|
1efe36 |
$sourceLinksDirsTarget"
|
|
|
1efe36 |
debug "targetLinksDirsTarget:
|
|
|
1efe36 |
$targetLinksDirsTarget"
|
|
|
1efe36 |
|
|
|
1efe36 |
sourceSearchPath="$source $sourceLinksDirsTarget"
|
|
|
1efe36 |
targetSearchPath="$target $targetLinksDirsTarget"
|
|
|
1efe36 |
|
|
|
1efe36 |
work(){
|
|
|
1efe36 |
if [ "X$1" == "Xrpmnew" -o "X$1" == "Xrpmorig" ] ; then
|
|
|
1efe36 |
debug "Working with $1 (1)"
|
|
|
1efe36 |
else
|
|
|
1efe36 |
debug "unknown parameter: $1"
|
|
|
1efe36 |
return 1
|
|
|
1efe36 |
fi
|
|
|
1efe36 |
|
|
|
1efe36 |
local files=`find $targetSearchPath | grep "\\.$1$"`
|
|
|
1efe36 |
for file in $files ; do
|
|
|
1efe36 |
local sf1=`echo $file | sed "s/\\.$1$//"`
|
|
|
1efe36 |
local sf2=`echo $sf1 | sed "s/$targetName/$srcName/"`
|
|
|
1efe36 |
# was file modified in origianl installation?
|
|
|
1efe36 |
rpm -Vf $source | grep -q $sf2
|
|
|
1efe36 |
if [ $? -gt 0 ] ; then
|
|
|
1efe36 |
if [ "X$1" == "Xrpmnew" ] ; then
|
|
|
1efe36 |
debug "$sf2 was NOT modified, removing possibly corrupted $sf1 and renaming from $file"
|
|
|
f603c0 |
mvDebug -f $file $sf1
|
|
|
1efe36 |
if [ $? -eq 0 ] ; then
|
|
|
1efe36 |
echo "restored $file to $sf1"
|
|
|
1efe36 |
else
|
|
|
f603c0 |
debug "FAILED to restore $file to $sf1"
|
|
|
1efe36 |
fi
|
|
|
1efe36 |
fi
|
|
|
1efe36 |
if [ "X$1" == "Xrpmorig" ] ; then
|
|
|
1efe36 |
debug "$sf2 was NOT modified, removing possibly corrupted $file"
|
|
|
f603c0 |
rmDebug $file
|
|
|
1efe36 |
fi
|
|
|
1efe36 |
else
|
|
|
1efe36 |
debug "$sf2 was modified, keeping $file, and removing the duplicated original"
|
|
|
1efe36 |
# information is now backuped, in new directory anyway. Removing future rpmsave to allow rpm -e
|
|
|
f603c0 |
rmDebug -f $sf2
|
|
|
1efe36 |
# or its corresponding backup
|
|
|
f603c0 |
rmDebug -f $sf2.$1
|
|
|
1efe36 |
fi
|
|
|
1efe36 |
done
|
|
|
1efe36 |
}
|
|
|
1efe36 |
|
|
|
1efe36 |
|
|
|
1efe36 |
srcName=`basename $source`
|
|
|
1efe36 |
targetName=`basename $target`
|
|
|
1efe36 |
|
|
|
1efe36 |
work rpmnew
|
|
|
1efe36 |
work rpmorig
|
|
|
1efe36 |
|
|
|
1efe36 |
debug "Working with rpmorig (2)"
|
|
|
1efe36 |
# simply moving old rpmsaves to new dir
|
|
|
1efe36 |
# fix for config (replace) leftovers
|
|
|
1efe36 |
files=`find $sourceSearchPath | grep "\\.rpmorig$"`
|
|
|
1efe36 |
for file in $files ; do
|
|
|
1efe36 |
rpmsaveTarget=`echo $file | sed "s/$srcName/$targetName/"`
|
|
|
1efe36 |
debug "relocating $file to $rpmsaveTarget"
|
|
|
1efe36 |
if [ -e $rpmsaveTarget ] ; then
|
|
|
f603c0 |
rmDebug $file
|
|
|
1efe36 |
else
|
|
|
f603c0 |
mvDebug $file $rpmsaveTarget
|
|
|
1efe36 |
fi
|
|
|
1efe36 |
done
|
|
|
1efe36 |
|
|
|
1efe36 |
debug "Working with rpmsave (1)"
|
|
|
1efe36 |
files=`find $sourceSearchPath | grep "\\.rpmsave$"`
|
|
|
1efe36 |
for file in $files ; do
|
|
|
1efe36 |
rpmsaveTarget=`echo $file | sed "s/$srcName/$targetName/"`
|
|
|
1efe36 |
debug "relocating $file to $rpmsaveTarget"
|
|
|
1efe36 |
if [ -e $rpmsaveTarget ] ; then
|
|
|
f603c0 |
rmDebug $file
|
|
|
1efe36 |
else
|
|
|
f603c0 |
mvDebug $file $rpmsaveTarget
|
|
|
1efe36 |
fi
|
|
|
1efe36 |
done
|
|
|
1efe36 |
|
|
|
1efe36 |
|
|
|
1efe36 |
#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
|
|
|
1efe36 |
#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
|
|
|
1efe36 |
#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
|
|
|
1efe36 |
#those dirs might be mepty by installtion, filling to not be rmeoved later
|
|
|
1efe36 |
#use exported CJC_BLACKDIRS_ADD to extend it in runtime/spec file
|
|
|
1efe36 |
blackdirs=""
|
|
|
1efe36 |
internal_blackdirs="jre/lib/applet jre/lib/*/client jre/lib/locale/*/LC_MESSAGES jre/lib/*/xawt jre/javaws properties/version properties jre/lib/endorsed jre/lib/boot lib/missioncontrol/p2/org.eclipse.equinox.p2.engine/profileRegistry/JMC.profile/.data"
|
|
|
1efe36 |
for x in $internal_blackdirs $CJC_BLACKDIRS_ADD ; do
|
|
|
1efe36 |
blackdirs="$blackdirs $source/$x"
|
|
|
1efe36 |
done
|
|
|
1efe36 |
|
|
|
1efe36 |
for blackdir in $blackdirs; do
|
|
|
1efe36 |
if [ -e $blackdir ] ; then
|
|
|
1efe36 |
debug "nasty $blackdir exists, filling"
|
|
|
1efe36 |
touch $blackdir/C-J-C_placeholder
|
|
|
1efe36 |
else
|
|
|
1efe36 |
debug "nasty $blackdir DONT exists, ignoring"
|
|
|
1efe36 |
fi
|
|
|
1efe36 |
done
|
|
|
1efe36 |
|
|
|
1efe36 |
debug "cleaning legacy leftowers"
|
|
|
1efe36 |
if [ "x$debug" == "xtrue" ] ; then
|
|
|
1efe36 |
find $sourceSearchPath -empty -type d -delete
|
|
|
1efe36 |
else
|
|
|
1efe36 |
find $sourceSearchPath -empty -type d -delete 2>/dev/null >/dev/null
|
|
|
1efe36 |
fi
|
|
|
f603c0 |
rmdirDebug $sourceSearchPath
|
|
|
1efe36 |
|
|
|
1efe36 |
# and remove placeholders
|
|
|
1efe36 |
for blackdir in $blackdirs; do
|
|
|
1efe36 |
if [ -e $blackdir ] ; then
|
|
|
1efe36 |
debug "nasty $blackdir exists, cleaning placeholder"
|
|
|
f603c0 |
rmDebug $blackdir/C-J-C_placeholder
|
|
|
1efe36 |
else
|
|
|
1efe36 |
debug "nasty $blackdir DONT exists, ignoring again"
|
|
|
1efe36 |
fi
|
|
|
1efe36 |
done
|
|
|
1efe36 |
|
|
|
1efe36 |
clean
|
|
|
f603c0 |
|
|
|
f603c0 |
exit 0
|