Blame SOURCES/copy_jdk_configs_fixFiles.sh

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