-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
51 lines (46 loc) · 1.51 KB
/
entrypoint.sh
File metadata and controls
51 lines (46 loc) · 1.51 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
#!/bin/bash
set -e
BACKUP_DIR="/workspace/.opencode-backup"
AUTH_FILE="/root/.local/share/opencode/auth.json"
CONFIG_FILE="/root/.config/opencode/opencode.json"
DB_FILE="/root/.local/share/opencode/opencode.db"
mkdir -p "$BACKUP_DIR"
backup() {
echo "[opencode-persist] Backing up state..."
cp -f "$AUTH_FILE" "$BACKUP_DIR/auth.json" 2>/dev/null || true
cp -f "$CONFIG_FILE" "$BACKUP_DIR/opencode.json" 2>/dev/null || true
cp -f "$DB_FILE" "$BACKUP_DIR/opencode.db" 2>/dev/null || true
echo "[opencode-persist] Backup complete."
}
restore() {
RESTORED=false
if [ ! -f "$AUTH_FILE" ] && [ -f "$BACKUP_DIR/auth.json" ]; then
mkdir -p "$(dirname "$AUTH_FILE")"
cp -f "$BACKUP_DIR/auth.json" "$AUTH_FILE"
chmod 600 "$AUTH_FILE"
RESTORED=true
echo "[opencode-persist] Restored auth.json"
fi
if [ ! -f "$CONFIG_FILE" ] && [ -f "$BACKUP_DIR/opencode.json" ]; then
mkdir -p "$(dirname "$CONFIG_FILE")"
cp -f "$BACKUP_DIR/opencode.json" "$CONFIG_FILE"
RESTORED=true
echo "[opencode-persist] Restored opencode.json"
fi
if [ ! -f "$DB_FILE" ] && [ -f "$BACKUP_DIR/opencode.db" ]; then
mkdir -p "$(dirname "$DB_FILE")"
cp -f "$BACKUP_DIR/opencode.db" "$DB_FILE"
RESTORED=true
echo "[opencode-persist] Restored opencode.db"
fi
if [ "$RESTORED" = true ]; then
echo "[opencode-persist] State restored from backup."
else
echo "[opencode-persist] No restore needed - state files present."
fi
}
case "$1" in
backup) backup ;;
restore) restore ;;
*) restore ;;
esac