aboutsummaryrefslogtreecommitdiff
path: root/awstats/build.sh
blob: 816ae3b38b3094c5ba4288c8443343b4b84da11d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/sh

set -euo pipefail

# Validate environment variables
[ -z "$SITE_DOMAIN" ]       && { echo "SITE_DOMAIN env variable required";       exit 1; }
[ -z "$SITE_ALIASES" ]      && { echo "SITE_DOMAIN env variable required";       exit 1; }
[ -z "$GEOIP_LICENSE_KEY" ] && { echo "GEOIP_LICENSE_KEY env variable required"; exit 1; }

# Create the config template
cat > /etc/awstats/awstats.${SITE_DOMAIN}.conf <<EOF
LogFile="/input/${SITE_DOMAIN}.log"
DirData="/output"
LogFormat = "%virtualname %host - %other %time1 %methodurl %code %bytesd %refererquot %uaquot"
SiteDomain="${SITE_DOMAIN}"
HostAliases="${SITE_DOMAIN} ${SITE_ALIASES}"
#ShowScreenSizeStats=1
DefaultFile="index.html default.html"
AllowFullYearView=3

LoadPlugin="ipv6"
# Should be enabled for build only
LoadPlugin="geoip2 /geoip/GeoLite2-Country.mmdb"
LoadPlugin="geoip2_city /geoip/GeoLite2-City.mmdb"

#ExtraSectionName1="Redirected Hit"
#ExtraSectionCodeFilter1="302"
#ExtraSectionCondition1="URL,\/offsite"
#ExtraSectionFirstColumnTitle1="Url"
#ExtraSectionFirstColumnValues1="QUERY_STRING,url=([^&]+)"
#ExtraSectionStatTypes1=HL
#MaxNbOfExtra1=500
#MinHitExtra1=1
#ExtraSectionAddSumRow1=1
EOF

# Download and setup GeoIP Databases
curl -s "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&suffix=tar.gz&license_key=${GEOIP_LICENSE_KEY}" | tar -xz -C /tmp
curl -s "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&suffix=tar.gz&license_key=${GEOIP_LICENSE_KEY}" | tar -xz -C /tmp
curl -s "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&suffix=tar.gz&license_key=${GEOIP_LICENSE_KEY}" | tar -xz -C /tmp

find /tmp -name '*.mmdb' -exec cp '{}' /geoip/ \;
rm -rf /tmp/GeoLite2*

/opt/awstats/wwwroot/cgi-bin/awstats.pl -config=${SITE_DOMAIN} -update -dir=/output