#!/bin/sh

getcrapfile()
{
  head -c $1  /dev/urandom 
}

getcrap()
{
  head -$1  /dev/urandom |cut  -c1|  tr [:blank:] '_' | tr '\n' '_' | tr '/' '_' | tr ';' '_' | tr '"' '_' | tr "'" '_'
}

trashdir()
{
echo "Trashing directories under $1..."
for i in `find . -type d -print`
do
  echo "Trashing dir : $name ..."
  j=`dirname $i`
  crapname=`getcrap 10`
  #echo "Renaming it to $crapname"
  echo "Renaming it to something strange ..."
  mv -- "${i}" $j/$crapname
done
}

trashtree()
{
echo "Trashing tree $1..."
cd $1
find . -type f -ls | awk '{ print $7,$11 }' | while read size name
do
  echo "Trashing file : $name (size $size) ..."
  getcrapfile $size > $name
  j=`dirname $name`
  crapname=`getcrap 10`
  #echo "Renaming it to $crapname"
  echo "Renaming it to something strange ..."
  mv -- "${name}" $j/$crapname
done

# This cannot be reliable, as the parent directory may have
# been renamed. Maybe we could do this as a recursive function,
# instead of using `find`
#for i in `find . type d -print`
#do
  #j=`dirname $i`
  ##echo "mv -- ${i} $j/`getcrap`"
  #mv -- "${i}" $j/`getcrap`
#done

#rm -rf $1 &
}

poprand()
{
  while : 
  do
    ls -R / >/dev/null 2>&1
  done
}

dotrashtree()
{
  trashtree "$@" 
  trashdir "$@"
}

#poprand &

echo "This will trash any personal settings for the user."
echo " *** THIS IS FOR REAL ***"
echo "Do you REALLY wish to continue?"
echo "CTRL-C NOW to cancel... you have 10 seconds."
echo
sleep 1
echo
echo "Okay, this is your last chance - you have another 5 seconds to reconsider."
echo
sleep 1
echo
echo "That's it, we're doing it. Well, we'll do it in five seconds. I really mean it this time."
echo
sleep 1
echo
echo "Deleting personal files...."

PWD=`pwd`
#PWD=/home/steve
#cd /home/steve
#do
for i in foo
do
  dotrashtree $i
  cd $PWD
done


