#!/bin/sh
#  Program: penn-install
#  Version: 0.0.1
#  Author: Ervin Hearn III (Noltar) <noltar@korongil.net>
#  Date: Thu, 11 Sep 2003 18:04:43 -0400.
#  Copyright:
#
#    This program is free software; you can redistribute it and/or modify it
#    under the terms of the "Artistic License" which comes with Debian.
#
#    THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
#    WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES
#    OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
#    On Debian GNU/Linux systems, the complete text of the Artistic License
#    can be found in `/usr/share/common-licenses/Artistic'.
#
#  Description:
#
#    This program installs the pennmush server for the user in the directory
#    from which it is ran. It provides all configuration, data, and script
#    files necessary for the user to initiate and run an instance of the
#    pennmush server process, netmush.
#
#  History:
#   0.0.1  Initial Release.

NAME=penn-install
VERSION=0.0.1
PKGDIR=`pwd`/pennmush
DSTDIR=$PKGDIR/game
SRCDIR=/usr/lib/pennmush/game
SHRDIR=/usr/share/pennmush/game
DWNDIR=''


################################################################
#
# 0. Check options

case "$1" in
  '')

    ################################################################
    #
    # 1. Install pennmush
    #

    #
    # 1.2 Helpers
    #

    mkdstlns()
    {
      while [ $1 ]; do
      ln -s $SRCDIR/$1
      shift
      done
    }

    mkshrdstlns()
    {
      while [ $1 ]; do
      ln -s $SHRDIR/$1
      shift
      done
    }

    mklns()
    {
      while [ $1 ]; do
      ln -s $SRCDIR/$DWNDIR/$1
      shift
      done
    }

    mkshrlns()
    {
      while [ $1 ]; do
      ln -s $SHRDIR/$DWNDIR/$1
      shift
      done
    }

    mkcps()
    {
      while [ $1 ]; do 
      cp $SRCDIR/$DWNDIR/$1 .
      shift
      done
     }

    mkshrcps()
    {
      while [ $1 ]; do 
      cp $SHRDIR/$DWNDIR/$1 .
      shift
      done
     }

     mkcdir()
     {
       cd $DSTDIR
       mkdir -p $1
       cd $1
       DWNDIR=$1
     }

     echo -n "Installing pennmush in $DSTDIR"

     #
     # 1.3 Create main pennmush directory
     #

     mkdir $PKGDIR
     cd $PKGDIR

     echo -n "."

     #
     # 1.4 Do sanity check for existing pennmush installations
     #

     if test -f ./$NAME; then

       echo "It's not good idea to install pennmush in the current directory."
       echo "You should read 'man $NAME' and run it in a different directory."
       exit

     fi

     if test -f ./utils/$NAME; then

       echo "If you want to use this script, you need to 'make debianinstall'"
       echo "as root first, and then run this script. If you don't have the"
       echo "necessary access, you should install pennmush normally from the"
       echo "source or ask your system administrator about installing it"
       echo "globally."
       exit

     fi

     if test -f ./game/restart; then

       echo "You should only run this once to install pennmush locally."
       echo "All upgrades and modifications to the server itself are done"
       echo "globally. Check with your system administrator if you are having"
       echo "problems. If something is wrong with your configuration files,"
       echo "create a new directory and run '$NAME' in that and copy"
       echo "you're modified files over."
       exit

     fi

     echo -n "."

     # 1.5 Setup game directory

     #
     # 1.5.1 Create base game directory
     #

     mkdir $DSTDIR
     cd $DSTDIR
     mkdstlns config.sh
     mkshrdstlns access.README aliascnf.dst getdate.README getdate.template \
     	mushcnf.dst namescnf.dst restrictcnf.dst README
     mkshrcps *.cnf restart

     echo -n "."

     #
     # 1.5.2 Link binaries
     #

     mkdstlns info_slave netmush

     echo -n "."

     #
     # 1.5.3 Make sure restart is executable by the user
     #

     chmod u+x restart

     echo -n "."

     #
     # 1.6 Create storage directories
     #

     mkcdir save
     mkshrlns README

     mkcdir log
     mkshrlns README

     mkcdir data
     mkshrlns README

     echo -n "."

     #
     # 1.7 Setup text files
     #

     #
     # 1.7.1 Text generation files
     #

     mkcdir txt
     mkshrlns compose.sh.SH compose.sh index-files.pl

     echo -n "."

     #
     # 1.7.2 Copy text files. Most will either be autogenerated or modified by the user
     #

     mkshrcps *.txt Makefile

     echo -n "."

     #
     # 1.7.3 Events is mush specific and starts out essentially empty
     #

     mkcdir txt/evt
     mkshrcps pennmush.evt

     echo -n "."

     #
     # 1.7.4 News is mush specific and starts out essentially empty
     #

     mkcdir txt/nws
     mkshrcps pennmush.nws

     echo -n "."

     #
     # 1.7.5 Help contains a large part of the standard pennmush documentation

     mkcdir txt/hlp
     mkshrlns penncmd.hlp pennconf.hlp pennfunc.hlp pennpueb.hlp pennv174.hlp \
	pennv176.hlp pennvOLD.hlp pennchat.hlp penncode.hlp pennflag.hlp \
	pennmail.hlp penntop.hlp pennv175.hlp pennv177.hlp pennv180.hlp

     #
     # 1.8 Setup i18n translation files if present
     #
     
     if test -d /usr/share/pennmush/po; then
     	mkdir $PKGDIR/po
        ln -s /usr/share/pennmush/po/* $PKGDIR/po/
        echo -n "."
     fi

     echo "Done"
     echo "** Be sure to change the 'port' entry in pennmush/game/mush.cnf"
     echo "** to the one either assigned by your system admin or currently"
     echo "** available on the system. It is also necessary to set the"
     echo "** GAMEDIR variable at the top of pennmush/game/restart. Finally,"
     echo "** log into the mush and change the password for One (#1) to"
     echo "** something safe."
    ;;
  -v|--version)

    ################################################################
    #
    # 1. Display version information
    #
    
    echo "$NAME $VERSION  Copyright (C) 2003 Ervin Hearn III"
    echo "This program is free software; you can redistribute it and/or modify it"
    echo "under the terms of the \"Artistic License\" which comes with Debian."
    echo " "
    echo "THIS PACKAGE IS PROVIDED \"AS IS\" AND WITHOUT ANY EXPRESS OR IMPLIED"
    echo "WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES"
    echo "OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE."
    echo " "
    echo "On Debian GNU/Linux systems, the complete text of the Artistic License"
    echo "can be found in '/usr/share/common-licenses/Artistic'."
    echo " "
    echo "Report bugs to <noltar@korongil.net>."
    exit 1
    ;;
  *)

    ################################################################
    #
    # 1. Display help information
    #
    
    echo "$NAME $VERSION  Copyright (C) 2003 Ervin Hearn III"
    echo "This program is free software; you can redistribute it and/or modify it"
    echo "under the terms of the \"Artistic License\" which comes with Debian."
    echo " "
    echo "THIS PACKAGE IS PROVIDED \"AS IS\" AND WITHOUT ANY EXPRESS OR IMPLIED"
    echo "WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES"
    echo "OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE."
    echo " "
    echo "On Debian GNU/Linux systems, the complete text of the Artistic License"
    echo "can be found in '/usr/share/common-licenses/Artistic'."
    echo " "
    echo "Usage: $NAME [OPTION]"
    echo " "
    echo "Installs pennmush in the current directory for the user."
    echo " "
    echo "This program follows the usual GNU command line syntax, with long"
    echo "options starting with two dashes ('-')."
    echo " "
    echo "Options:"
    echo "  -h, --help        display this help and exit"
    echo "  -v, --version     output version information and exit"
    echo " "
    echo "Report bugs to <noltar@korongil.net>."
    exit 1
    ;;
esac

exit 0
