#!/usr/bin/env bash
# disk_chart.sh — ext4 disk usage bar chart via gnuplot

OUTPUT="/home/kofler/disk_usage_latest.png"
DATA=$(df -t ext4 | tail -n +2 |
       awk '{printf "\"%s\" %.2f %.2f\n",
            $NF, $3/1048576, $4/1048576}')

gnuplot <<GNUPLOT
    set terminal pngcairo size 960,520 enhanced font "DejaVu Sans,11"
    set output '${OUTPUT}'
    set title "Disk Usage (ext4) — $(date '+%Y-%m-%d %H:%M')" font ",13"
    set ylabel "Space (GB)"; set yrange [0:*]
    set border 3; set tics out nomirror; set grid ytics lc rgb "#bbbbbb"
    set style data histogram; set style histogram rowstacked
    set style fill solid 0.85 border -1; set boxwidth 0.9
    set key top right box opaque
    \$DATA << EOD
${DATA}
EOD
    plot \$DATA using 2:xtic(1) title "Used" lc rgb "#D94F3D", \
                '' using 3     title "Available" lc rgb "#4A90D9"
GNUPLOT
