privateone commited on
Commit
972bac4
·
verified ·
1 Parent(s): 2389d11

Create init.sh

Browse files
Files changed (1) hide show
  1. init.sh +52 -0
init.sh ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e # Exit if any command fails
3
+
4
+ echo "🔐 GITHUB_PAT: ${GITHUB_PAT}" # Mask token in logs
5
+
6
+ # Define variables
7
+ REPO_URL="https://github.com/blendersb/teleapi.git"
8
+ BRANCH="main"
9
+ TARGET_DIR="/app/teleapi"
10
+ APP_DIR="/app"
11
+
12
+ # Only clone if GITHUB_PAT is set
13
+ if [ -n "$GITHUB_PAT" ]; then
14
+ echo "📥 GITHUB_PAT detected. Cloning private repository..."
15
+
16
+ # Clone only if the target directory does not exist
17
+ if [ ! -d "$TARGET_DIR" ]; then
18
+ git clone -b "$BRANCH" "https://blendersb:${GITHUB_PAT}@github.com/blendersb/teleapi.git" "$TARGET_DIR"
19
+ else
20
+ echo "✅ Repository already cloned at $TARGET_DIR"
21
+ fi
22
+ echo "📂 Moving contents from $TARGET_DIR to $APP_DIR..."
23
+ shopt -s dotglob # include hidden files like .env, .gitignore
24
+ mv "$TARGET_DIR"/* "$APP_DIR"/
25
+ rm -rf "$TARGET_DIR"
26
+ shopt -u dotglob
27
+
28
+ # Set permissions (optional)
29
+ echo "🔧 Setting main folder permissions..."
30
+ chmod -R +x "$APP_DIR"
31
+ chmod -R 777 "$APP_DIR/*"
32
+ echo "🔧 Setting sessions permissions..."
33
+ chmod -R 777 "$APP_DIR/clients_sessions"
34
+
35
+ # Install Python dependencies
36
+ if [ -f "$APP_DIR/requirements.txt" ]; then
37
+ echo "📦 Installing Python dependencies..."
38
+ pip3 install --no-cache-dir --upgrade -r "$APP_DIR/requirements.txt"
39
+ else
40
+ echo "⚠️ No requirements.txt found in $APP_DIR"
41
+ fi
42
+
43
+ # Change to repo directory
44
+ cd "$APP_DIR"
45
+ echo "✅ Init script complete. Starting application..."
46
+ # Start the actual app (from CMD)
47
+ exec "$@"
48
+ else
49
+ echo "ℹ️ GITHUB_PAT not set. Skipping clone step."
50
+ fi
51
+
52
+