#!/bin/sh


if [ -z "$1" ]; then
	echo -e "Welcome to sfa-perm script\n\n  This script will set your permissions right.\n use it in your sitename dir\n\n usage: ./sfa-perm.sh username user_of_webserver path_of_install \n eg: ./sfa-perm.sh sfactive apache\n\n	NOTE: this is only for new installs !\n\n"
		exit
fi

if [ -z "$2" ] || [ -z "$3" ]; then
	echo -e "you need to specify the user your webserver runs as (usually www, www-data or apache), and the path to the install."
	exit
fi

user=$1
webserver=$2
path=$3

cd $path
chown -R $user.$user local scripts website
find local scripts website -type d -exec chmod 775 {} \;
find local scripts website -type f -exec chmod 664 {} \;
chown $webserver local/include local/include/*.inc local/include/*.php local/templates/ local/templates/*.tpl 
chown $webserver local/cache local/logs/ local/logs/sf* local/cache/pages/ local/cache/pages/*.inc local/cache/calendar/ 
chown $webserver local/cache/calendar/event* local/cache/*.html local/cache/hashes_time local/cache/*.txt local/cache/*.inc local/cache/galleries/
chown $webserver ../shared/session website/news local/cache/compiled/ website/syn/ website/themes/ 
chown $webserver website/themes/*.css website/process website/scripts website/uploads/ website/features/ website/calendar/event_cache 
chown $webserver website/calendar/week_cache/ website/archives/cache/ website/im/* website/images/ 
chown $webserver website/imcenter website/images/*.gif website/images/*.jpg website/images/*.png 
cd  ~-
