#!/bin/bash # Email Forwarder Install Script for Linux # Installs virtual environment, systemd user services, and configures paths. set -e # Exit on error # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Default paths PROJECT_DIR="$(pwd)" STATE_DIR="./state" # Functions check_dependencies() { echo -e "${YELLOW}Checking dependencies...${NC}" if ! command -v python3 &> /dev/null; then echo -e "${RED}Error: python3 not found. Please install Python 3.${NC}" exit 1 fi if ! command -v systemctl &> /dev/null; then echo -e "${RED}Error: systemctl not found. Systemd required.${NC}" exit 1 fi echo -e "${GREEN}Dependencies OK.${NC}" } setup_venv() { echo -e "${YELLOW}Setting up virtual environment...${NC}" if [ ! -d "venv" ]; then python3 -m venv venv echo -e "${GREEN}Virtual environment created.${NC}" else echo -e "${GREEN}Virtual environment already exists.${NC}" fi source venv/bin/activate pip install -e . deactivate echo -e "${GREEN}Dependencies installed.${NC}" } setup_systemd() { echo -e "${YELLOW}Setting up systemd user services...${NC}" # Create systemd dir mkdir -p "$HOME/.config/systemd/user" # Copy service files cp *.service *.timer "$HOME/.config/systemd/user/" # Replace placeholders in service file sed -i "s|\${PROJECT_DIR}|$PROJECT_DIR|g" "$HOME/.config/systemd/user/email_forwarder.service" # Reload systemd systemctl --user daemon-reload echo -e "${GREEN}Systemd services configured.${NC}" } create_state_dir() { echo -e "${YELLOW}Ensuring state directory exists...${NC}" mkdir -p "$STATE_DIR" echo -e "${GREEN}State directory: $STATE_DIR${NC}" } post_install() { echo -e "${GREEN}Installation complete!${NC}" echo "" echo "Next steps:" echo "1. Copy .env.example to .env and fill in your IMAP credentials and URLs." echo "2. Run: systemctl --user enable email_forwarder.timer" echo "3. Run: systemctl --user start email_forwarder.timer" echo "4. Check status: systemctl --user status email_forwarder.timer" echo "" echo "If you encounter issues, check logs with: journalctl --user -u email_forwarder.service" } # Main echo -e "${GREEN}Email Forwarder Install Script${NC}" echo "Project dir: $PROJECT_DIR" echo "State dir: $STATE_DIR" echo "" read -p "Continue with installation? (y/N): " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo "Installation cancelled." exit 0 fi check_dependencies setup_venv create_state_dir setup_systemd post_install