| #!/bin/sh |
|
|
| |
| if [ -z "$GIT_TOKEN" ]; then |
| echo "❌ ERROR: GIT_TOKEN is not set!" |
| exit 1 |
| fi |
|
|
| REPO_URL="https://$GIT_TOKEN@github.com/appujohn007/Mega-Downloader-API.git" |
| TARGET="/app/repo" |
|
|
| echo "📌 Cloning private repo into /app/repo ..." |
| git clone "$REPO_URL" "$TARGET" |
|
|
| echo "📌 Copying project files..." |
| cp -r "$TARGET"/* /app/ |
|
|
| |
| if [ -f "/app/requirements.txt" ]; then |
| echo "📦 Installing requirements..." |
| pip install --no-cache-dir -r /app/requirements.txt |
| pip install uvicorn |
| else |
| echo "⚠️ No requirements.txt found." |
| fi |
|
|
| |
| STATUS_FILE="/tmp/tor_status" |
| echo "initializing" > "$STATUS_FILE" |
|
|
| |
| |
| |
| echo "🚀 Starting Web App (Uvicorn)..." |
| uvicorn main:app --host 0.0.0.0 --port 7860 & |
| APP_PID=$! |
|
|
| |
| |
| |
| PIPE=/tmp/tor_log_pipe |
| mkfifo $PIPE |
|
|
| while true; do |
| echo "------------------------------------------------" |
| echo "🧅 Starting Tor Proxy..." |
| echo "------------------------------------------------" |
| echo "restarting" > "$STATUS_FILE" |
| |
| tor > $PIPE 2>&1 & |
| TOR_PID=$! |
| |
| start_time=$(date +%s) |
| bootstrapped=false |
|
|
| while read -r line; do |
| echo "$line" |
|
|
| |
| if echo "$line" | grep -q "Bootstrapped 100%"; then |
| if [ "$bootstrapped" = "false" ]; then |
| echo "✅ Tor Status: SUCCESS (100% Bootstrapped)" |
| echo "working" > "$STATUS_FILE" |
| bootstrapped=true |
| fi |
| fi |
|
|
| |
| if [ "$bootstrapped" = "false" ]; then |
| current_time=$(date +%s) |
| elapsed=$((current_time - start_time)) |
| |
| if [ "$elapsed" -ge 180 ]; then |
| echo "⚠️ Timeout: Tor stuck. Restarting..." |
| kill -9 $TOR_PID |
| break |
| fi |
| fi |
| done < $PIPE |
|
|
| wait $TOR_PID |
| echo "🔄 Tor process ended. Re-looping..." |
| rm -f $PIPE |
| mkfifo $PIPE |
| done |