#!/bin/bash # Transmission RSS Manager Installer Script # Main entry point for the installation # Text formatting BOLD='\033[1m' GREEN='\033[0;32m' YELLOW='\033[0;33m' RED='\033[0;31m' NC='\033[0m' # No Color # Print header echo -e "${BOLD}==================================================${NC}" echo -e "${BOLD} Transmission RSS Manager Installer ${NC}" echo -e "${BOLD} Version 1.2.0 - Enhanced Edition ${NC}" echo -e "${BOLD}==================================================${NC}" echo # Check if script is run with sudo if [ "$EUID" -ne 0 ]; then echo -e "${RED}Please run as root (use sudo)${NC}" exit 1 fi # Get current directory SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # Create modules directory if it doesn't exist mkdir -p "${SCRIPT_DIR}/modules" # Check if modules exist, if not, extract them if [ ! -f "${SCRIPT_DIR}/modules/config.sh" ]; then echo -e "${YELLOW}Creating module files...${NC}" # Create config module cat > "${SCRIPT_DIR}/modules/config.sh" << 'EOL' #!/bin/bash # Configuration module for Transmission RSS Manager Installation # Configuration variables with defaults INSTALL_DIR="/opt/transmission-rss-manager" SERVICE_NAME="transmission-rss-manager" USER=$(logname || echo $SUDO_USER) PORT=3000 # Transmission configuration variables TRANSMISSION_REMOTE=false TRANSMISSION_HOST="localhost" TRANSMISSION_PORT=9091 TRANSMISSION_USER="" TRANSMISSION_PASS="" TRANSMISSION_RPC_PATH="/transmission/rpc" TRANSMISSION_DOWNLOAD_DIR="/var/lib/transmission-daemon/downloads" TRANSMISSION_DIR_MAPPING="{}" # Media path defaults MEDIA_DIR="/mnt/media" ENABLE_BOOK_SORTING=true function gather_configuration() { echo -e "${BOLD}Installation Configuration:${NC}" echo -e "Please provide the following configuration parameters:" echo read -p "Installation directory [$INSTALL_DIR]: " input_install_dir INSTALL_DIR=${input_install_dir:-$INSTALL_DIR} read -p "Web interface port [$PORT]: " input_port PORT=${input_port:-$PORT} read -p "Run as user [$USER]: " input_user USER=${input_user:-$USER} echo echo -e "${BOLD}Transmission Configuration:${NC}" echo -e "Configure connection to your Transmission client:" echo read -p "Is Transmission running on a remote server? (y/n) [n]: " input_remote if [[ $input_remote =~ ^[Yy]$ ]]; then TRANSMISSION_REMOTE=true read -p "Remote Transmission host [localhost]: " input_trans_host TRANSMISSION_HOST=${input_trans_host:-$TRANSMISSION_HOST} read -p "Remote Transmission port [9091]: " input_trans_port TRANSMISSION_PORT=${input_trans_port:-$TRANSMISSION_PORT} read -p "Remote Transmission username []: " input_trans_user TRANSMISSION_USER=${input_trans_user:-$TRANSMISSION_USER} read -p "Remote Transmission password []: " input_trans_pass TRANSMISSION_PASS=${input_trans_pass:-$TRANSMISSION_PASS} read -p "Remote Transmission RPC path [/transmission/rpc]: " input_trans_path TRANSMISSION_RPC_PATH=${input_trans_path:-$TRANSMISSION_RPC_PATH} # Configure directory mapping for remote setup echo echo -e "${YELLOW}Directory Mapping Configuration${NC}" echo -e "When using a remote Transmission server, you need to map paths between servers." echo -e "For each directory on the remote server, specify the corresponding local directory." echo # Get remote download directory read -p "Remote Transmission download directory: " REMOTE_DOWNLOAD_DIR REMOTE_DOWNLOAD_DIR=${REMOTE_DOWNLOAD_DIR:-"/var/lib/transmission-daemon/downloads"} # Get local directory that corresponds to remote download directory read -p "Local directory that corresponds to the remote download directory: " LOCAL_DOWNLOAD_DIR LOCAL_DOWNLOAD_DIR=${LOCAL_DOWNLOAD_DIR:-"/mnt/transmission-downloads"} # Create mapping JSON TRANSMISSION_DIR_MAPPING=$(cat < "${SCRIPT_DIR}/modules/utils.sh" << 'EOL' #!/bin/bash # Utilities module for Transmission RSS Manager Installation # Function to log a message with timestamp function log() { local level=$1 local message=$2 local timestamp=$(date '+%Y-%m-%d %H:%M:%S') case $level in "INFO") echo -e "${timestamp} ${GREEN}[INFO]${NC} $message" ;; "WARN") echo -e "${timestamp} ${YELLOW}[WARN]${NC} $message" ;; "ERROR") echo -e "${timestamp} ${RED}[ERROR]${NC} $message" ;; *) echo -e "${timestamp} [LOG] $message" ;; esac } # Function to check if a command exists function command_exists() { command -v "$1" &> /dev/null } # Function to backup a file before modifying it function backup_file() { local file=$1 if [ -f "$file" ]; then local backup="${file}.bak.$(date +%Y%m%d%H%M%S)" cp "$file" "$backup" log "INFO" "Created backup of $file at $backup" fi } # Function to create a directory if it doesn't exist function create_dir_if_not_exists() { local dir=$1 local owner=$2 if [ ! -d "$dir" ]; then mkdir -p "$dir" log "INFO" "Created directory: $dir" if [ -n "$owner" ]; then chown -R "$owner" "$dir" log "INFO" "Set ownership of $dir to $owner" fi fi } # Function to finalize the setup (permissions, etc.) function finalize_setup() { log "INFO" "Setting up final permissions and configurations..." # Set proper ownership for the installation directory chown -R $USER:$USER $INSTALL_DIR # Create media directories with correct permissions create_dir_if_not_exists "$MEDIA_DIR/movies" "$USER:$USER" create_dir_if_not_exists "$MEDIA_DIR/tvshows" "$USER:$USER" create_dir_if_not_exists "$MEDIA_DIR/music" "$USER:$USER" create_dir_if_not_exists "$MEDIA_DIR/software" "$USER:$USER" # Create book/magazine directories if enabled if [ "$ENABLE_BOOK_SORTING" = true ]; then create_dir_if_not_exists "$MEDIA_DIR/books" "$USER:$USER" create_dir_if_not_exists "$MEDIA_DIR/magazines" "$USER:$USER" fi # Install NPM packages log "INFO" "Installing NPM packages..." cd $INSTALL_DIR && npm install # Start the service log "INFO" "Starting the service..." systemctl daemon-reload systemctl enable $SERVICE_NAME systemctl start $SERVICE_NAME # Check if service started successfully sleep 2 if systemctl is-active --quiet $SERVICE_NAME; then log "INFO" "Service started successfully!" else log "ERROR" "Service failed to start. Check logs with: journalctl -u $SERVICE_NAME" fi # Create default configuration if it doesn't exist if [ ! -f "$INSTALL_DIR/config.json" ]; then log "INFO" "Creating default configuration file..." cat > $INSTALL_DIR/config.json << EOF { "transmissionConfig": { "host": "${TRANSMISSION_HOST}", "port": ${TRANSMISSION_PORT}, "username": "${TRANSMISSION_USER}", "password": "${TRANSMISSION_PASS}", "path": "${TRANSMISSION_RPC_PATH}" }, "remoteConfig": { "isRemote": ${TRANSMISSION_REMOTE}, "directoryMapping": ${TRANSMISSION_DIR_MAPPING} }, "destinationPaths": { "movies": "${MEDIA_DIR}/movies", "tvShows": "${MEDIA_DIR}/tvshows", "music": "${MEDIA_DIR}/music", "books": "${MEDIA_DIR}/books", "magazines": "${MEDIA_DIR}/magazines", "software": "${MEDIA_DIR}/software" }, "seedingRequirements": { "minRatio": 1.0, "minTimeMinutes": 60, "checkIntervalSeconds": 300 }, "processingOptions": { "enableBookSorting": ${ENABLE_BOOK_SORTING}, "extractArchives": true, "deleteArchives": true, "createCategoryFolders": true, "ignoreSample": true, "ignoreExtras": true, "renameFiles": true, "autoReplaceUpgrades": true, "removeDuplicates": true, "keepOnlyBestVersion": true }, "rssFeeds": [], "rssUpdateIntervalMinutes": 60, "autoProcessing": false } EOF chown $USER:$USER $INSTALL_DIR/config.json fi log "INFO" "Setup finalized!" }