Blame SOURCES/copy_jdk_configs_fixFiles.sh

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