Spaces:
Paused
Paused
File size: 2,478 Bytes
48500af |
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
#!/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 |