#!/usr/local/bin/perl

# mkhome.pl
# create a customized, generic home page.
# designed for nyx.cs.du.edu but easily expandable to other systems.
#    if you move it to your own host, please let me know about it, so
#    i can add you to the mailing list for mkhome installers.  you'll get
#    update notices and so on.
# author: meng weng wong, http://pobox.com/~mengwong/
 $version = "1.2.2";
# date: Sat May 13 17:56:25 MDT 1995
# original source: http://nyx10.cs.du.edu:8001/~mwong/mkhome.pl
# usage:  perl mkhome.pl.  no arguments.
# action: creates ~/html, creates ~/html/index.html.  changes perms.
# Modificado por Guido Orellana.

system ("echo for accounting only | mail -s '$0 $version executed' gorellan\@dcc.uchile.cl");

($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($<);

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
($yr = $year) =~ s/.*(..)$/$1/;

$FULLNAME = $gcos;		# fullname of user
# $HOST_URL = `hostname`;       # we happen to know where we are.
$HOST_URL = "http://www.dcc.uchile.cl";
$USER = $name;			# user is the user ...
# $HOST_NAME = `hostname`; chop $HOST_NAME; # get the hostname
$HOST_NAME = "dcc.uchile.cl";
$HOMEPAGE = "index.html";	# default name for homepages.
$HOST_BLURB = "Nyx or the University of Denver"; # institution to indemnify
$MODDATE = sprintf("%02d%02d%02d",$yr,$mon+1,$mday);
$UserDir = "public_www";

if (-e "$dir/$UserDir")
{
    print "$dir/$UserDir existe ...\n";
    if (! -d _)
    {
	die "$dir/$UserDir existe y no es un directorio!\n";
    }
    elsif (-e "$dir/$UserDir/$HOMEPAGE")
    {
	print "$dir/$UserDir/$HOMEPAGE ya existe.  sobreescribo? [Ns] ";
	$answer = <STDIN>;
	if ($answer =~ /^[sS]/)
	{ unlink("$dir/$UserDir/$HOMEPAGE~");
	  rename("$dir/$UserDir/$HOMEPAGE","$dir/$UserDir/$HOMEPAGE~");
	  print "backup saved to $HOMEPAGE~\n";
        }
	else
	{ print "leaving $dir/$UserDir/$HOMEPAGE alone.  exiting.\n"; exit; }
    }
}
else
{
    print "$dir/$UserDir doesn't exist, creating ... ";
    mkdir ("$dir/$UserDir",0755) || die "unable to create $dir/$UserDir.  $!\n";
    chmod (0755,"$dir/$UserDir");
    print "created.\n";
}

print "creating $dir/$UserDir/$HOMEPAGE\n";

    open (HOMEPAGE, ">$dir/$UserDir/$HOMEPAGE") || die "unable to create $dir/$UserDir/$HOMEPAGE:  $!\n";
    
    print HOMEPAGE <<"default";
<TITLE>${FULLNAME}'s Home Page</TITLE>
<H1>${FULLNAME}'s Home Page</H1>

Bienvenido a mi página personal, la que fue creada por un programa en Perl,
si quieres obtenerlo presiona <a href="http://www.dcc.uchile.cl/~gorellan/mkhome.pl">aquí</a>.  Algunos
links interesantes son:<P>

<UL>
<LI> <A HREF="$HOST_URL/">Dcc Home Page</A>
<LI> <A HREF="http://www.lycos.com/">Lycos Search</A>
<LI> <A HREF="http://www.ncsa.uiuc.edu/demoweb/html-primer.html">A
     Primer on writing HTML documents</A>
<LI> <A
     HREF="http://www.uwm.edu/Mirror/inet.services.html">The
     Yanoff List</A>
<LI> <A HREF="http://pobox.com/~mengwong/">Meng Weng
     Wong's home page</A>
<LI> <A HREF="$HOST_URL/cgi-bin/finger?$USER">finger me</A>
<LI> <A HREF="http://info.cern.ch/hypertext/WWW/TheProject.html">About
     the World Wide Web</A>
<LI> <A
     HREF="http://kufacts.cc.ukans.edu/about_lynx/about_lynx.html">Lynx
     home page</A>
<LI> <A HREF="http://www.ncsa.uiuc.edu/demoweb/demo.html">Mosaic Demo
     Document</A>
<LI> <A
     HREF="http://www.ncsa.uiuc.edu/SDG/Software/Mosaic/Docs/whats-new.html">Mosaic
     What's New on the Web</A>
<LI> <A HREF="http://cuiwww.unige.ch/meta-index.html">Searchable
     Meta-Index of WWW resources</A>
<LI> <A HREF="http://pobox.com/pobox/frommkindex.html">lifetime email at pobox.com</A>
</UL>

<hr>


<UL>
<LI> last modified $MODDATE
<LI> Si quieres enviame un Mail <A
     HREF="mailto:$USER\@$HOST_NAME">$USER\@$HOST_NAME</A> con tus
comentarios y correcciones, o si quieres conocerme.
</UL>

<ADDRESS>$USER\@$HOST_NAME</ADDRESS>
<!--
			     mkhome.pl $version
		      generic home page creator
	      http://nyx10.cs.du.edu:8001/~mwong/mkhome.pl
   by meng weng wong, http://www.seas.upenn.edu/~mengwong/meng.html
-->
default

close HOMEPAGE;
chmod (0644, "$dir/$UserDir/$HOMEPAGE");

print "Ejecutado con exito.  El URL para tu pagina es\n";
print "\t$HOST_URL/~$USER/index.html\n";
print "para acceder a ella tipea: lynx $HOST_URL/~$USER/index.html (terminal ASCCI).\n";
print "o netscape $HOST?URL/~$USER/index.html (terminal grafico).\n";
print "remember to \"chmod a+x ~\" when you're ready.\n";
print "\n\nThe following is a public service announcement:\n";
print "\t\t\t\tRTFM!!!  RTFM!!!  RTFM!!!\n";
