#!/usr/bin/env bash
# Watches for changes to the source files and re-generates the Ignition config.

cd $( dirname "$0" )
prev_md5=
while true; do
    md5=$( md5sum config.bu files/* )
    if [ "$md5" = "$prev_md5" ]; then
        sleep 1
    else
        if butane --pretty --strict --files-dir ./files/ config.bu >config.ign; then
            echo "Updated: `date`"             
        fi                                     
        prev_md5=$md5         
done
