#!/bin/bash set -e # Exit if any command fails # echo "🔐 GITHUB_PAT: ${GITHUB_PAT}" # Mask token in logs # Define variables #REPO_URL="https://github.com/blendersb/teleapi.git" BRANCH="${BRANCH:=main}" TARGET_DIR="/app/One_Stream" APP_DIR="/app" # Only clone if GITHUB_PAT is set if [ -n "$GITHUB_PATH" ]; then echo "đŸ“Ĩ GITHUB_PAT detected. Cloning private repository..." # Clone only if the target directory does not exist if [ ! -d "$TARGET_DIR" ]; then if [ -n "$CODE_REPO" ]; then echo "đŸ“Ĩ CODE_REPOSITRY detected. Cloning private repository..." git clone -b "$BRANCH" "$CODE_REPO" "$TARGET_DIR" else echo "đŸ“Ĩ Cloning private repository..." git clone -b "$BRANCH" "$GITHUB_PATH" "$TARGET_DIR" fi cd "$TARGET_DIR" echo "📝 Latest Git Commit:" git log -1 --pretty=format:"🔹 %h 🔹 %s 🔹 by %an 🔹 on %ad" --date=short echo echo "📂 Moving contents from $TARGET_DIR to $APP_DIR..." shopt -s dotglob # include hidden files like .env, .gitignore mv "$TARGET_DIR"/* "$APP_DIR"/ rm -rf "$TARGET_DIR" shopt -u dotglob # Set permissions (optional) #echo "🔧 Setting main folder permissions..." #chmod -R +x "$APP_DIR" #chmod -R 777 "$APP_DIR" ls -la "$APP_DIR" #echo "🔧 Setting up sessions & permissions..." #SESSION_DIR="$APP_DIR/sessions" #chmod -R 777 "$APP_DIR/sessions" #echo "🔍 Scanning files in: $SESSION_DIR" #echo #find "$SESSION_DIR" -type f | while read -r file; do # perms=$(stat -c "%A" "$file") # Get permission string # if [ -w "$file" ]; then # writable="✅ Writable" # else # writable="❌ Not Writable" # fi # echo "$perms $writable → $file" # # rm -rf "$file" #done else echo "✅ Repository already cloned at $TARGET_DIR" fi # Change to repo directory cd "$APP_DIR" # Install Python dependencies if [ -f "$APP_DIR/requirements.txt" ]; then echo "đŸ“Ļ Installing Python dependencies..." pip3 install --no-cache-dir --upgrade -r "requirements.txt" else echo "âš ī¸ No requirements.txt found in $APP_DIR" fi echo "✅ Init script complete. Starting application..." # Start the actual app (from CMD) exec "$@" else echo "â„šī¸ GITHUB_PAT not set. Skipping clone step." fi