#!/bin/bash

INSTALL_ROOT=${1:-}
SORCERY_INSTALL_LOG=$INSTALL_ROOT/etc/sorcery/install.log
if ! test -f $SORCERY_INSTALL_LOG ; then
  echo "sorcery install log not found"
  exit 1
fi
echo "removing files"
sort $SORCERY_INSTALL_LOG|grep -v $SORCERY_INSTALL_LOG|while read file; do
  if test -f $file || test -h $file ; then
    rm $file
  fi
done

echo "removing empty directories"
sort -r $SORCERY_INSTALL_LOG|while read file; do
  if test -d $file ; then
    rmdir $file 2>/dev/null
  fi
done
rm -f $SORCERY_INSTALL_LOG
true
