rachkovii68 commited on
Commit
0479a78
·
verified ·
1 Parent(s): 8e86364

Update start.sh

Browse files
Files changed (1) hide show
  1. start.sh +32 -11
start.sh CHANGED
@@ -1,18 +1,39 @@
1
  #!/bin/bash
2
 
3
- # --- Git and SSH Setup (Corrected for non-root) ---
4
- echo "Setting up SSH for Git in a temporary directory..."
5
- SSH_DIR="/tmp/.ssh"
6
- mkdir -p "$SSH_DIR"
7
-
8
- # This assumes the key is copied to /opt/app/id_rsa_huggingface in the Dockerfile
9
- if [ -f "/opt/app/id_rsa_huggingface" ]; then
10
- cp /opt/app/id_rsa_huggingface "$SSH_DIR/id_rsa"
11
- chmod 600 "$SSH_DIR/id_rsa"
12
- echo "SSH key prepared."
13
  else
14
- echo "Warning: SSH key /opt/app/id_rsa_huggingface not found."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  fi
 
 
16
 
17
  echo "Cloning/updating repository..."
18
  # Use GIT_SSH_COMMAND to specify key and options without writing to system files
 
1
  #!/bin/bash
2
 
3
+ # --- Git and SSH Setup (Using Secrets) ---
4
+ echo "Setting up SSH for Git..."
5
+
6
+ # Check if the SSH_PRIVATE_KEY secret is provided from Hugging Face Space secrets
7
+ if [ -z "$SSH_PRIVATE_KEY" ]; then
8
+ echo "Warning: SSH_PRIVATE_KEY secret is not set. Skipping git synchronization."
 
 
 
 
9
  else
10
+ echo "SSH_PRIVATE_KEY secret found. Setting up for git synchronization..."
11
+ SSH_DIR="/tmp/.ssh"
12
+ mkdir -p "$SSH_DIR"
13
+
14
+ # Write the key from the environment variable to a file. Use -e to handle newlines.
15
+ echo -e "$SSH_PRIVATE_KEY" > "$SSH_DIR/id_rsa"
16
+ chmod 600 "$SSH_DIR/id_rsa"
17
+ echo "SSH key prepared from secret."
18
+
19
+ # Use GIT_SSH_COMMAND to specify key and options
20
+ export GIT_SSH_COMMAND="ssh -i $SSH_DIR/id_rsa -o StrictHostKeyChecking=no"
21
+
22
+ echo "Cloning/updating repository..."
23
+ # Clone the repository into the persistent /data directory if it doesn't exist
24
+ if [ ! -d "/data/.git" ]; then
25
+ # Clone to a temporary directory and move contents to /data
26
+ git clone git@hf.co:spaces/rachkovii68/x-ui /tmp/repo
27
+ mv /tmp/repo/.git /data/
28
+ else
29
+ echo "Repo already exists in /data. Pulling latest changes."
30
+ cd /data
31
+ git pull
32
+ cd /
33
+ fi
34
  fi
35
+ # --- End Git and SSH Setup ---
36
+
37
 
38
  echo "Cloning/updating repository..."
39
  # Use GIT_SSH_COMMAND to specify key and options without writing to system files