bk939448 commited on
Commit
ac644e7
·
verified ·
1 Parent(s): 61baa6f

Upload entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +54 -0
entrypoint.sh ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Ensure HF CLI is in PATH
4
+ export PATH="$HOME/.local/bin:$PATH"
5
+
6
+ # Set HF Token from Space Secrets
7
+ export HF_TOKEN="${HF_TOKEN}"
8
+
9
+ # Variables
10
+ BUCKET='hf://buckets/bk939448/opencodeai'
11
+ SOURCE='/data'
12
+
13
+ # Configure Git
14
+ git config --global user.email 'badal@example.com'
15
+ git config --global user.name 'Badal'
16
+
17
+ # Set OpenCode path
18
+ OP_PATH=$(find / -name opencode -type f -printf '%h' -quit 2>/dev/null)
19
+ export PATH="$OP_PATH:$PATH"
20
+
21
+ # ============================================
22
+ # STEP 1: RESTORE (Try, but continue if bucket empty)
23
+ # ============================================
24
+ echo '=== [STEP 1] RESTORING DATA FROM BUCKET ==='
25
+ if hf sync "$BUCKET" "$SOURCE" --delete 2>/dev/null; then
26
+ echo '=== [STEP 1] RESTORE COMPLETE ==='
27
+ else
28
+ echo '=== [STEP 1] Restore skipped (bucket empty or failed - continuing anyway) ==='
29
+ fi
30
+
31
+ # ============================================
32
+ # STEP 2: START OPENCODE
33
+ # ============================================
34
+ echo '=== [STEP 2] STARTING OPENCODE ==='
35
+ export OPENCODE_SERVER_USERNAME=${OPENCODE_SERVER_USERNAME}
36
+ export OPENCODE_SERVER_PASSWORD=${OPENCODE_SERVER_PASSWORD}
37
+ opencode web --port 7860 --hostname 0.0.0.0 > /tmp/opencode.log 2>&1 &
38
+ sleep 10
39
+ echo '=== [STEP 2] OPENCODE STARTED ==='
40
+
41
+ # ============================================
42
+ # STEP 3: REAL-TIME CONTINUOUS SYNC
43
+ # ============================================
44
+ echo '=== [STEP 3] STARTING REAL-TIME SYNC ==='
45
+ while true; do
46
+ # Check if OpenCode is still running
47
+ if ! pgrep -f 'opencode' > /dev/null; then
48
+ echo 'CRITICAL: OpenCode process died! Exiting container...'
49
+ exit 1
50
+ fi
51
+
52
+ # Real-time continuous sync (no interval - continuous!)
53
+ hf sync "$SOURCE" "$BUCKET" --delete
54
+ done