-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathupdateit.sh
More file actions
executable file
Β·151 lines (129 loc) Β· 4.46 KB
/
Copy pathupdateit.sh
File metadata and controls
executable file
Β·151 lines (129 loc) Β· 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env bash
set -euo pipefail
# Usage:
# ./updateit.sh "your commit message"
# Optional env vars:
# BACKUP_DIR=~/adictmlbackup
# BACKUP_MODE=rsync # or: cp
# BACKUP_KEEP_DAYS=30 # delete old timestamped backups (only for timestamp mode)
# BACKUP_LAYOUT=mirror # or: timestamp
#
# What it does:
# 1) runs your Python scripts
# 2) cleans LaTeX junk
# 3) commits & pushes main repo
# 4) backs up ALL TeX files starting with ADictML* (plus a few key assets)
# 5) commits & pushes the backup repo
MSG="${1:-}"
if [[ -z "$MSG" ]]; then
echo "ERROR: commit message missing."
echo "Usage: $0 \"commit message\""
exit 1
fi
BACKUP_DIR="${BACKUP_DIR:-$HOME/adictmlbackup}"
BACKUP_MODE="${BACKUP_MODE:-rsync}" # rsync | cp
BACKUP_LAYOUT="${BACKUP_LAYOUT:-mirror}" # mirror | timestamp
BACKUP_KEEP_DAYS="${BACKUP_KEEP_DAYS:-30}"
echo "[INFO] Commit message: $MSG"
echo "[INFO] Backup repo: $BACKUP_DIR"
echo "[INFO] Backup mode: $BACKUP_MODE"
echo "[INFO] Backup layout: $BACKUP_LAYOUT"
# --- Sanity checks ---
command -v python >/dev/null 2>&1 || { echo "ERROR: python not found in PATH"; exit 1; }
command -v git >/dev/null 2>&1 || { echo "ERROR: git not found in PATH"; exit 1; }
if [[ ! -d "$BACKUP_DIR/.git" ]]; then
echo "ERROR: BACKUP_DIR does not look like a git repo: $BACKUP_DIR"
echo "Tip: git clone <your-backup-remote> \"$BACKUP_DIR\""
exit 1
fi
# --- Run your generation scripts ---
# FlattenGlossary.py disabled β expanded tex variants removed
# echo "[INFO] Running FlattenGlossary.py ..."
# python assets/FlattenGlossary.py
echo "[INFO] Running DependencyGraph.py ..."
python assets/DependencyGraph.py
echo "[INFO] Running countterms.py ..."
python assets/countterms.py
# --- Clean LaTeX junk (flexible + safe) ---
echo "[INFO] Cleaning LaTeX temporary files ..."
find . -maxdepth 2 -type f \( \
-name "*.aux" -o -name "*.log" -o -name "*.out" -o -name "*.toc" -o \
-name "*.bbl" -o -name "*.blg" -o -name "*.dvi" -o -name "*.ist" -o \
-name "*.fls" -o -name "*.fdb_latexmk" -o -name "*.synctex.gz" -o \
-name "*.glo" -o -name "*.gls" -o -name "*.glg" -o \
-name "*-glg" -o -name "*-gls" -o -name "*-glo" \
\) -print -delete
# --- Commit & push main repo ---
echo "[INFO] Committing in main repo ..."
git add -A
git commit -m "$MSG" || echo "[INFO] No changes to commit in main repo."
git push origin main
# --- Backup selection ---
# All TeX files starting with ADictML* + a few important extras
# (Edit EXTRAS if you want.)
# --- Collect ADictML*.tex files (Bash 3.2 compatible) ---
TEX_FILES=()
while IFS= read -r f; do
TEX_FILES+=("$f")
done < <(find . -maxdepth 1 -type f -name 'ADictML*.tex' | sort)
EXTRAS=(
"ListSymbols_English.tex"
"assets/ml_macros.tex"
"assets/Literature.bib"
)
# Filter extras to existing files
EXTRAS_EXISTING=()
for f in "${EXTRAS[@]}"; do
[[ -e "$f" ]] && EXTRAS_EXISTING+=("$f")
done
if [[ "${#TEX_FILES[@]}" -eq 0 ]]; then
echo "[WARN] No files matched ADictML*.tex in repo root."
else
echo "[INFO] Found ${#TEX_FILES[@]} file(s) matching ADictML*.tex"
fi
# Decide destination layout inside backup repo
STAMP="$(date +%Y%m%d_%H%M%S)"
if [[ "$BACKUP_LAYOUT" == "timestamp" ]]; then
DEST="$BACKUP_DIR/snapshots/$STAMP"
mkdir -p "$DEST"
echo "[INFO] Timestamped backup destination: $DEST"
else
DEST="$BACKUP_DIR" # mirror into repo root
echo "[INFO] Mirror backup destination: $DEST"
fi
backup_copy_one() {
local src="$1"
local dst_root="$2"
local dst="$dst_root/$src"
mkdir -p "$(dirname "$dst")"
if [[ "$BACKUP_MODE" == "rsync" ]]; then
rsync -a --delete-after "$src" "$dst"
else
rm -rf "$dst"
cp -R "$src" "$dst"
fi
echo " β Backed up: $src"
}
echo "[INFO] Backing up ADictML*.tex and extras ..."
for f in "${TEX_FILES[@]}"; do
# TEX_FILES entries are relative like "./ADictML_Main.tex" from find; normalize to no leading ./
f="${f#./}"
backup_copy_one "$f" "$DEST"
done
for f in "${EXTRAS_EXISTING[@]}"; do
backup_copy_one "$f" "$DEST"
done
# Optionally delete old snapshots
if [[ "$BACKUP_LAYOUT" == "timestamp" ]]; then
echo "[INFO] Pruning snapshots older than ${BACKUP_KEEP_DAYS} days ..."
find "$BACKUP_DIR/snapshots" -mindepth 1 -maxdepth 1 -type d -mtime +"$BACKUP_KEEP_DAYS" -print -exec rm -rf {} \; || true
fi
# --- Commit & push inside the backup repo ---
echo "[INFO] Committing inside backup repository ..."
(
cd "$BACKUP_DIR"
git add -A
git commit -m "Backup: $MSG" || echo "[INFO] No changes to commit in backup repo."
git push
)
echo "[OK] Backup repo updated."