#!/usr/bin/perl -w
# -*- perl -*-

#
# $Id: mksymlinks,v 1.3 2003/01/07 19:46:13 eserte Exp $
# Author: Slaven Rezic
#
# Copyright (C) 2001 Online Office Berlin. All rights reserved.
#
# Mail: slaven@rezic.de
# WWW:  http://bbbike.sourceforge.net
#

# Create a symlink farm from a http-accessable directory to the BBBike source

use File::Copy qw(cp);
use strict;
use FindBin;
use File::Spec;

(my $bbbike_src = $FindBin::RealBin) =~ s|/[^/]+/?$||;
my $config_name = shift;

symlink "$bbbike_src/html"  , "html"   or die $!;
symlink "$bbbike_src/images", "images" or die $!;
symlink "$bbbike_src/java"  , "java"   or die $!;
symlink "$bbbike_src"	    , "root"   or die $!;

mkdir "cgi", 0755;
if (!-d "cgi") {
    die "Can't create cgi directory: $!";
}

open(SH, ">cgi/bbbike.cgi") or die $!;
print SH <<EOF;
#!/bin/sh
$^X $bbbike_src/cgi/bbbike.cgi \$*
EOF
close SH;
chmod 0755, "cgi/bbbike.cgi";

if (defined $config_name) {
    if (!file_name_is_absolute($config_name)) {
	if ($config_name !~ /\.cgi.config$/) {
	    $config_name = "bbbike-$config_name.cgi.config";
	}
	$config_name = "$bbbike_src/cgi/$config_name";
    }
    if (!-f $config_name) {
	die "Can't find config $config_name";
    }
    cp("$config_name", "cgi/bbbike.cgi.config") or die $!;
    chmod 0644, "cgi/bbbike.cgi.config";
}

# REPO BEGIN
# REPO NAME file_name_is_absolute /home/e/eserte/src/repository 
# REPO MD5 a77759517bc00f13c52bb91d861d07d0

=head2 file_name_is_absolute($file)

=for category File

Return true, if supplied file name is absolute. This is only necessary
for older perls where File::Spec is not part of the system.

=cut

sub file_name_is_absolute {
    my $file = shift;
    my $r;
    eval {
        require File::Spec;
        $r = File::Spec->file_name_is_absolute($file);
    };
    if ($@) {
	if ($^O eq 'MSWin32') {
	    $r = ($file =~ m;^([a-z]:(/|\\)|\\\\|//);i);
	} else {
	    $r = ($file =~ m|^/|);
	}
    }
    $r;
}
# REPO END


__END__
