#!/bin/bash
:<<'__COMMENT__'
auto_push_notes.bash v1.2
Julián
- Detect any modification
- Update remote repository
- Update website
- Manage links
__COMMENT__
set -euo pipefail
OBSIDIAN_DIR="/path/to/Obsidian/files"
WEBSITE_DIR="/var/www/<website_name>/"
echo "[$(date '+%F %T')] >>> auto_push_notes.bash"
while true; do
inotifywait -r \
--exclude '/\..*' \
-e modify,create,delete,move $OBSIDIAN_DIR || continue
# inotifywait
echo "[$(date '+%F %T')] [inotifywait] Change detected"
# Git
echo "[$(date '+%F %T')] [Git] Committing and pushing..."
cd "$OBSIDIAN_DIR" || {
echo "[$(date '+%F %T')] Error: Failed to change directory to $OBSIDIAN_DIR"
exit 1
}
git add .
timestamp=$(date "+%F %T")
git commit -m "VPS auto-commit ${timestamp}" || echo "Nothing to commit"
git push origin main
# Hugo
echo "[$(date '+%F %T')] [Hugo] Deploying website..."
cd "$WEBSITE_DIR" || {
echo "[$(date '+%F %T')] Error: Failed to change directory to $WEBSITE_DIR"
exit 1
}
#hugo
hugo --cleanDestinationDir
python3 ~/mod_notes_links.py
done