#!/bin/sh

echo
echo "BECK-2 preprocessor by lcamtuf"
echo "This program prepares battlefield..."
echo "To undo please use 'cleanup' script."
echo

# Assume that user's homepage is into /home/httpd/html/USER...
TARGET=/home/httpd/html/`whoami`

echo -n "Going directly to your www home... "
cd $TARGET &>/dev/null

if [ "$PWD" != "$TARGET" ]; then
  echo "ERROR"
  exit 0
fi

echo "OK"

SUBDIR=x
MAXDIRS=100
CREATED=0

echo -n "Creating $MAXDIRS subdirs... "

HOME=$PWD

while [ $MAXDIRS -ge $CREATED ]; do
  OLDDIR=$PWD
  mkdir $SUBDIR &>/dev/null
  cd $SUBDIR &>/dev/null
  if [ "$PWD" = "$OLDDIR" ]; then
    echo "ERROR"
    exit 0
  fi
  let CREATED=CREATED+1
done

echo "OK"
