#!/bin/sh

################################################################################

# Customize the absolute path below so that it corresponds to the directory
# where you want Webalizer to be built. DO NOT run this script unless you
# have first modified this line.

TARGETDIR=/home/USERNAME/webalizer

################################################################################

# Copyright (C) 2009 Andres Cabezas Ulate

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

################################################################################

# You can view the terms of the GNU General Public License at the following link:

# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt

################################################################################

# 1. Create the webalizer directory.

mkdir $TARGETDIR/

# 2. Make the directory where the required library files will be stored.

mkdir $TARGETDIR/lib

# 3. Make a directory to store the source code for the libraries you will use.

mkdir $TARGETDIR/sources

# 4. Download and build the bzip2 library
# (http://www.bzip.org/, http://www.bzip.org/downloads.html)

cd $TARGETDIR/sources
wget http://www.bzip.org/1.0.5/bzip2-1.0.5.tar.gz
tar xvfz bzip2-1.0.5.tar.gz
cd bzip2-1.0.5/
make
make install PREFIX=$TARGETDIR

# 5. Download anb build the matching version of the Berkeley DB library.

cd $TARGETDIR/sources
wget http://download.oracle.com/berkeley-db/db-4.4.20.tar.gz
tar xvfz db-4.4.20.tar.gz
cd db-4.4.20/build_unix/
../dist/configure --prefix=$TARGETDIR
make
make install

# 6. Download and build Webalizer
# (http://www.webalizer.org/, http://www.webalizer.org/download.html)

cd $TARGETDIR/sources
wget ftp://ftp.mrunix.net/pub/webalizer/webalizer-2.21-02-src.tgz
tar xvfz webalizer-2.21-02-src.tgz
cd webalizer-2.21-02/
./configure --prefix=$TARGETDIR --with-language=english --enable-dns --enable-bz2 --enable-geoip --with-bz2lib=$TARGETDIR/lib --with-bz2=$TARGETDIR/include
make
make install

# 7. Install the Webalizer binaries in the webalizer folder

cd $TARGETDIR
cp bin/webalizer .
ln -s webalizer webazolver

# 8.  Include the following lines at the top of any scripts which run Webalizer.

# LD_LIBRARY_PATH=$TARGETDIR/lib:$LD_LIBRARY_PATH
# export LD_LIBRARY_PATH

# Step 9 is needed in order for Webalizer to find all the libraries it needs
# to run.  An alternative is to compile Webalizer statically by adding the
# --enable-static parameter to the configure script.  Doing this eliminates the
# need for step 9.  However, the webalizer binary grows in size from 320 kilobytes
# to 1.9 megabytes.  According to the compiler messages, there could be
# other caveats, which aren't covered in these instructions.

################################################################################