Blame SOURCES/copy_jdk_configs_fixFiles.sh

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