#!/bin/sh
# ssl-setup.sh					29 Apr 07
#------------------------------------------------------------

: <<'=cut'

=head1 NAME

ssl-setup.sh - Setup use of SSL for TWiki authentication

=head1 SYNOPSIS

B<ssl-setup.sh> I<hostname> I<ip_address> I<twiki_dir> [I<twiki_content>]


=head1 DESCRIPTION

Creates configuration files to be used for a Web server where the
content is managed by TWiki. With that configuration, passwords are
not transmitted unencrypted over a network.

You need to specify the hostname of your Web server, its IP address,
and the directory where TWiki is installed. If you have separated the
data and the program parts of TWiki, you can add the data base
directory as an optional 4th argument (default is the TWiki
installation directory).

If these are the only virtual servers on your Web server, you can use
C<_default_> as I<ip_address>, too.


=head1 FILES

=over

=item F<twiki.full-server>

Apache configuration snippet, to be included into a virtual host section.

=item F<hostname> (or F<vhost.tmpl>)

Definition of two virtual hosts.

=item F<LocalSite.cfg.patch>

Patch for F<LocalSite.cfg>, to be used after every configure.

=back

=cut


# Check arguments.

if [ "$#" -lt 3 -o "$#" -gt 4 ]
   then	echo "usage: `basename $0` hostname ip_address twiki_dir [twiki_content]" >&2
	exit 1
fi

hostname="$1"
ip_address="$2"
twiki_dir="$3"
if [ "$#" = 3 ]
   then	twiki_content="$3"
   else	twiki_content="$4"
fi

# Sanity check. But don't abort, execution of this install script may
# be on an auxilliary system.
test -d "$twiki_dir/bin"  ||
    echo "$twiki_dir doesn't seem to be a TWiki installation directory." >&2
test -d "$twiki_content/data"  ||
    echo "$twiki_content doesn't seem to be a TWiki content directory." >&2


# Create the configuration files.

for src in *.tmpl
   do	dest=`basename $src .tmpl`
	test "$dest" = 'vhost'  &&  dest="$hostname"
	# FIXME: If one of the replacement texts contains the sed s-delimiter,
	# we loose. Sigh, maybe we should use Perl for this.
	sed "s/HOSTNAME/$hostname/g
	     s/IP_ADDRESS/$ip_address/g
	     s+TWIKI_DIR+$twiki_dir+g
	     s+TWIKI_CONTENT+$twiki_content+g" $src >$dest
   done



#======================================================================
#
# Log:
#
# 29 Apr 07 -js Initial revison
