#!/bin/sh
#############################
## Build script for: awstats
## Creator: Jay Scott Raymond
## Adapted from examples from linuxpackages.net
## Date: 17 Nov 2008
## Builds package: Yes
## Source location: http://www.postgresql.org/
## Downloads source: No
## Build script version: v1
## Requirements: 
##
## Notes: 
##

## Include the slackware-pkg conf file
if [ -a /etc/slack-package.conf ]; then
. /etc/slack-package.conf
  else
  echo "Sorry you need to have the slack-package.conf file to run these"
  echo "please install the slackbuilds package from LinuxPackages.net"
  exit
fi

# Set initial variables:
NAME=awstats
VERSION=6.8
BUILD=1$MYIN


## Location to download the sources
#SRC_LOC=""

PKG=$TMP/package-$NAME

## Lets Grab the Source if needed
#if [ -a $CWD/$NAME-$VERSION.tar.gz ]; then
#  echo "Source present not downloading"
#  else
#  $WGET $SRC_LOC || true
#fi

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
rm -rf $PKG
mkdir -p $PKG # place for the package to be built

cd $TMP

unpack() {
    rm -rf $NAME-$VERSION
    # choose one
    #tar xjvf $CWD/$NAME-$VERSION.tar.bz2
    tar xzvf $CWD/$NAME-$VERSION.tar.gz
    cd $NAME-$VERSION
    fix_source
}

config() {
    cd $TMP/$NAME-$VERSION
}


compile() {
    cd $TMP/$NAME-$VERSION
}

install() {
    cd $TMP/$NAME-$VERSION
    mkdir -p $PKG/usr/share/awstats
    cp -a tools wwwroot docs $PKG/usr/share/awstats
}

# use this for packages that don't respect DESTDIR or need additional fixup
construct() {

    cd $TMP/$NAME-$VERSION
    mkdir -p $PKG/var/lib/awstats

    mkdir -p $PKG/install
    cat $CWD/doinst.sh > $PKG/install/doinst.sh

    mkdir -p $PKG/etc/httpd/extra
    cat $CWD/awstats.conf > $PKG/etc/httpd/extra/awstats.conf.new

    mkdir -p $PKG/etc/awstats
    cat wwwroot/cgi-bin/awstats.model.conf \
	> $PKG/etc/awstats/awstats.model.conf.new

    mkdir -p $PKG/etc/cron.hourly
    cat > $PKG/etc/cron.hourly/awstats.new <<EOF
#!/bin/sh
/usr/share/awstats/tools/awstats_updateall.pl now -awstatsprog=/usr/share/awstats/wwwroot/cgi-bin/awstats.pl
#/usr/bin/perl /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -update -config=default
EOF
}

prepare() {
create_docs $PKG $NAME-$VERSION
rm -rf $PKG/usr/doc/$NAME-$VERSION/docs
ln -sf ../../share/$NAME/docs $PKG/usr/doc/$NAME-$VERSION/docs

## Some package cleanup
( cd $PKG
strip_bin
strip_lib
strip_static
gzip -9q usr/pgsql/man/*/*
#gzip_man $PKG
#gzip_info $PKG
bin_perms $PKG
sbin_perms $PKG
)
}

description() {
mkdir -p $PKG/install
        cat > $PKG/install/slack-desc << END 
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description.  Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in.  You must
# make exactly 11 lines for the formatting to be correct.  It's also
# customary to leave one space after the ':'.

       |-----handy-ruler------------------------------------------------------|
awstats: AWStats $VERSION
awstats:
awstats: AWStats is a free powerful and featureful tool that generates advanced
awstats: web, streaming, ftp or mail server statistics, graphically. This log
awstats: analyzer works as a CGI or from command line and shows you all
awstats: possible information your log contains, in few graphical web pages. It
awstats: can analyze log files from all major server tools.
awstats:
awstats: The AWStats homepage is http://www.awstats.net/
awstats: Packaged by: Leigh Wedding <leigh.wedding@telstra.com>
awstats:
END
}

cpslackbuild() {
mkdir -p $PKG/usr/src/slackbuilds/$NAME
cp $CWD/$NAME.SlackBuild $PKG/usr/src/slackbuilds/$NAME
}

build() {
# Build the package:
cd $PKG
makepkg -l y -c n $PKG_DIR/$NAME-$VERSION-$ARCH-$BUILD.tgz
echo "Your $NAME package is complete, make sure you open it up before installing it."
echo "It is located in $PKG_DIR thanks for your support The Linuxpackages.net Folks"
}

unpack
config
compile
install
construct
prepare
description

cpslackbuild
build

