Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 1 addition & 25 deletions home-manager/services/cliproxyapi/scripts/backup-auth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ CONFIG_DIR="$HOME/.cli-proxy-api"
BACKUP_DIR="s3://cliproxyapi/backup/auths/"
MAIN_DIR="s3://cliproxyapi/auths/"
AUTH_DIR="$CONFIG_DIR/objectstore/auths"
DOTFILES_AUTH_DIR="$HOME/dotfiles/objectstore/auths"
CCS_AUTH_DIR="$HOME/.ccs/cliproxy/auth"

# STEP 1: Pull from R2 to local (captures files created by cliproxyapi directly in R2)
Expand All @@ -32,22 +31,7 @@ if [ -n "${OBJECTSTORE_ENDPOINT:-}" ]; then
"$AUTH_DIR/" 2>/dev/null && echo "✅ Pulled from R2 backup/auths/" >&2 || true
fi

# STEP 2: Merge missing files from dotfiles (macOS only)
# Uses --ignore-existing to never overwrite files from R2, only fill gaps
# This recovers files that may have been deleted from R2 but exist in git
# No circular loop risk since dotfiles is not in WatchPaths
if [ "$(uname)" = "Darwin" ]; then
if [ -d "$DOTFILES_AUTH_DIR" ] && [ -n "$(ls -A "$DOTFILES_AUTH_DIR" 2>/dev/null)" ]; then
before_count=$(find "$AUTH_DIR" -maxdepth 1 -type f 2>/dev/null | wc -l | tr -d ' ')
@rsync@ -a --ignore-existing "$DOTFILES_AUTH_DIR/" "$AUTH_DIR/"
after_count=$(find "$AUTH_DIR" -maxdepth 1 -type f 2>/dev/null | wc -l | tr -d ' ')
if [ "$after_count" -gt "$before_count" ]; then
echo "✅ Recovered $((after_count - before_count)) missing file(s) from dotfiles" >&2
fi
fi
fi

# STEP 3: Sync from ccs auth dir (picks up files created by ccs's internal cliproxy)
# STEP 2: Sync from ccs auth dir (picks up files created by ccs's internal cliproxy)
if [ -d "$CCS_AUTH_DIR" ] && [ -n "$(ls -A "$CCS_AUTH_DIR" 2>/dev/null)" ]; then
@rsync@ -a "$CCS_AUTH_DIR/" "$AUTH_DIR/"
echo "✅ Synced from ccs auth dir to local cache" >&2
Expand Down Expand Up @@ -83,12 +67,4 @@ if [ -d "$AUTH_DIR" ] && [ -n "$(ls -A "$AUTH_DIR" 2>/dev/null)" ]; then
mkdir -p "$CCS_AUTH_DIR"
@rsync@ -a "$AUTH_DIR/" "$CCS_AUTH_DIR/"
echo "✅ Synced to ccs auth dir" >&2

# macOS only: Sync back to dotfiles repo for git tracking
# (Skipped on Linux to avoid redundant auth file copies)
if [ "$(uname)" = "Darwin" ]; then
mkdir -p "$DOTFILES_AUTH_DIR"
@rsync@ -a "$AUTH_DIR/" "$DOTFILES_AUTH_DIR/"
echo "✅ Synced to dotfiles repo" >&2
fi
fi
24 changes: 1 addition & 23 deletions home-manager/services/cliproxyapi/scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,7 @@ if [ -n "${OBJECTSTORE_ENDPOINT:-}" ] && [ -n "${OBJECTSTORE_ACCESS_KEY:-}" ]; t
"s3://cliproxyapi/backup/auths/" \
"$AUTH_DIR/" 2>/dev/null && echo "✅ Pulled from R2 backup/auths/" >&2 || true

# macOS only: Always merge missing files from git-tracked dotfiles
# Uses --ignore-existing to never overwrite newer files from R2
# This ensures files deleted from R2 are recovered from git backup
# (Skipped on Linux to avoid redundant auth file copies)
if [ "$(uname)" = "Darwin" ]; then
DOTFILES_AUTH_DIR="$HOME/dotfiles/objectstore/auths"
if [ -d "$DOTFILES_AUTH_DIR" ] && [ -n "$(ls -A "$DOTFILES_AUTH_DIR" 2>/dev/null)" ]; then
# Count files before merge
before_count=$(find "$AUTH_DIR" -maxdepth 1 -type f 2>/dev/null | wc -l | tr -d ' ')

# Merge missing files from dotfiles (never overwrite existing)
@rsync@ -a --ignore-existing "$DOTFILES_AUTH_DIR/" "$AUTH_DIR/"

# Count files after merge
after_count=$(find "$AUTH_DIR" -maxdepth 1 -type f 2>/dev/null | wc -l | tr -d ' ')

if [ "$after_count" -gt "$before_count" ]; then
echo "✅ Restored $((after_count - before_count)) missing auth file(s) from dotfiles" >&2
fi
fi
fi

# CRITICAL: Always sync local auth files to R2 after merge
# CRITICAL: Always sync local auth files back to R2 after pulling
# This ensures any files that exist locally but not in R2 get uploaded,
# preventing "key does not exist" errors when cliproxyapi reads from object storage
if [ -d "$AUTH_DIR" ] && [ -n "$(ls -A "$AUTH_DIR" 2>/dev/null)" ]; then
Expand Down
Loading