Blame SOURCES/copy_jdk_configs_fixFiles.sh

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