#!/bin/sh
#-----------------------------------------------------------------
# setup.sh
#
# this is a small "helper" shell script to help those that have
# shell access to their website setup Jamroom easier.
#
# version 1.1 05/11/2004 by bigguy@jamroom.net
# see http://www.jamroom.net for all things Jamroom!
#-----------------------------------------------------------------
# $Id: setup.sh,v 1.1.1.1 2009/05/30 15:24:18 bigguy Exp $
#-----------------------------------------------------------------

echo
echo "       *** Jamroom Setup Assistant version 1.5 ***"
echo
echo "This script will help \"pre-configure\" a certain number of"
echo "directories for Jamroom, and ensure they are permissioned"
echo "correctly.  You DO NOT need to run this if your PHP install"
echo "is NOT running in PHP Safe Mode - otherwise, you need to run"
echo "this script so Safe Mode permissions are set correctly."
echo "You can re-run this script at any time without affecting"
echo "your current Jamroom install."
echo
echo "How many bands would you like Jamroom to setup support for?"
echo "NOTE:  Jamroom can support more bands at any time even if"
echo "you do not provision for them here."
echo
echo "Here are some recommendations:"
echo "  LARGE SITE: 5000"
echo " MEDIUM SITE: 500"
echo "  SMALL SITE: 25"
echo
echo "(please enter a number or Ctrl-C to quit)"
echo
read band_num

echo
echo "building support and configuring for $band_num bands..."
echo

mkdir compile logs 2>/dev/null

# first make sure we have our directories...
for each_dir in `echo 'uploads media members config'`
do
  if [ -d $each_dir ]
    then

      echo "settings permissions on and verifying $each_dir ... "
      chmod 777 $each_dir

      cd $each_dir
      i=1
      while [ $i -le $band_num ]
      do 
	mkdir $i 2>/dev/null
	chmod 777 $i 2>/dev/null
	i=`expr $i + 1`
      done
      cd ..
      echo 'completed'

    else

      echo
      echo "** ERROR ** - your \"$each_dir\" directory does not exist!"
      echo "your Jamroom installation is corrupt - please"
      echo "re-download and verify your Jamroom installation"
      echo
      exit

  fi
done

echo "settings permissions on config ... "
if [ -d config ]
  then
    chmod 777 config
  else
    echo
    echo "** ERROR ** - your config directory does not exist!"
    echo "your Jamroom installation is corrupt - please"
    echo "re-download and verify your Jamroom installation"
    echo
    exit
fi

echo "settings permissions on compile ... "
if [ -d compile ]
  then
    chmod 777 compile
  else
    echo
    echo "** ERROR ** - your compile directory does not exist!"
    echo "your Jamroom installation is corrupt - please"
    echo "re-download and verify your Jamroom installation"
    echo
    exit
fi

echo "settings permissions on logs ... "
if [ -d logs ]
  then
    chmod 777 logs
  else
    echo
    echo "** ERROR ** - your logs directory does not exist!"
    echo "your Jamroom installation is corrupt - please"
    echo "re-download and verify your Jamroom installation"
    echo
    exit
fi

echo "settings permissions on templates ... "
if [ -d templates ]
  then
    chmod 777 templates
    find templates -type f -print | xargs chmod 666
    find templates -type d -print | xargs chmod 777
  else
    echo
    echo "** ERROR ** - your templates directory does not exist!"
    echo "your Jamroom installation is corrupt - please"
    echo "re-download and verify your Jamroom installation"
    echo
    exit
fi

echo 'completed'

echo
echo 'Your Jamroom has been permissioned correctly'
echo 'please run install.php from your browser now'
echo

