#!/bin/sh
IMGDIR=/var/lib/brocken
IMGTARGET=/var/tmp/brocken
mkdir -p ${IMGTARGET}

rsync -a ${IMGDIR}/* ${IMGTARGET}

cd $IMGDIR
SAVELIST=$(mktemp)
for l in $(find . -type l) ; do
   readlink $l >> $SAVELIST
done

for j in $(find . -type f) ; do
  if ! grep -q $(basename $j) $SAVELIST ; then
    rm $j
#  else
#    echo "Keep file $j where it is"
  fi 
done
