Spaces:
Paused
Paused
| 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 |