84 lines
3.5 KiB
Bash
84 lines
3.5 KiB
Bash
|
|
#!/bin/bash
|
||
|
|
# ╔══════════════════════════════════════════════════════════════════╗
|
||
|
|
# ║ arch-dev :: entrypoint ║
|
||
|
|
# ║ Seeds /home/dev from skel template on first run. ║
|
||
|
|
# ║ Updates dotfiles when image is newer than home. ║
|
||
|
|
# ║ Initializes git for snapshot/rollback functionality. ║
|
||
|
|
# ╚══════════════════════════════════════════════════════════════════╝
|
||
|
|
|
||
|
|
set -e
|
||
|
|
|
||
|
|
SKEL=/etc/skel-arch-dev
|
||
|
|
HOME_DIR=/home/dev
|
||
|
|
MARKER="$HOME_DIR/.arch-dev-initialized"
|
||
|
|
GITDIR="$HOME_DIR/.arch-dev-state"
|
||
|
|
|
||
|
|
# ── First run: seed everything from skel ──────────────────────────────────────
|
||
|
|
if [[ ! -f "$MARKER" ]]; then
|
||
|
|
echo "🌱 arch-dev: first run — seeding home from skeleton..."
|
||
|
|
# Copy everything except things that should not exist yet
|
||
|
|
rsync -a --chown=dev:dev "$SKEL/" "$HOME_DIR/"
|
||
|
|
|
||
|
|
# Initialize git repo for snapshots
|
||
|
|
cd "$HOME_DIR"
|
||
|
|
git init --quiet --separate-git-dir="$GITDIR" .
|
||
|
|
git --git-dir="$GITDIR" --work-tree="$HOME_DIR" config user.name "arch-dev"
|
||
|
|
git --git-dir="$GITDIR" --work-tree="$HOME_DIR" config user.email "dev@arch-dev.local"
|
||
|
|
|
||
|
|
# Write .gitignore to exclude noise
|
||
|
|
cat > "$HOME_DIR/.gitignore" <<'GITIGNORE'
|
||
|
|
# Caches and logs
|
||
|
|
.cache/
|
||
|
|
.local/state/
|
||
|
|
.local/share/nvim/log
|
||
|
|
.local/share/nvim/lazy-lock.json.bak
|
||
|
|
.npm/
|
||
|
|
__pycache__/
|
||
|
|
*.pyc
|
||
|
|
|
||
|
|
# History (intentional — too noisy to track)
|
||
|
|
.zsh_history
|
||
|
|
.lesshst
|
||
|
|
.bash_history
|
||
|
|
.python_history
|
||
|
|
|
||
|
|
# Compiled neovim plugin caches
|
||
|
|
.local/share/nvim/lazy/*/plugin/packer_compiled.lua
|
||
|
|
|
||
|
|
# Trash
|
||
|
|
.local/share/Trash/
|
||
|
|
GITIGNORE
|
||
|
|
|
||
|
|
git --git-dir="$GITDIR" --work-tree="$HOME_DIR" add -A
|
||
|
|
git --git-dir="$GITDIR" --work-tree="$HOME_DIR" commit -q -m "initial: arch-dev skeleton baked"
|
||
|
|
git --git-dir="$GITDIR" --work-tree="$HOME_DIR" tag -a "skeleton" -m "factory state"
|
||
|
|
|
||
|
|
touch "$MARKER"
|
||
|
|
echo "✓ arch-dev: home initialized with snapshot 'skeleton'"
|
||
|
|
|
||
|
|
# ── Subsequent runs: refresh dotfiles only if image is newer ──────────────────
|
||
|
|
else
|
||
|
|
SKEL_TIME=$(stat -c %Y "$SKEL/.zshrc" 2>/dev/null || echo 0)
|
||
|
|
HOME_TIME=$(stat -c %Y "$HOME_DIR/.zshrc" 2>/dev/null || echo 0)
|
||
|
|
|
||
|
|
if [[ "$SKEL_TIME" -gt "$HOME_TIME" ]]; then
|
||
|
|
echo "🔄 arch-dev: image dotfiles newer than home — updating..."
|
||
|
|
# Auto-snapshot before updating, in case user wants to revert
|
||
|
|
if [[ -d "$GITDIR" ]]; then
|
||
|
|
git --git-dir="$GITDIR" --work-tree="$HOME_DIR" add -A 2>/dev/null
|
||
|
|
git --git-dir="$GITDIR" --work-tree="$HOME_DIR" \
|
||
|
|
commit -q -m "auto: pre-update snapshot $(date +%Y%m%d-%H%M%S)" 2>/dev/null || true
|
||
|
|
fi
|
||
|
|
# Refresh only the dotfiles, not user data
|
||
|
|
rsync -a --chown=dev:dev \
|
||
|
|
--exclude='.local/share/nvim/lazy' \
|
||
|
|
--exclude='.cache' \
|
||
|
|
"$SKEL/" "$HOME_DIR/"
|
||
|
|
echo "✓ arch-dev: dotfiles updated (auto-snapshot taken first)"
|
||
|
|
fi
|
||
|
|
fi
|
||
|
|
|
||
|
|
# ── Hand off ──────────────────────────────────────────────────────────────────
|
||
|
|
cd "$HOME_DIR"
|
||
|
|
exec "$@"
|