#!/usr/bin/perl -w

my $projectName = $ARGV [0];
my $indexer = $ARGV [1];

#------------------------------------------------------------
# Create the webshare project directory
#------------------------------------------------------------

if ( -e "/opt/webshare/$projectName")
	{
	print "webshare $projectName already exists\n";
	}
	else
	{
        system ("/bin/mkdir /opt/webshare/$projectName");

        if ("$indexer" eq "Full")
            {
            system ("/bin/cp -R /opt/webshare-tools/phpfm/* /opt/webshare/$projectName/");
            system ("/bin/cp -f /opt/webshare/$projectName/conf/config.inc.php-full /opt/webshare/$projectName/conf/config.inc.php");
            }
        elsif ("$indexer" eq "NoDelete")
            {
            system ("/bin/cp -R /opt/webshare-tools/phpfm/* /opt/webshare/$projectName/");
            system ("/bin/cp -f /opt/webshare/$projectName/conf/config.inc.php-nodelete /opt/webshare/$projectName/conf/config.inc.php");
            }	    
        elsif ("$indexer" eq "UpDown")
            {
            system ("/bin/cp -R /opt/webshare-tools/phpfm/* /opt/webshare/$projectName/");
            system ("/bin/cp -f /opt/webshare/$projectName/conf/config.inc.php-updown /opt/webshare/$projectName/conf/config.inc.php");
            }
        elsif ("$indexer" eq "View")
            {
            system ("/bin/cp -R /opt/webshare-tools/phpfm/* /opt/webshare/$projectName/");
            system ("/bin/cp -f /opt/webshare/$projectName/conf/config.inc.php-view /opt/webshare/$projectName/conf/config.inc.php");
            }

        system ("/usr/bin/find /opt/webshare/$projectName -type f -exec chmod 644 {} ';'");
        system ("/usr/bin/find /opt/webshare/$projectName -type d -exec chmod 755 {} ';'");
        system ("/bin/chown -R www:www /opt/webshare/$projectName/files");

        system ("/bin/touch /home/e-smith/db/webshare/htpasswd.$projectName");
        system ("/sbin/e-smith/signal-event ibay-modify");
	}

exit (0);
