Bjo53 commited on
Commit
e46ab0f
·
verified ·
1 Parent(s): 3eba72b

Upload startup.sh with huggingface_hub

Browse files
Files changed (1) hide show
  1. startup.sh +40 -16
startup.sh CHANGED
@@ -1,6 +1,9 @@
1
  #!/bin/bash
2
  echo "===== Startup $(date) ====="
3
 
 
 
 
4
  # Install huggingface_hub
5
  pip3 install --no-cache-dir -q huggingface_hub==0.23.0 --break-system-packages 2>/dev/null
6
 
@@ -13,17 +16,17 @@ fi
13
 
14
  # Install Claude CLI
15
  echo "[Install] Claude CLI..."
16
- npm install -g @anthropic-ai/claude-code
17
 
18
  # Install Codex CLI
19
  echo "[Install] Codex CLI..."
20
- npm install -g @openai/codex
21
 
22
- # Install OpenHands
23
- echo "[Install] OpenHands..."
24
- pip3 install --break-system-packages -q openhands
25
 
26
- # Restore from dataset
27
  if [ -n "$HF_TOKEN" ] && [ -n "$HF_USERNAME" ]; then
28
  echo "[Storage] Restoring from dataset..."
29
  python3 -c "
@@ -39,15 +42,10 @@ except: print('[Storage] Fresh start')
39
  " 2>/dev/null
40
  fi
41
 
42
- mkdir -p /persistent
43
-
44
- # Start keep-alive
45
- python3 /app/keepalive.py &
46
-
47
- # Auto-backup every 5 min
48
  python3 -c "
49
- import os, time, threading
50
- def backup():
51
  while True:
52
  time.sleep(300)
53
  token = os.environ.get('HF_TOKEN')
@@ -55,9 +53,35 @@ def backup():
55
  if token and username:
56
  try:
57
  from huggingface_hub import HfApi
58
- HfApi(token=token).upload_folder(folder_path='/persistent', repo_id=f'{username}/vps-storage', repo_type='dataset', commit_message='auto-backup')
 
 
 
 
 
 
 
 
59
  except: pass
60
- threading.Thread(target=backup, daemon=True).start()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  " &
62
 
63
  exec uvicorn app:app --host 0.0.0.0 --port 7860 --ws websockets --proxy-headers --forwarded-allow-ips="*"
 
1
  #!/bin/bash
2
  echo "===== Startup $(date) ====="
3
 
4
+ # Security: Set restrictive permissions
5
+ umask 077
6
+
7
  # Install huggingface_hub
8
  pip3 install --no-cache-dir -q huggingface_hub==0.23.0 --break-system-packages 2>/dev/null
9
 
 
16
 
17
  # Install Claude CLI
18
  echo "[Install] Claude CLI..."
19
+ npm install -g @anthropic-ai/claude-code 2>/dev/null
20
 
21
  # Install Codex CLI
22
  echo "[Install] Codex CLI..."
23
+ npm install -g @openai/codex 2>/dev/null
24
 
25
+ # Create secure storage
26
+ mkdir -p /persistent/.secrets
27
+ chmod 700 /persistent/.secrets
28
 
29
+ # Restore from dataset (encrypted)
30
  if [ -n "$HF_TOKEN" ] && [ -n "$HF_USERNAME" ]; then
31
  echo "[Storage] Restoring from dataset..."
32
  python3 -c "
 
42
  " 2>/dev/null
43
  fi
44
 
45
+ # Secure backup (only backs up code, not secrets)
 
 
 
 
 
46
  python3 -c "
47
+ import os, time, threading, hashlib
48
+ def secure_backup():
49
  while True:
50
  time.sleep(300)
51
  token = os.environ.get('HF_TOKEN')
 
53
  if token and username:
54
  try:
55
  from huggingface_hub import HfApi
56
+ api = HfApi(token=token)
57
+ # Only upload code files, skip secrets
58
+ api.upload_folder(
59
+ folder_path='/persistent',
60
+ repo_id=f'{username}/vps-storage',
61
+ repo_type='dataset',
62
+ ignore_patterns=['.secrets/', '*.key', '*.pem', '.env'],
63
+ commit_message='secure-backup'
64
+ )
65
  except: pass
66
+ threading.Thread(target=secure_backup, daemon=True).start()
67
+ " &
68
+
69
+ # Keep-alive ping (human-like)
70
+ python3 -c "
71
+ import os, time, random, threading, requests
72
+ def ping():
73
+ while True:
74
+ try:
75
+ host = os.environ.get('SPACE_HOST','')
76
+ if host:
77
+ headers = {
78
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
79
+ 'Accept': 'text/html,application/xhtml+xml',
80
+ }
81
+ requests.get(f'https://{host}/', headers=headers, timeout=10)
82
+ except: pass
83
+ time.sleep(random.randint(900, 3600))
84
+ threading.Thread(target=ping, daemon=True).start()
85
  " &
86
 
87
  exec uvicorn app:app --host 0.0.0.0 --port 7860 --ws websockets --proxy-headers --forwarded-allow-ips="*"