head	1.7;
access;
symbols;
locks; strict;
comment	@# @;


1.7
date	2000.09.05.19.52.27;	author kmaples;	state dead;
branches;
next	1.6;

1.6
date	2000.09.05.02.26.12;	author kmaples;	state Exp;
branches;
next	1.5;

1.5
date	2000.09.02.18.12.11;	author kmaples;	state Exp;
branches;
next	1.4;

1.4
date	2000.08.18.00.24.01;	author kmaples;	state Exp;
branches;
next	1.3;

1.3
date	2000.08.16.23.55.44;	author kmaples;	state Exp;
branches;
next	1.2;

1.2
date	2000.08.15.21.07.52;	author kmaples;	state Exp;
branches;
next	1.1;

1.1
date	2000.08.15.19.55.33;	author kmaples;	state Exp;
branches;
next	;


desc
@@


1.7
log
@Use of .in files by these scripts is being depricated in favor of a shared library using an .in file
@
text
@#!/usr/bin/perl -w

# ================================================================
# Copyright (c) 2000 Collab.Net.  All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. The end-user documentation included with the redistribution, if
# any, must include the following acknowlegement: "This product includes
# software developed by Collab.Net (http://www.Collab.Net/)."
# Alternately, this acknowlegement may appear in the software itself, if
# and wherever such third-party acknowlegements normally appear.
#
# 4. The hosted project names must not be used to endorse or promote
# products derived from this software without prior written
# permission. For written permission, please contact info@@collab.net.
#
# 5. Products derived from this software may not use the "Tigris" name
# nor may "Tigris" appear in their names without prior written
# permission of Collab.Net.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# ====================================================================
#
# This software consists of voluntary contributions made by many
# individuals on behalf of Collab.Net.
#


################################################################
# Name:              ModuleAdd
# Original Author:   jrobbins@@collab.net
# $Id: ModuleAdd.in,v 1.6 2000/09/05 02:26:12 kmaples Exp $
#
# The goal of this script is to do everything that is needed to add a new
# module to the given project.
#
#---------------------------------------------------------------
# Arguments:
# This replaces the arbitrary assignment of args to tokens, and is
# shared by all scripts of this kind.  Keys are then mapped to the
# corresponding element lists specified in the %COMMAND_ARGS
# hash, which in turn specifies which of these args gets passed 
# to the 'child' scripts:
my %elements = (
        'apache_host_ip'      => '__APACHE_HOST_IP__',
        'apache_helm_conf'    => '__APACHE_HELM_CONF__',
	'htdoc_root'          => '__HTDOC_ROOT__',
        'sandbox'             => '__SANDBOX__',
        'domain_name'         => $ARGV[0] || '',
        'project_name'        => $ARGV[1] || '',
        'brand_name'          => $ARGV[2] || '',
        'description'         => $ARGV[3] || '',
        'module_name'         => $ARGV[4] || '',
        'module_description'  => $ARGV[5] || '',
        'is_web'              => $ARGV[6] || '',
        'was_web'             => $ARGV[7] || '',
        'is_private'          => $ARGV[8] || '',
);




# Minimum number of args this script requires for successful execution:
#my $minimum_arg_index = 8;

## This holds arrays of tokens for each action which map to the 
## command-line arguments put into the %elements hash.
## Note that quite a number of these have been rendered obsolete
## by EdK's work with converting these functions to servlets; only
## the ones known to be active are referred to here.
## The idea here is to abstract these into something static which
## can be stored in one place and shared amongst related functions.
## Note that the presence of a token here in the value side of the 
## hash means that it is implicitly required:

my %COMMAND_ARGS = (
	'apache-project-add'     => ['sandbox', 'apache_host_ip', 'apache_helm_conf', 'htdoc_root', 'project_name', 'domain_name', 'brand_name', 'description'],
	'apache-project-delete'  => ['sandbox', 'apache_helm_conf', 'htdoc_root', 'project_name', 'domain_name', 'brand_name'],
	'cvs-module-add'         => ['sandbox', 'htdoc_root', 'project_name', 'domain_name', 'brand_name', 'module_name', 'module_description', 'is_web', 'is_private'],
	'cvs-module-delete'      => ['sandbox', 'htdoc_root', 'project_name', 'domain_name', 'brand_name', 'module_name', 'is_web'],
	'cvs-module-edit'        => ['sandbox', 'htdoc_root', 'project_name', 'domain_name', 'brand_name', 'module_name', 'is_web', 'was_web', 'is_private'],
	'cvs-project-add'        => ['sandbox', 'htdoc_root', 'project_name', 'domain_name', 'brand_name', 'is_private'],
	'cvs-project-delete'     => ['sandbox', 'htdoc_root', 'project_name', 'domain_name', 'brand_name'],
);

#---------------------------------------------------------------
# Approach to logging - each 'ControlScript' (like this one) should 
# maintain it's own log file that includes the actions it's children.

my $script_name;

# Alpha and Omega:
BEGIN {
	# Open the logfile for logging at the beginning of execution.
	# The primary reason for this is to 'die' before doing anything
	# that we won't be able to log, and opening the log filehandle
	# in the beginning ensures this.
	
	# Grab just the filename portion of this script to use as a 
	# log identifier:
	$script_name = $0;
	$script_name =~ s/^.*\/([\w]+)$/$1/;

	# Autoflush buffer:
	$| = 1;

	# If this program is called by another program, we'll send STDOUT
	# and SDTERR to the logfile - this way the children's messages will
	# stick with the parent's logs.  Conversely, if this is called 
	# interactively (on the command line), we'll just let the output
	# go to the terminal instead of clogging up the logfiles with stuff
	# resulting from debugging attempts.
	
	unless(-t STDIN && -t STDOUT){
			
		# This needs to be established dynamically; I don't know the
		# preferred method for arriving at this value:
		my $logdir   = '__SANDBOX__/log/';		
		my $logfile  = $script_name . '.log';
		
		# Point STDOUT and STDERR to the logfile, or bail out:
		unless(open(STDOUT,">> $logdir" . "$logfile") && open(STDERR,">&STDOUT")){
			die "Can't open handle for logging: $!\n";
		}
		
		# This shouldn't really be necessary, but it couldn't hurt:
		select(STDERR); $| = 1;	
		select(STDOUT); $| = 1;	

		# This might appear odd, but since STDOUT is now a filehandle
		# for the logfile, try to get a lock on it, or bail out:
		unless(flock(STDOUT, 2|4)){ # Ask nice first.
			sleep 1;
			unless(flock(STDOUT, 2)){
				die "Unable to lock logfile: $!\n";
			}
		}
	}
	# This is all in order to print a nice header for the log
	# entry:

	my $time   = time();
	my $date   = localtime($time);
	my $header = "[$date]\n[$$] START: $script_name\n";
	
	print $header;
}
END {
	# Note that because END blocks are executed from bottom to top,
	# this block should appear BEFORE any other END blocks trying 
	# to print to the same filehandle.  This might seem unnecessary,
	# but since we did point these at a file, we really ought to 
	# clean up after ourselves:

	my $footer = "[$$] END: $script_name\n\n";
	
	print $footer;

	close(STDOUT) or die "Couldn't close logging handle STDOUT: $!\n";
	close(STDERR) or die "Couldn't close logging handle STDERR: $!\n";
}
#---------------------------------------------------------------
# An early-warning system: nip this in the bud if it's not going 
# to be able to execute anyway:
#unless($#ARGV >= $minimum_arg_index){
#	die "Execution failed due to insufficient arguments.\n";
#}

#---------------------------------------------------------------
# MAIN
#---------------------------------------------------------------
# NOTE:  According to Ed K., servlets are now dealing with functions
# relating to qmail/ezmlm/mhonarc - this leaves CVS and apache as
# the two components to be manipulated here.

my $ret = ''; # placeholder for current return value.  Unused.

# QMAIL:    call defunct
# EZMLM:    call defunct

# CVS:
# add a new cvs directory to the project
print "calling cvs-module-add:\n";
$ret = perform('cvs-module-add',\%elements,\%COMMAND_ARGS);

# Mhonarc:  call defunct

# Apache:   nothing

#---------------------------------------------------------------
# END MAIN
#---------------------------------------------------------------
#-------------------
sub perform {
#-------------------
	# Syntax:  perform(action, \%elements, \%COMMAND_ARGS);
	# Returns: diagnostic message
	
	my ($function, $elements_ref, $act_ref) = @@_;
	my $cmd     = 'unix command line';
	my $ret;
	
	# Nasty sharp pointy things: this just retrieves the original list
	# stored in the hashtable:
	my @@args = @@{ $act_ref->{$function} };
	
	# Now we replace those keys with their values as declared:
	foreach(@@args){
		# bail out if no value defined for 'required' key:
		my $current_value = $elements_ref->{$_};
		unless(defined($current_value)){
			print "WARNING: No value was set for '$_' token.\n";
			return(0);
		}
		# replace the key w/ its actual value:
		$_ = $current_value;
	}

	# A safe system call.  Note: DON'T use backticks for something
	# like this, or you'll likely lose all of the child's diagnostic
	# messages:
	$ret = system($function,@@args);
	
	# invert success here - the system will return '0' for true, '1'
	# for false - note that we're returning a diagnostic message, 
	# as logging of 'die' conditions are the responsibility of the 
	# called rather than the caller:	
	if($ret == 0){
		print "EXECUTED: $function @@args\n";
		return(1);
	} else {
		print "FAILED: $function @@args\n";
		return(0);
	}
}

__END__


@


1.6
log
@Removed check which required all nine listed arguments.
@
text
@d53 1
a53 1
# $Id: ModuleAdd.in,v 1.5 2000/09/02 18:12:11 kmaples Exp $
@


1.5
log
@Changed order of first two args as per Leonard - domain_name, project_name
@
text
@d53 1
a53 1
# $Id: ModuleAdd.in,v 1.4 2000/08/18 00:24:01 kmaples Exp $
d85 1
a85 1
my $minimum_arg_index = 8;
d186 3
a188 3
unless($#ARGV >= $minimum_arg_index){
	die "Execution failed due to insufficient arguments.\n";
}
@


1.4
log
@Added token for APACHE_HOST_IP; adjusted %COMMAND_ARGS accordingly.
@
text
@d53 1
a53 1
# $Id: ModuleAdd.in,v 1.3 2000/08/16 23:55:44 kmaples Exp $
d70 2
a71 2
        'project_name'        => $ARGV[0] || '',
        'domain_name'         => $ARGV[1] || '',
@


1.3
log
@Added support for token __APACHE_HELM_CONF__; adjusted the interface between
parent and child scripts defined in %COMMAND_ARGS accordingly.
@
text
@d53 1
a53 1
# $Id: ModuleAdd.in,v 1.2 2000/08/15 21:07:52 kmaples Exp $
d66 1
d98 1
a98 1
	'apache-project-add'     => ['sandbox', 'apache_helm_conf', 'htdoc_root', 'project_name', 'domain_name', 'brand_name', 'module_name', 'module_description', 'is_web', 'is_private'],	
@


1.2
log
@Changed all scripts to require a consistent 9-element @@ARGV; scripts now
take $sandbox from __SANDBOX__ rather than from @@ARGV.
@
text
@d53 1
a53 1
# $Id: ModuleAdd.in,v 1.1 2000/08/15 19:55:33 kmaples Exp $
d66 2
d97 7
a103 7
	'apache-project-add'     => ['sandbox', 'project_name', 'domain_name', 'brand_name', 'module_name', 'module_description', 'is_web', 'is_private'],	
	'apache-project-delete'  => ['sandbox', 'project_name', 'domain_name', 'brand_name'],
	'cvs-module-add'         => ['sandbox', 'project_name', 'domain_name', 'brand_name', 'module_name', 'module_description', 'is_web', 'is_private'],
	'cvs-module-delete'      => ['sandbox', 'project_name', 'domain_name', 'brand_name', 'module_name', 'is_web'],
	'cvs-module-edit'        => ['sandbox', 'project_name', 'domain_name', 'brand_name', 'module_name', 'is_web', 'was_web', 'is_private'],
	'cvs-project-add'        => ['sandbox', 'project_name', 'domain_name', 'brand_name', 'is_private'],
	'cvs-project-delete'     => ['sandbox', 'project_name', 'domain_name', 'brand_name'],
@


1.1
log
@Reviewed by:
.in files sharing a common framework for logging and common interface between the
calling servlet and child (sub) scripts performing the atomic tasks.  This
is presumed to be an intermediary step toward moving the common (global)
interface defs. and perform() routine into something shared (e.g., perl mod).

Even better is doing the whole thing in java.
@
text
@d53 1
a53 1
# $Id: $
d60 5
a64 13
# $ARGV[1] = project_name
# $ARGV[2] = domain_name (including TLD)
# $ARGV[3] = brand_name
# $ARGV[4] = module name (may include slashes)
# $ARGV[5] = module description 
# $ARGV[6] = check out to web server? (1 or 0)
# $ARGV[7] = is this module private? (1 or 0)

# Process arguments:
# Another way of going about the same thing - this replaces the 
# preceeding and should be declared on a per-script basis, in order
# to facilitate mapping to element lists specified in the %COMMAND_ARGS
# hash (hopefully global, someday):
d66 10
a75 10
	'sandbox'             => $ARGV[0] || '',
	'project_name'        => $ARGV[1] || '',
	'domain_name'         => $ARGV[2] || '',
	'brand_name'          => $ARGV[3] || '',
	'description'         => 'N/A',
	'module_name'         => $ARGV[4] || '',
	'module_description'  => $ARGV[5] || '',
	'is_web'              => $ARGV[6] || '',
	'was_web'             => 'N/A',
	'is_private'          => $ARGV[7] || '',
d79 2
d82 1
a82 1
my $minimum_arg_index = 7;
@

