#!/bin/sh
# Version 3.2
################################################################################
# This script was desinged to facilitate ircd upgrades for admins.
#
# Intruction:
#
# download this file into your ~/ home directory.
# chmod +x hybrid	# chmod +x this file so you can run it.
# ./hybrid install	# this will download and compile hybrid ircd.
# ./hybrid upgrade	# this will upgrade your existing hybrid installation.
# ./hybrid upgrade-script	# this will upgrade this script.
#
################################################################################
#                             CONFIGURATION SECTION                            #
################################################################################
# Here you cand edit some options that will passed to ./configure
#
IDIR=$HOME/ircd # set the path of your ircd folder.
MAX_CLIENTS=500	# set the ammount of users to allow on this server.
NICKLEN=20	# set the max nick length (this must be the same on all servers)
#
################################################################################
#                                DOWNLOAD SECTION                              #
################################################################################
# Use the latest stable version the rebelchat.org mirror
#
VERSION=ircd-hybrid-7.0rc10.tgz			# file name.
URL=http://ftp.rptn.net/pub/ircd-hybrid/	# url to fetch from.
SOURCE=ircd-hybrid-7.0rc10			# source dir.
#
# Use the latest CVS snapshot (use with caution)
#VERSION=ircd-hybrid-7.tar.gz			# file name.
#URL=http://squeaker.ratbox.org			# url to fetch from.
#SOURCE=ircd-hybrid-7				# source dir.
#
################################################################################
#   END OF CONFIGURATIONS, MOST PEOPLE WILL NOT NEED TO EDIT PAST THIS LINE    #
################################################################################

DATE=`date "+%y%m%d"`
FETCHER=/usr/bin/fetch

    case "$1" in
    upgrade)
	# make sure ircd/tmp exists.
	mkdir $IDIR/tmp > /dev/null 2>&1
	cd $IDIR/tmp && \
	
	# fetch source.
	$FETCHER $URL/$VERSION && \
	$FETCHER $URL/modules/hybrid_services.c && \
	$FETCHER $URL/modules/m_forcenick.c && \
	$FETCHER $URL/modules/m_sping.c && \
	tar zxf $VERSION && \
	mv hybrid_services.c m_forcenick.c m_sping.c $SOURCE/contrib/ && \

	# configure and compile.
	cd $IDIR/tmp/$SOURCE && \
	./configure --prefix=$IDIR --with-nicklen=$NICKLEN \
            --with-maxclients=$MAX_CLIENTS --enable-small-net && \
	make && make install && \

	# install a few modules.
	cd contrib && make && \
	make hybrid_services.so m_forcenick.so m_sping.so && \
	mv m_clearchan.so m_force.so m_opme.so m_ojoin.so $IDIR/modules/autoload &&\
	mv m_map.so m_tburst.so m_mkpasswd.so hybrid_services.so m_forcenick.so m_sping.so $IDIR/modules/autoload && \

	# remove the tarball and date-stamp the sources.
	cd $IDIR/tmp && \
	mv $SOURCE hybrid-$DATE && \
	rm $VERSION
	echo "----------------------------------------------------------------------"
	echo "hybrid-ircd has now been upgraded on your system"
	echo "this upgrade script was desinged for the rebelchat irc network"
        ;;

    install)
	# make sure ircd/tmp exists.
	mkdir $IDIR > /dev/null 2>&1
	mkdir $IDIR/tmp > /dev/null 2>&1
	cd $IDIR/tmp && \
	
	# fetch source.
	$FETCHER $URL/$VERSION && \
	$FETCHER $URL/modules/hybrid_services.c && \
	$FETCHER $URL/modules/m_forcenick.c && \
	$FETCHER $URL/modules/m_sping.c && \
	tar zxf $VERSION && \

	mv hybrid_services.c m_forcenick.so m_sping.so $SOURCE/contrib/ && \

	# configure and compile.
	cd $IDIR/tmp/$SOURCE && \
	./configure --prefix=$IDIR --with-nicklen=$NICKLEN \
            --with-maxclients=$MAX_CLIENTS --enable-small-net && \
	make && make install && \

	# install a few modules.
	cd contrib && make && \
	make hybrid_services.so	m_forcenick.so m_sping.so && \
	mv m_clearchan.so m_force.so m_opme.so m_ojoin.so $IDIR/modules/autoload &&\
	mv m_map.so m_tburst.so m_mkpasswd.so hybrid_services.so m_forcenick.so m_sping.so $IDIR/modules/autoload && \

	# remove the tarball and date-stamp the sources.
	cd $IDIR/tmp && \
	mv $SOURCE hybrid-$DATE && \
	rm $VERSION && \

	# move this script into the ircd dir.
	mv ~/hybrid $IDIR && \
	echo "----------------------------------------------------------------------"
	echo "hybrid-ircd has now been installed on your system"
	echo "this upgrade script was desinged for the rebelchat irc network"
        ;;

    upgrade-script)
	# update this script.
	$FETCHER http://ftp.rptn.net/pub/ircd-hybrid/hybrid 
	chmod +x $IDIR/hybrid
        ;;
    *)
	echo "Usage: `basename $0` {install|upgrade|upgrade-script}" >&2
	exit 64
        ;;
    esac

    exit 0
