#!/bin/bash # Signal Bot Deployment Script # This script handles setup and runs the Signal bot set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color echo -e "${GREEN}=== Signal Bot Deployment Script ===${NC}" # Check if Python is installed if ! command -v python3 &> /dev/null; then echo -e "${RED}Error: Python3 is not installed. Please install Python 3.8 or higher.${NC}" exit 1 fi # Get script directory SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" # Check and create virtual environment if [ ! -d "venv" ]; then echo -e "${YELLOW}Creating virtual environment...${NC}" python3 -m venv venv fi # Activate virtual environment echo -e "${YELLOW}Activating virtual environment...${NC}" source venv/bin/activate # Install requirements echo -e "${YELLOW}Installing requirements...${NC}" pip install -q -r requirements.txt # Check for .env file if [ ! -f ".env" ]; then if [ -f ".env.sample" ]; then echo -e "${YELLOW}Creating .env file from sample...${NC}" cp .env.sample .env else echo -e "${RED}Warning: No .env file found.${NC}" fi fi # Load environment variables from .env file if it exists if [ -f ".env" ]; then echo -e "${YELLOW}Loading environment variables from .env...${NC}" set -a source .env set +a fi # Display configuration status echo "" echo -e "${GREEN}=== Configuration Status ===${NC}" echo "" # Check required environment variables check_env_var() { local var_name=$1 local var_value="${!var_name}" local description=$2 if [ -z "$var_value" ] || [ "$var_value" == "" ]; then echo -e "${RED}✗ $var_name: Not set${NC} - $description" return 1 else # Mask sensitive values local masked_value="${var_value:0:4}..." echo -e "${GREEN}✓ $var_name: $masked_value${NC}" return 0 fi } config_ok=true check_env_var "PHONE_NUMBER" "Your Signal phone number (e.g., +1234567890)" || config_ok=false check_env_var "GROUP_ID" "Group ID for receiving messages" || config_ok=false check_env_var "GROUP_ID_SEND" "Group ID for sending messages" || config_ok=false check_env_var "CAT_API" "The Cat API key (optional)" || true # Optional echo "" echo -e "${GREEN}=== Mode Configuration ===${NC}" MODE=${MODE:-PRD} if [ "$MODE" == "DBG" ]; then echo -e "${YELLOW}Running in DEBUG mode - Commands will be sent to 'note to self' (your own number)${NC}" else echo -e "${GREEN}Running in PRODUCTION mode${NC}" fi echo "" if [ "$config_ok" = false ]; then echo -e "${YELLOW}=== Manual Configuration Required ===${NC}" echo "" echo "Please configure the following in your .env file or environment:" echo "" echo "1. PHONE_NUMBER - Your Signal phone number linked to the bot" echo " Example: export PHONE_NUMBER=\"+1234567890\"" echo "" echo "2. GROUP_ID - The group ID where the bot receives messages" echo " Find this by looking at received messages in debug mode" echo "" echo "3. GROUP_ID_SEND - The group ID where the bot sends responses" echo " Can be the same as GROUP_ID or different" echo "" echo "4. CAT_API (optional) - API key for The Cat API" echo " Get one at: https://thecatapi.com/#pricing" echo "" echo "5. MODE - Set to DBG for debug mode, PRD for production" echo " In debug mode, commands are sent to your own number" echo "" echo -e "${RED}Exiting due to missing configuration.${NC}" echo "Edit your .env file and run this script again." exit 1 fi # Display Signal CLI REST API setup instructions if not already done echo -e "${GREEN}=== Signal CLI REST API Setup ===${NC}" echo "" echo "Make sure Signal CLI REST API is running. If not, run:" echo "" echo " docker run -d --name signal-api --restart=always -p 9922:8080 \\" echo " -v \$HOME/signal-api:/home/.local/share/signal-cli \\" echo " -e 'MODE=json-rpc' bbernhard/signal-cli-rest-api:0.167-dev" echo "" echo "Then link your Signal account by scanning the QR code at:" echo " http://localhost:9922/v1/qrcodelink?device_name=signal-api" echo "" # Start the application with live reload echo -e "${GREEN}=== Starting Signal Bot ===${NC}" echo "Live reload is enabled - changes to Python files will auto-restart the server" echo "" uvicorn main:app --host 0.0.0.0 --port 8000 --reload