#!/bin/bash SMTP_SERVICE_NAME="pymta-smtp.service" WEB_SERVICE_NAME="pymta-web.service" APP_ROOT_FOLDER="" #/opt/PyMTA-server # Set APP_ROOT_FOLDER to the directory where this script is located if not already set if [[ -z "$APP_ROOT_FOLDER" ]]; then SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" APP_ROOT_FOLDER="$SCRIPT_DIR" fi SCRIPT_MODE="install" TARGET_USER="$USER" IS_SYSTEM=false # Function to print usage usage() { echo "Usage:" echo " $0 Install as current user" echo " $0 -u username Install as system service for given user (requires sudo)" echo " $0 -rm Remove user service for current user ( also works with 'remove')" echo " $0 -rm username Remove system service for specified user (requires sudo)" echo " $0 -rm system Remove system service" exit 1 } # Parse arguments while [[ $# -gt 0 ]]; do case "$1" in -u) TARGET_USER="$2" IS_SYSTEM=true shift 2 ;; -rm) SCRIPT_MODE="remove" if [[ "$2" ]]; then if [[ "$2" == "system" ]]; then IS_SYSTEM=true TARGET_USER="" else IS_SYSTEM=true TARGET_USER="$2" fi shift fi shift ;; remove) SCRIPT_MODE="remove" shift ;; *) usage ;; esac done write_user_services() { mkdir -p "$HOME/.config/systemd/user" cat > "$HOME/.config/systemd/user/$SMTP_SERVICE_NAME" < "$HOME/.config/systemd/user/$WEB_SERVICE_NAME" < /dev/null < /dev/null <