#!/bin/bash # Telfax Enterprise Fax Server Installation Script for macOS # # Usage: sudo ./install-macos.sh set -e INSTALL_DIR="/usr/local" BIN_DIR="$INSTALL_DIR/bin" CONFIG_DIR="$INSTALL_DIR/etc/telfax" DATA_DIR="$INSTALL_DIR/var/lib/telfax" LOG_DIR="$INSTALL_DIR/var/log/telfax" PLIST_NAME="com.telfax.server.plist" PLIST_DEST="/Library/LaunchDaemons/$PLIST_NAME" echo "=== Telfax Enterprise Fax Server Installation (macOS) ===" echo "" # Check if running as root if [ "$EUID" -ne 0 ]; then echo "Error: Please run as root (sudo ./install-macos.sh)" exit 1 fi # Create directories echo "Creating directories..." mkdir -p "$BIN_DIR" mkdir -p "$CONFIG_DIR" mkdir -p "$DATA_DIR" mkdir -p "$LOG_DIR" # Build the binary if needed SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" PROJECT_DIR="$(dirname "$SCRIPT_DIR")" if [ ! -f "$PROJECT_DIR/target/release/telfax" ]; then echo "Building telfax (release mode)..." cd "$PROJECT_DIR" cargo build --release fi # Install binary echo "Installing binary..." cp "$PROJECT_DIR/target/release/telfax" "$BIN_DIR/" chmod +x "$BIN_DIR/telfax" # Install configuration if [ ! -f "$CONFIG_DIR/config.toml" ]; then echo "Installing production configuration..." cp "$PROJECT_DIR/deployment/config.production.toml" "$CONFIG_DIR/config.toml" echo "" echo "⚠️ IMPORTANT: Edit $CONFIG_DIR/config.toml" echo " - Change all authentication tokens" echo " - Verify modem device paths" echo " - Set your station_id and header" echo "" else echo "Configuration file already exists, skipping..." fi # Install launchd plist echo "Installing launchd service..." cp "$PROJECT_DIR/deployment/$PLIST_NAME" "$PLIST_DEST" chmod 644 "$PLIST_DEST" # Set permissions echo "Setting permissions..." chown -R root:wheel "$CONFIG_DIR" chown -R root:wheel "$DATA_DIR" chown -R root:wheel "$LOG_DIR" chmod 600 "$CONFIG_DIR/config.toml" echo "" echo "=== Installation Complete ===" echo "" echo "Binary: $BIN_DIR/telfax" echo "Configuration: $CONFIG_DIR/config.toml" echo "Data directory: $DATA_DIR" echo "Log directory: $LOG_DIR" echo "Service plist: $PLIST_DEST" echo "" echo "Next steps:" echo " 1. Edit $CONFIG_DIR/config.toml and configure:" echo " - Authentication tokens (IMPORTANT!)" echo " - Modem device paths" echo " - Station ID and header" echo "" echo " 2. Load and start the service:" echo " sudo launchctl load -w $PLIST_DEST" echo "" echo " 3. Check service status:" echo " sudo launchctl list | grep telfax" echo "" echo " 4. View logs:" echo " tail -f $LOG_DIR/telfax.log" echo " tail -f $LOG_DIR/telfax-error.log" echo "" echo " 5. Test API:" echo " curl -H 'Authorization: Bearer YOUR_TOKEN' http://localhost:3000/api/v1/status" echo "" echo "To stop the service:" echo " sudo launchctl unload $PLIST_DEST" echo ""