#!/bin/bash # Dependencies module for Transmission RSS Manager Installation function install_dependencies() { log "INFO" "Installing dependencies..." # Check for package manager if command -v apt-get &> /dev/null; then # Update package index apt-get update # Install Node.js and npm if not already installed if ! command_exists node; then log "INFO" "Installing Node.js and npm..." apt-get install -y ca-certificates curl gnupg mkdir -p /etc/apt/keyrings # Check if download succeeds if ! curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg; then log "ERROR" "Failed to download Node.js GPG key" exit 1 fi echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" > /etc/apt/sources.list.d/nodesource.list # Update again after adding repo apt-get update # Install nodejs if ! apt-get install -y nodejs; then log "ERROR" "Failed to install Node.js" exit 1 fi else log "INFO" "Node.js is already installed." fi # Check if we need to install Transmission (only if local transmission was selected and not remote) if [ "$TRANSMISSION_REMOTE" = false ] && ([ "$TRANSMISSION_HOST" = "localhost" ] || [ "$TRANSMISSION_HOST" = "127.0.0.1" ]); then if ! command_exists transmission-daemon; then log "INFO" "Local Transmission installation selected, but transmission-daemon is not installed." read -p "Would you like to install Transmission now? (y/n): " install_transmission if [[ "$install_transmission" =~ ^[Yy]$ ]]; then log "INFO" "Installing Transmission..." if ! apt-get install -y transmission-daemon; then log "ERROR" "Failed to install Transmission" log "WARN" "You will need to install Transmission manually before using this application." else # Stop transmission-daemon to allow configuration changes systemctl stop transmission-daemon # Set default settings TRANSMISSION_SETTINGS_DIR="/var/lib/transmission-daemon/info" if [ -f "$TRANSMISSION_SETTINGS_DIR/settings.json" ]; then # Backup original settings cp "$TRANSMISSION_SETTINGS_DIR/settings.json" "$TRANSMISSION_SETTINGS_DIR/settings.json.bak" # Update RPC settings to allow our app to connect sed -i 's/"rpc-authentication-required": true,/"rpc-authentication-required": false,/g' "$TRANSMISSION_SETTINGS_DIR/settings.json" sed -i 's/"rpc-whitelist-enabled": true,/"rpc-whitelist-enabled": false,/g' "$TRANSMISSION_SETTINGS_DIR/settings.json" log "INFO" "Transmission has been configured for local access." else log "WARN" "Could not find Transmission settings file. You may need to configure Transmission manually." fi # Start transmission-daemon systemctl start transmission-daemon log "INFO" "Transmission has been installed and started." fi else log "WARN" "Transmission installation skipped. You will need to install it manually." fi else log "INFO" "Transmission is already installed." fi fi # Install additional dependencies log "INFO" "Installing additional dependencies..." # Try to install unrar-free if unrar is not available if ! apt-get install -y unrar 2>/dev/null; then log "INFO" "unrar not available, trying unrar-free instead..." apt-get install -y unrar-free fi # Install other dependencies apt-get install -y unzip p7zip-full # Try to install nginx apt-get install -y nginx || log "WARN" "Nginx installation failed, web interface may not be accessible" else log "ERROR" "This installer requires apt-get package manager" log "INFO" "Please install the following dependencies manually:" log "INFO" "- Node.js (v18.x)" log "INFO" "- npm" log "INFO" "- unrar" log "INFO" "- unzip" log "INFO" "- p7zip-full" log "INFO" "- nginx" if [ "$TRANSMISSION_HOST" = "localhost" ] || [ "$TRANSMISSION_HOST" = "127.0.0.1" ]; then log "INFO" "- transmission-daemon" fi exit 1 fi # Check if all dependencies were installed successfully local dependencies=("node" "npm" "unzip" "nginx") local missing_deps=() # Add transmission to dependencies check if local installation was selected and not remote if [ "$TRANSMISSION_REMOTE" = false ] && ([ "$TRANSMISSION_HOST" = "localhost" ] || [ "$TRANSMISSION_HOST" = "127.0.0.1" ]); then dependencies+=("transmission-daemon") fi for dep in "${dependencies[@]}"; do if ! command_exists "$dep"; then missing_deps+=("$dep") fi done # Check for either unrar or unrar-free if ! command_exists "unrar" && ! command_exists "unrar-free"; then missing_deps+=("unrar") fi # Check for either 7z or 7za (from p7zip-full) if ! command_exists "7z" && ! command_exists "7za"; then missing_deps+=("p7zip") fi if [ ${#missing_deps[@]} -eq 0 ]; then log "INFO" "All dependencies installed successfully." else log "ERROR" "Failed to install some dependencies: ${missing_deps[*]}" log "WARN" "Please install them manually and rerun this script." # More helpful information based on which deps are missing if [[ " ${missing_deps[*]} " =~ " node " ]]; then log "INFO" "To install Node.js manually, visit: https://nodejs.org/en/download/" fi if [[ " ${missing_deps[*]} " =~ " nginx " ]]; then log "INFO" "To install nginx manually: sudo apt-get install nginx" fi if [[ " ${missing_deps[*]} " =~ " transmission-daemon " ]]; then log "INFO" "To install Transmission manually: sudo apt-get install transmission-daemon" log "INFO" "After installation, you may need to configure it by editing /var/lib/transmission-daemon/info/settings.json" fi exit 1 fi } function create_directories() { log "INFO" "Creating installation directories..." # Check if INSTALL_DIR is defined if [ -z "$INSTALL_DIR" ]; then log "ERROR" "INSTALL_DIR is not defined" exit 1 fi # Check if CONFIG_DIR is defined if [ -z "$CONFIG_DIR" ]; then log "ERROR" "CONFIG_DIR is not defined" exit 1 fi # Create directories and check for errors DIRECTORIES=( "$INSTALL_DIR" "$INSTALL_DIR/logs" "$INSTALL_DIR/public/js" "$INSTALL_DIR/public/css" "$INSTALL_DIR/modules" "$INSTALL_DIR/data" "$CONFIG_DIR" ) for dir in "${DIRECTORIES[@]}"; do if ! mkdir -p "$dir"; then log "ERROR" "Failed to create directory: $dir" exit 1 fi done # Set permissions for configuration directory chown -R "$USER:$USER" "$CONFIG_DIR" chmod 755 "$CONFIG_DIR" log "INFO" "Directories created successfully." }