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
9ff854
debug "source: $source"
9ff854
debug "target: $target"
9ff854
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
9ff854
  local files=`find $target | 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"
9ff854
       rm $rma $sf1 
9ff854
       mv $rma $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
9ff854
files=`find $source | 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)"
9ff854
files=`find $source | 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
9ff854
#those dirs might be mepty by installtion, filling to not be rmeoved later
9ff854
blackdirs="$source/jre/lib/applet $source/jre/lib/*/client"
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
9ff854
  find $source -empty -type d -delete
9ff854
  rmdir $rma $source
9ff854
else
9ff854
  find $source -empty -type d -delete 2>/dev/null >/dev/null
9ff854
  rmdir $rma $source 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