55bca92691
Core features: - Class 1 T.30 protocol: full send/receive implementation - HDLC: DLE-stuffing, FCS strip, USR5637 bit-reversal handling - T.4 MH encoder/decoder (1728px A4 standard) - Document pipeline: PDF (Ghostscript), PNG, TIFF input - Width clamping: US Letter 1734px → 1728px fax standard - Cover page: CJK rasterization (TW/CN/JP/EN), TIFF + HTML output - OCR verification: Tesseract 5 with eng+chi_tra, CJK space-tolerant - API server (axum): health, send, jobs, cover, retry, cancel - Background worker: auto-poll queue, speed fallback, retry policy - Modem detection, pool management Real-world test results (2026-07-23): - V90 → 25153038: 4 pages, V.17 12000 bps, 2:33 ✅ - USR5637 → 25153038: 4 pages, V.17 12000 bps, 2:26 ✅ - Both faxes confirmed received on remote machine Tested: loopback (100% pixel match), multi-page, all input formats, cover pages, OCR verify, API endpoints, worker processing. 13 unit tests pass, 0 new clippy warnings.
275 lines
6.9 KiB
Bash
Executable File
275 lines
6.9 KiB
Bash
Executable File
#!/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 <<EOF
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
<plist version="1.0">
|
|
<dict>
|
|
<key>Label</key>
|
|
<string>com.telfax.server</string>
|
|
|
|
<key>ProgramArguments</key>
|
|
<array>
|
|
<string>$INSTALL_DIR/bin/telfax</string>
|
|
<string>serve</string>
|
|
<string>--config</string>
|
|
<string>$CONFIG_DIR/config.toml</string>
|
|
</array>
|
|
|
|
<key>RunAtLoad</key>
|
|
<true/>
|
|
|
|
<key>KeepAlive</key>
|
|
<true/>
|
|
|
|
<key>StandardOutPath</key>
|
|
<string>$LOG_DIR/telfax.log</string>
|
|
|
|
<key>StandardErrorPath</key>
|
|
<string>$LOG_DIR/telfax-error.log</string>
|
|
|
|
<key>EnvironmentVariables</key>
|
|
<dict>
|
|
<key>RUST_LOG</key>
|
|
<string>info</string>
|
|
</dict>
|
|
|
|
<key>WorkingDirectory</key>
|
|
<string>$DATA_DIR</string>
|
|
</dict>
|
|
</plist>
|
|
EOF
|
|
chmod 644 /Library/LaunchDaemons/com.telfax.server.plist
|
|
;;
|
|
|
|
Linux)
|
|
# Linux systemd
|
|
cat > /etc/systemd/system/telfax.service <<EOF
|
|
[Unit]
|
|
Description=Telfax Enterprise Fax Server
|
|
After=network.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=root
|
|
WorkingDirectory=$DATA_DIR
|
|
ExecStart=$INSTALL_DIR/bin/telfax serve --config $CONFIG_DIR/config.toml
|
|
Restart=on-failure
|
|
RestartSec=10
|
|
TimeoutStartSec=30
|
|
TimeoutStopSec=30
|
|
|
|
StandardOutput=journal
|
|
StandardError=journal
|
|
SyslogIdentifier=telfax
|
|
|
|
Environment=RUST_LOG=info
|
|
|
|
NoNewPrivileges=true
|
|
ProtectSystem=strict
|
|
ProtectHome=true
|
|
PrivateTmp=true
|
|
|
|
ReadWritePaths=$DATA_DIR $LOG_DIR /dev
|
|
|
|
LimitNOFILE=65536
|
|
LimitNPROC=4096
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
chmod 644 /etc/systemd/system/telfax.service
|
|
systemctl daemon-reload
|
|
;;
|
|
esac
|
|
|
|
# Set permissions
|
|
echo -e "${YELLOW}Setting permissions...${NC}"
|
|
case "$OS" in
|
|
Darwin)
|
|
chown -R root:wheel "$CONFIG_DIR"
|
|
chown -R root:wheel "$DATA_DIR"
|
|
chown -R root:wheel "$LOG_DIR"
|
|
;;
|
|
Linux)
|
|
chown -R root:root "$CONFIG_DIR"
|
|
chown -R root:root "$DATA_DIR"
|
|
chown -R root:root "$LOG_DIR"
|
|
;;
|
|
esac
|
|
|
|
chmod 600 "$CONFIG_DIR/config.toml"
|
|
|
|
# Create environment file
|
|
echo -e "${YELLOW}Creating environment file...${NC}"
|
|
cat > "$CONFIG_DIR/telfax.env" <<EOF
|
|
# Telfax Environment Variables
|
|
# Source this file for quick access: source /etc/telfax/telfax.env
|
|
|
|
export TELFAX_BIN="$INSTALL_DIR/bin/telfax"
|
|
export TELFAX_CONFIG="$CONFIG_DIR/config.toml"
|
|
export TELFAX_DATA="$DATA_DIR"
|
|
export TELFAX_LOG="$LOG_DIR"
|
|
|
|
# Quick commands
|
|
alias telfax='$TELFAX_BIN --config $TELFAX_CONFIG'
|
|
alias telfax-log='tail -f $TELFAX_LOG/telfax.log'
|
|
alias telfax-status='$TELFAX_BIN status'
|
|
EOF
|
|
|
|
echo ""
|
|
echo -e "${GREEN}=== Installation Complete ===${NC}"
|
|
echo ""
|
|
echo "Binary: $INSTALL_DIR/bin/telfax"
|
|
echo "Configuration: $CONFIG_DIR/config.toml"
|
|
echo "Data directory: $DATA_DIR"
|
|
echo "Log directory: $LOG_DIR"
|
|
echo ""
|
|
echo -e "${YELLOW}Next Steps:${NC}"
|
|
echo ""
|
|
echo "1. Edit configuration:"
|
|
echo " nano $CONFIG_DIR/config.toml"
|
|
echo ""
|
|
echo "2. Configure authentication tokens (IMPORTANT!)"
|
|
echo " - Change all default tokens in [auth.tokens]"
|
|
echo " - Configure email settings if needed"
|
|
echo ""
|
|
echo "3. Configure modems:"
|
|
echo " - Set correct device paths in [[modems]]"
|
|
echo " - Adjust class and priority as needed"
|
|
echo ""
|
|
echo "4. Start the service:"
|
|
case "$OS" in
|
|
Darwin)
|
|
echo " sudo launchctl load -w /Library/LaunchDaemons/com.telfax.server.plist"
|
|
echo ""
|
|
echo "5. Check service status:"
|
|
echo " sudo launchctl list | grep telfax"
|
|
;;
|
|
Linux)
|
|
echo " sudo systemctl enable telfax"
|
|
echo " sudo systemctl start telfax"
|
|
echo ""
|
|
echo "5. Check service status:"
|
|
echo " sudo systemctl status telfax"
|
|
;;
|
|
esac
|
|
echo ""
|
|
echo "6. View logs:"
|
|
echo " tail -f $LOG_DIR/telfax.log"
|
|
echo ""
|
|
echo "7. Test API:"
|
|
echo " curl http://localhost:3000/api/v1/status"
|
|
echo ""
|
|
echo "8. Open Web UI:"
|
|
echo " http://localhost:3000"
|
|
echo ""
|
|
echo -e "${GREEN}Deployment successful!${NC}"
|
|
echo ""
|
|
|
|
# Optional: Start service automatically
|
|
read -p "Start Telfax service now? (y/n) " -n 1 -r
|
|
echo
|
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
case "$OS" in
|
|
Darwin)
|
|
launchctl load -w /Library/LaunchDaemons/com.telfax.server.plist
|
|
echo -e "${GREEN}Service started!${NC}"
|
|
;;
|
|
Linux)
|
|
systemctl enable telfax
|
|
systemctl start telfax
|
|
echo -e "${GREEN}Service started!${NC}"
|
|
;;
|
|
esac
|
|
else
|
|
echo -e "${YELLOW}Service not started. Start manually when ready.${NC}"
|
|
fi |