File size: 1,361 Bytes
819ff17
d7efe47
819ff17
99f659f
 
 
 
 
15c36d3
99f659f
 
 
e251c22
99f659f
 
 
 
 
 
 
 
 
d7efe47
1b68410
99f659f
 
 
 
 
 
 
d7efe47
7facd24
99f659f
d7efe47
 
 
 
 
 
 
99f659f
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
#!/bin/bash
set -e

# 1. Configuration for Username/Password
# These will default to admin/admin if you don't set them in HF Space Secrets
NGX_NAME="${NGX_NAME:-admin}"
NGX_PASS="${NGX_PASS:-admin}"
PORT="${PORT:-7860}" # HF default port

# Generate the htpasswd file for Nginx in the root app folder
CRYPTPASS=$(openssl passwd -apr1 "${NGX_PASS}")
echo "${NGX_NAME}:${CRYPTPASS}" > /root/app/ngpasswd

echo "Login configured as: $NGX_NAME"

# 2. Fix Nginx Config Paths
# We assume nginx.conf is in /root/app/
COMMIT=$(cat /opt/openvscode-server/product.json | jq -r .commit)
sed -i "s/#COMMIT#/$COMMIT/g" /root/app/nginx.conf
sed -i "s/#PORT#/$PORT/g" /root/app/nginx.conf

# Start Nginx as root (since we called this script with sudo)
nginx -c /root/app/nginx.conf

# 3. Dataset Sync (Background)
# Pointing specifically to the root-level data folder
echo "Starting HF dataset sync to /root/app/data..."
python3 /root/app/scripts/sync_hf.py --destination /root/app/data &

# 4. Launch VS Code Server
# Forced to /root for everything
vscode="/opt/openvscode-server/bin/openvscode-server"

echo "Launching VSCode with Absolute Root access..."
exec $vscode \
    --host 0.0.0.0 \
    --port 5050 \
    --without-connection-token \
    --working-dir / \
    --user-data-dir /root/.vscode-server \
    --extensions-dir /root/.vscode-server/extensions \
    "${@}"