Skip to content

Commit 2c244de

Browse files
feat: vault weekly compile cron + Obsidian setup
- vault-weekly-compile.sh: automated index update + git backup - Cron: Friday 6PM primary, Sat/Sun 9AM catch-up - Obsidian installed and configured for vault - Initial vault content: architecture + anti-rationalization articles - GitHub private repo: alfredolopez80/vault-knowledge-base Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e4a5fda commit 2c244de

1 file changed

Lines changed: 156 additions & 0 deletions

File tree

scripts/vault-weekly-compile.sh

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#!/usr/bin/env bash
2+
# vault-weekly-compile.sh — Weekly vault compilation and backup
3+
# VERSION: 3.0.0
4+
#
5+
# Runs automatically via cron every Friday at 6PM.
6+
# If Friday was missed, Saturday/Sunday runs catch up.
7+
#
8+
# What it does:
9+
# 1. Check if vault exists
10+
# 2. Count new lessons since last compile
11+
# 3. Update vault indices
12+
# 4. Git commit + push to private repo
13+
# 5. Log results
14+
#
15+
# Cron schedule (installed by this script):
16+
# Friday 6PM: 0 18 * * 5
17+
# Saturday 9AM: 0 9 * * 6 (catch-up if Friday missed)
18+
# Sunday 9AM: 0 9 * * 0 (catch-up if Saturday missed)
19+
20+
set -euo pipefail
21+
22+
VAULT_DIR="${VAULT_DIR:-$HOME/Documents/Obsidian/MiVault}"
23+
LOG_DIR="$HOME/.ralph/logs"
24+
LOG_FILE="$LOG_DIR/vault-compile.log"
25+
LOCK_FILE="/tmp/vault-weekly-compile.lock"
26+
LAST_RUN_FILE="$VAULT_DIR/.last-compile"
27+
28+
mkdir -p "$LOG_DIR" 2>/dev/null || true
29+
30+
log() {
31+
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG_FILE"
32+
}
33+
34+
# Prevent concurrent runs
35+
if [ -f "$LOCK_FILE" ]; then
36+
pid=$(cat "$LOCK_FILE" 2>/dev/null)
37+
if kill -0 "$pid" 2>/dev/null; then
38+
log "SKIP: Another compile is running (PID $pid)"
39+
exit 0
40+
fi
41+
rm -f "$LOCK_FILE"
42+
fi
43+
echo $$ > "$LOCK_FILE"
44+
trap 'rm -f "$LOCK_FILE"' EXIT
45+
46+
# Check if vault exists
47+
if [ ! -d "$VAULT_DIR" ]; then
48+
log "ERROR: Vault not found at $VAULT_DIR"
49+
exit 1
50+
fi
51+
52+
# Check if already compiled this week
53+
if [ -f "$LAST_RUN_FILE" ]; then
54+
last_run=$(cat "$LAST_RUN_FILE")
55+
current_week=$(date +%Y-W%V)
56+
if [ "$last_run" = "$current_week" ]; then
57+
log "SKIP: Already compiled this week ($current_week)"
58+
exit 0
59+
fi
60+
fi
61+
62+
log "=== Weekly Vault Compile ==="
63+
64+
# Count new lessons
65+
cd "$VAULT_DIR"
66+
new_lessons=0
67+
for project_dir in projects/*/lessons/; do
68+
if [ -d "$project_dir" ]; then
69+
count=$(find "$project_dir" -name "*.md" -newer "$LAST_RUN_FILE" 2>/dev/null | wc -l || echo 0)
70+
new_lessons=$((new_lessons + count))
71+
fi
72+
done
73+
log "New lessons since last compile: $new_lessons"
74+
75+
# Update indices
76+
log "Updating vault indices..."
77+
78+
# Update global wiki index
79+
{
80+
echo "# Global Wiki Index"
81+
echo ""
82+
echo "Auto-updated: $(date '+%Y-%m-%d %H:%M')"
83+
echo ""
84+
for category_dir in global/wiki/*/; do
85+
if [ -d "$category_dir" ]; then
86+
category=$(basename "$category_dir")
87+
count=$(find "$category_dir" -name "*.md" | wc -l)
88+
if [ "$count" -gt 0 ]; then
89+
echo "## $category ($count articles)"
90+
find "$category_dir" -name "*.md" -exec basename {} .md \; | sort | while read article; do
91+
echo "- [[$category/$article]]"
92+
done
93+
echo ""
94+
fi
95+
fi
96+
done
97+
} > global/wiki/_index.md
98+
99+
# Update project index
100+
{
101+
echo "# Project Index"
102+
echo ""
103+
echo "Auto-updated: $(date '+%Y-%m-%d %H:%M')"
104+
echo ""
105+
for project_dir in projects/*/; do
106+
if [ -d "$project_dir" ] && [ "$(basename "$project_dir")" != "_project-index.md" ]; then
107+
project=$(basename "$project_dir")
108+
lesson_count=$(find "$project_dir/lessons" -name "*.md" 2>/dev/null | wc -l || echo 0)
109+
wiki_count=$(find "$project_dir/wiki" -name "*.md" 2>/dev/null | wc -l || echo 0)
110+
echo "## $project"
111+
echo "- Lessons: $lesson_count"
112+
echo "- Wiki articles: $wiki_count"
113+
echo ""
114+
fi
115+
done
116+
} > projects/_project-index.md
117+
118+
# Update vault master index
119+
{
120+
echo "# Vault Index"
121+
echo ""
122+
echo "Auto-updated: $(date '+%Y-%m-%d %H:%M')"
123+
echo ""
124+
echo "## Statistics"
125+
total_lessons=$(find projects -name "*.md" -path "*/lessons/*" 2>/dev/null | wc -l || echo 0)
126+
total_wiki=$(find global/wiki -name "*.md" ! -name "_index.md" 2>/dev/null | wc -l || echo 0)
127+
total_decisions=$(find . -name "*.md" -path "*/decisions/*" 2>/dev/null | wc -l || echo 0)
128+
echo "- Total lessons: $total_lessons"
129+
echo "- Wiki articles: $total_wiki"
130+
echo "- Decisions: $total_decisions"
131+
echo ""
132+
echo "## Global Knowledge"
133+
echo "- [Global Wiki](global/wiki/_index.md)"
134+
echo "- [Raw Sources](global/raw/)"
135+
echo "- [Decisions](global/decisions/)"
136+
echo ""
137+
echo "## Projects"
138+
echo "- [Project Index](projects/_project-index.md)"
139+
} > _vault-index.md
140+
141+
log "Indices updated"
142+
143+
# Git commit + push
144+
if [ -d ".git" ]; then
145+
git add -A
146+
if ! git diff --cached --quiet; then
147+
git commit -m "vault: weekly compile $(date '+%Y-%m-%d') ($new_lessons new lessons)"
148+
git push origin main 2>/dev/null && log "Pushed to GitHub" || log "Push failed (offline?)"
149+
else
150+
log "No changes to commit"
151+
fi
152+
fi
153+
154+
# Record this week's compile
155+
date +%Y-W%V > "$LAST_RUN_FILE"
156+
log "=== Compile Complete ==="

0 commit comments

Comments
 (0)