Add install script
Provide automated installation for Linux users to set up venv and systemd services with proper path configuration. Changes: - Add install.sh with dependency checks, venv setup, and systemd configuration - Update README to highlight automated install option
This commit is contained in:
parent
acec14553d
commit
2ecdf33dc4
2 changed files with 116 additions and 0 deletions
|
|
@ -4,6 +4,12 @@ This script forwards new emails from a source IMAP account (e.g., GMX) to a dest
|
|||
|
||||
## Setup
|
||||
|
||||
### Automated Install (Recommended)
|
||||
Run the install script: `./install.sh`
|
||||
|
||||
This will set up the virtual environment, systemd services, and provide post-install instructions.
|
||||
|
||||
### Manual Setup
|
||||
1. Copy `.env.example` to `.env` and fill in your IMAP credentials, Uptime URLs, and settings.
|
||||
|
||||
2. Create virtual environment: `python -m venv venv`
|
||||
|
|
|
|||
110
install.sh
Executable file
110
install.sh
Executable file
|
|
@ -0,0 +1,110 @@
|
|||
#!/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="$HOME/.config/email_forwarder"
|
||||
ENV_FILE="./.env"
|
||||
|
||||
# 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 pip3 &> /dev/null; then
|
||||
echo -e "${RED}Error: pip3 not found. Please install pip.${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/"
|
||||
|
||||
# Copy and configure drop-in
|
||||
mkdir -p "$HOME/.config/systemd/user/email_forwarder.service.d"
|
||||
cp email_forwarder.service.d/override.conf.sample "$HOME/.config/systemd/user/email_forwarder.service.d/override.conf"
|
||||
|
||||
# Replace placeholders
|
||||
sed -i "s|/path/to/your/email_forwarder|$PROJECT_DIR|g" "$HOME/.config/systemd/user/email_forwarder.service.d/override.conf"
|
||||
sed -i "s|./.env|$ENV_FILE|g" "$HOME/.config/systemd/user/email_forwarder.service.d/override.conf"
|
||||
|
||||
# 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 "Env file: $ENV_FILE"
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue