#!/usr/athena/bin/perl

unshift (@INC, '/afs/sipb.mit.edu/project/www/src/db');
require 'dbparse.pl';

#############################################################################
#############################################################################
# These are hardcoded links that should be created in "people".
# It's okay to add elements to this list, but be sure you do it right.
#
# Syntax is "name of symlink", "file symlink points to" ...

%to_create = (
    "index.html", "../home-pages.html",
    "jevens",     "/afs/sipb.mit.edu/user/nocturne/www-lib",
    "shabby",     "/afs/athena.mit.edu/user/s/h/shabby/www",
    "tori.html",  "nocturne/tori.html"
);

#############################################################################
#############################################################################


$newpeople = '/afs/sipb.mit.edu/project/www/root/newpeople';
$people    = '/afs/sipb.mit.edu/project/www/root/people';
$oldpeople = '/afs/sipb.mit.edu/project/www/.oldpeople';
$master_db_file = $DB'default_home;

system("rm -rf $newpeople");
system("rm -rf $oldpeople");
mkdir($newpeople, 0777);

if (&DB'ParseHome($master_db_file) == 0) {
   print "Cannot open $newfile. Aborting.\n";
   exit(0);
}

foreach $user (sort keys %DB'index) {
    $new = "";
    ($url, $name, $sort_index, $link, $date) = &DB'FetchUser($user); #'

    if ($link ne "") {
        $url =~ /\/people\/([^\/]+)\//;
        $new = ($newpeople . "/" . $1);

	symlink($link, $new);
    }
}


chdir($newpeople);

foreach $new (sort keys %to_create) {
    symlink($to_create{$new}, $new);
}

rename($people, $oldpeople);
rename($newpeople, $people);
system("rm -rf $oldpeople")
