From dd2ce7e81f54c9a08266f742682ce648813eac8f Mon Sep 17 00:00:00 2001 From: Azreen Jamal Date: Tue, 3 Mar 2026 04:16:27 +0800 Subject: [PATCH] telegram bot: launchd install/uninstall scripts for macOS --- telegram-bot/.gitignore | 1 + telegram-bot/bot.err | 24 +++++++++++++++++ telegram-bot/bot.log | 3 +++ telegram-bot/install.sh | 54 +++++++++++++++++++++++++++++++++++++++ telegram-bot/uninstall.sh | 5 ++++ 5 files changed, 87 insertions(+) create mode 100644 telegram-bot/bot.err create mode 100644 telegram-bot/bot.log create mode 100755 telegram-bot/install.sh create mode 100755 telegram-bot/uninstall.sh diff --git a/telegram-bot/.gitignore b/telegram-bot/.gitignore index a14702c..a201dc1 100644 --- a/telegram-bot/.gitignore +++ b/telegram-bot/.gitignore @@ -32,3 +32,4 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json # Finder (MacOS) folder config .DS_Store +bot.log\nbot.err diff --git a/telegram-bot/bot.err b/telegram-bot/bot.err new file mode 100644 index 0000000..8587574 --- /dev/null +++ b/telegram-bot/bot.err @@ -0,0 +1,24 @@ + 9 | const SSH_USER = process.env.SSH_USER || "root"; +10 | const SSH_HOST = process.env.SSH_HOST!; +11 | const SSH_PORT = process.env.SSH_PORT || "22"; +12 | const ALLOWED_USERS = process.env.TELEGRAM_ALLOWED_USERS?.split(",").map(Number) || []; +13 | +14 | if (!BOT_TOKEN) throw new Error("TELEGRAM_BOT_TOKEN missing from .env"); + ^ +error: TELEGRAM_BOT_TOKEN missing from .env + at /Users/azreenjamal/pi-vs-claude-code/telegram-bot/index.ts:14:27 + at loadAndEvaluateModule (2:1) + +Bun v1.3.10 (macOS arm64) + 9 | const SSH_USER = process.env.SSH_USER || "root"; +10 | const SSH_HOST = process.env.SSH_HOST!; +11 | const SSH_PORT = process.env.SSH_PORT || "22"; +12 | const ALLOWED_USERS = process.env.TELEGRAM_ALLOWED_USERS?.split(",").map(Number) || []; +13 | +14 | if (!BOT_TOKEN) throw new Error("TELEGRAM_BOT_TOKEN missing from .env"); + ^ +error: TELEGRAM_BOT_TOKEN missing from .env + at /Users/azreenjamal/pi-vs-claude-code/telegram-bot/index.ts:14:27 + at loadAndEvaluateModule (2:1) + +Bun v1.3.10 (macOS arm64) diff --git a/telegram-bot/bot.log b/telegram-bot/bot.log new file mode 100644 index 0000000..a5c1bb5 --- /dev/null +++ b/telegram-bot/bot.log @@ -0,0 +1,3 @@ +🚀 Bot starting... +✅ @cr_management_smart_bot is live +🔧 [775071081] run_command: free -h diff --git a/telegram-bot/install.sh b/telegram-bot/install.sh new file mode 100755 index 0000000..ce6a611 --- /dev/null +++ b/telegram-bot/install.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# Install telegram bot as a macOS launchd service (auto-start on boot) +set -e + +BOT_DIR="$(cd "$(dirname "$0")" && pwd)" +PROJECT_DIR="$(dirname "$BOT_DIR")" +BUN_PATH="$(which bun)" +PLIST_NAME="com.cr.telegram-bot" +PLIST_PATH="$HOME/Library/LaunchAgents/${PLIST_NAME}.plist" + +if [ -z "$BUN_PATH" ]; then + echo "❌ bun not found in PATH" + exit 1 +fi + +if [ ! -f "$PROJECT_DIR/.env" ]; then + echo "❌ .env not found at $PROJECT_DIR/.env" + exit 1 +fi + +# Unload if already installed +launchctl unload "$PLIST_PATH" 2>/dev/null || true + +cat > "$PLIST_PATH" < + + + + Label + ${PLIST_NAME} + ProgramArguments + + /bin/bash + -c + source ${PROJECT_DIR}/.env && exec ${BUN_PATH} run ${BOT_DIR}/index.ts + + WorkingDirectory + ${BOT_DIR} + RunAtLoad + + KeepAlive + + StandardOutPath + ${BOT_DIR}/bot.log + StandardErrorPath + ${BOT_DIR}/bot.err + + +EOF + +launchctl load "$PLIST_PATH" +echo "✅ Installed and started: ${PLIST_NAME}" +echo " Logs: ${BOT_DIR}/bot.log" +echo " Stop: launchctl unload ${PLIST_PATH}" diff --git a/telegram-bot/uninstall.sh b/telegram-bot/uninstall.sh new file mode 100755 index 0000000..a3a23a9 --- /dev/null +++ b/telegram-bot/uninstall.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# Remove telegram bot launchd service +PLIST_PATH="$HOME/Library/LaunchAgents/com.cr.telegram-bot.plist" +launchctl unload "$PLIST_PATH" 2>/dev/null && echo "✅ Stopped and unloaded" || echo "⚠️ Not loaded" +rm -f "$PLIST_PATH" && echo "✅ Removed plist" || true