#!/bin/bash


inotifywait -mrq -e create,delete,move,close_write /opt/source-code/blog --exclude '^.*/avatar.jpg|^.*/\.git' | while read directory action filename; do
    echo ====================================================
    echo `date`
    echo $directory$filename $action
    rm -rf /opt/websites/blog
    let numOfAvatar=`ls /opt/websites/nav/assets/images/logos/ | wc -l`
    let randNumber=$RANDOM%$numOfAvatar

    cp /opt/websites/nav/assets/images/logos/${randNumber}.jpg /opt/websites/homepage/assets/img/logo.jpg -rf
    cp /opt/websites/nav/assets/images/logos/${randNumber}.jpg /opt/websites/nav/assets/images/logos/avatar.jpg -rf
    cp /opt/websites/nav/assets/images/logos/${randNumber}.jpg /opt/source-code/blog/img/avatar.jpg -rf
    jekyll b -s /opt/source-code/blog/ -d /opt/websites/blog/
    echo -e '\n'
done
