#!/bin/sh

output="/app/www/.stats"
nic="eth0"

generate_index() {
cat <<EOF
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="refresh" content="3000">
    <title>Alpine Linux mirror statistics</title>
</head>
<body>
    <table border="0">
        <tr><td><img src="summary.png" alt="summary"></td><td><img src="hours.png" alt="hours"></td></tr>
        <tr><td rowspan="2"><img src="days.png" alt="days"></td></tr>
        <tr><td><img src="months.png" alt="months"></td></tr>
    </table>
</body>
</html>
EOF
}

if [ ! -f "$output/index.html" ]; then
    mkdir -p "$output"
    generate_index > "$output/index.html"
fi

for type in hours days months summary hsummary vsummary; do
    vnstati --${type} -i "$nic" -o "$output/${type}.png"
done