#!/bin/sh
# ----------------------------------------------------------------------------
# /usr/bin/webalizer-run - update log files
#
# Creation   :  2009-05-24 jv
# Last update:  $Id$
#
# Copyright (c) 2009 the eisfair team, team(at)eisfair(dot)org
# Copyright (c) 2014-@@YEAR@@ Holger Bruenjes, holgerbruenjes(at)gmx(dot)net
#
# 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.
# ----------------------------------------------------------------------------
#set -x

lines="yes"
cron=''
if [ "X${1}" = "Xcron" ]
then
    cron="-Q"
    lines="no"
fi

idx=1
for config_file in $(ls /etc/webalizer/webalizer_*.conf)
do
    if [ "${lines}" = "yes" ]
    then
        echo '--------------------------------------------------------------------------------'
    fi
    mkdir -p $(grep OutputDir ${config_file} | sed 's/OutputDir//')

    if [ "${lines}" = "yes" ]
    then
        # output codex
        if $(echo "${LC_CTYPE}" | grep -qE '.[Uu][Tt][Ff]-?8')
        then
            /usr/bin/webalizer -c ${config_file} -T | iconv -f iso88591 -t UTF-8
        else
            /usr/bin/webalizer -c ${config_file} -T
        fi
    else
        /usr/bin/webalizer -c ${config_file} ${cron}
    fi
    idx=$((${idx} + 1))
done

if [ "${lines}" = "yes" ]
then
    echo '--------------------------------------------------------------------------------'
   /var/install/bin/anykey
fi

set +x

exit 0
# ----------------------------------------------------------------------------
# end
# ----------------------------------------------------------------------------