lock_resources "libgrimoire" "install"  &&
if [[ -z $INSTALL_ROOT ]]; then
  mkdir $SOURCE_DIRECTORY.bld/old.libs  &&
  message "${MESSAGE_COLOR}copying old libraries${DEFAULT_COLOR}" &&
  local each  &&
  for each in /lib{,64,32}/*; do
    local dest="${SOURCE_DIRECTORY}.bld/old.libs/${each##*/}" &&
    if ! test -f "${dest}" && test -f "${each}"; then
      cp -a "${each}" "${dest}"
    fi
  done  &&
  message "${MESSAGE_COLOR}Runnning ldconfig${DEFAULT_COLOR}" &&
  ldconfig $SOURCE_DIRECTORY.bld/old.libs  &&
  local LD  &&
  message "${MESSAGE_COLOR}changing ld-linux${DEFAULT_COLOR}" &&
  for each in /lib{,64,32}/ld-linux*; do
    if test -f "$each"; then
      if test -L "$each"; then
        LD=$(readlink $each)
      else
        # glibc > 2.33
        LD=${each}
      fi
      LDB=${LD##*/}
      ln -sf $SOURCE_DIRECTORY.bld/old.libs/$LDB $each
     fi
  done
fi  &&

message "${MESSAGE_COLOR}Dispelling glibc${DEFAULT_COLOR}" &&
if  spell_ok  glibc;  then
  dispel  --notriggers  --nosustain  glibc
fi  &&

message "${MESSAGE_COLOR}cleaning old symlinks${DEFAULT_COLOR}" &&
# clean up symlinks that break stuff, we used to install those
if [[ -h  $INSTALL_ROOT/usr/include/asm ]]; then
  rm -f $INSTALL_ROOT/usr/include/asm
fi  &&
if [[ -h  $INSTALL_ROOT/usr/include/asm-generic ]]; then
  rm -f $INSTALL_ROOT/usr/include/asm-generic
fi  &&
if [[ -h  $INSTALL_ROOT/usr/include/linux ]]; then
  rm -f $INSTALL_ROOT/usr/include/linux
fi &&
true
