#!/bin/bash # Telfax Enterprise - Complete Production Deployment Script # # This script deploys Telfax as a production-ready fax server # Supports: macOS (launchd) and Linux (systemd) 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}=== Telfax Enterprise Fax Server Deployment ===${NC}" echo "" # Detect OS OS=$(uname -s) case "$OS" in Darwin) echo "Detected: macOS" INSTALL_DIR="/usr/local" CONFIG_DIR="$INSTALL_DIR/etc/telfax" DATA_DIR="$INSTALL_DIR/var/lib/telfax" LOG_DIR="$INSTALL_DIR/var/log/telfax" ;; Linux) echo "Detected: Linux" INSTALL_DIR="/opt/telfax" CONFIG_DIR="/etc/telfax" DATA_DIR="/var/lib/telfax" LOG_DIR="/var/log/telfax" ;; *) echo -e "${RED}Unsupported OS: $OS${NC}" exit 1 ;; esac # Check for root privileges if [ "$EUID" -ne 0 ]; then echo -e "${RED}Please run as root (sudo ./deploy.sh)${NC}" exit 1 fi # Create directories echo -e "${YELLOW}Creating directories...${NC}" mkdir -p "$INSTALL_DIR/bin" mkdir -p "$CONFIG_DIR" mkdir -p "$DATA_DIR" mkdir -p "$LOG_DIR" # Build binary echo -e "${YELLOW}Building Telfax binary...${NC}" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" PROJECT_DIR="$(dirname "$SCRIPT_DIR")" cd "$PROJECT_DIR" cargo build --release --features server if [ ! -f "target/release/telfax" ]; then echo -e "${RED}Build failed! Binary not found.${NC}" exit 1 fi # Install binary echo -e "${YELLOW}Installing binary...${NC}" cp target/release/telfax "$INSTALL_DIR/bin/" chmod +x "$INSTALL_DIR/bin/telfax" # Install configuration if [ ! -f "$CONFIG_DIR/config.toml" ]; then echo -e "${YELLOW}Installing configuration...${NC}" cp deployment/config.enterprise.toml "$CONFIG_DIR/config.toml" echo -e "${GREEN}Configuration installed to: $CONFIG_DIR/config.toml${NC}" else echo -e "${YELLOW}Configuration already exists, skipping...${NC}" fi # Create database directory echo -e "${YELLOW}Initializing databases...${NC}" mkdir -p "$(dirname "$DATA_DIR/queue.db")" mkdir -p "$(dirname "$DATA_DIR/address_book.db")" # Install service echo -e "${YELLOW}Installing system service...${NC}" case "$OS" in Darwin) # macOS launchd cat > /Library/LaunchDaemons/com.telfax.server.plist < Label com.telfax.server ProgramArguments $INSTALL_DIR/bin/telfax serve --config $CONFIG_DIR/config.toml RunAtLoad KeepAlive StandardOutPath $LOG_DIR/telfax.log StandardErrorPath $LOG_DIR/telfax-error.log EnvironmentVariables RUST_LOG info WorkingDirectory $DATA_DIR EOF chmod 644 /Library/LaunchDaemons/com.telfax.server.plist ;; Linux) # Linux systemd cat > /etc/systemd/system/telfax.service < "$CONFIG_DIR/telfax.env" <