Save as setup.sh

#!/bin/zsh

echo “Starting full system setup… 🚀”

# — 1. Ensure Python 3 is Installed —
if ! command -v python3 &> /dev/null; then
echo “Python3 not found. Installing with Homebrew…”
/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)” brew install python
fi

# — 2. Create Necessary Directories —
TARGET_DIR=”$HOME/Documents/bots”
if [ ! -d “$TARGET_DIR” ]; then
echo “Creating missing directory: $TARGET_DIR”
mkdir -p “$TARGET_DIR”
fi

# — 3. Rename .save Files —
for file in *.py.save; do
[ -e “$file” ] || continue
newname=”${file%.save}”
mv “$file” “$newname”
echo “Renamed $file to $newname”
done

# — 4. Run All Python Scripts in the Folder —
for script in *.py; do
[ -e “$script” ] || continue
echo “Running $script…”
python3 “$script”
done

# — 5. Set Up Scheduled Tasks (Runs Scripts at 9 AM Daily) — (crontab -l; echo “0 9 * * * python3 $TARGET_DIR/main_script.py”) | crontab –

# — 6. Set Up GitHub Sync (Pull latest changes) —
if [ -d “$TARGET_DIR/.git” ]; then
cd “$TARGET_DIR”
git pull origin main
echo “Updated from GitHub!”
else
echo “GitHub repo not found. Skipping sync.”
fi

# — 7. Simple Telegram Bot Command (Triggers Script Remotely) — echo “Setting up Telegram bot trigger…”
cat < “$TARGET_DIR/bot_handler.py”
import os
import telegram
from telegram.ext import Application, CommandHandler
import subprocess

TOKEN = “YOUR_BOT_TOKEN”
TARGET_DIR = os.path.expanduser(“$TARGET_DIR”) # Ensures correct path handling

async def run_script(update, context):
process = subprocess.run([“python3″, f”{TARGET_DIR}/main_script.py”], capture_output=True, text=True) await update.message.reply_text(f”Script executed!\n{process.stdout}”)

app = Application.builder().token(TOKEN).build()
app.add_handler(CommandHandler(“run_script”, run_script))
app.run_polling()
EOF

echo “Setup complete! ✅”

Leave a comment