diff --git a/bootstrap-installer.sh b/bootstrap-installer.sh new file mode 100755 index 0000000..260ea47 --- /dev/null +++ b/bootstrap-installer.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +# Transmission RSS Manager - Bootstrap Installer +# This script downloads the latest version from git and runs the setup + +# Color and formatting +GREEN='\033[0;32m' +RED='\033[0;31m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color +BOLD='\033[1m' + +# Installation directory +INSTALL_DIR="/opt/trans-install" +REPO_URL="https://git.powerdata.dk/masterdraco/transmission-rss-manager.git" + +# Check if running as root +if [ "$EUID" -ne 0 ]; then + echo -e "${RED}This script must be run as root or with sudo privileges.${NC}" + exit 1 +fi + +# Display welcome message +echo -e "${GREEN}${BOLD}Transmission RSS Manager - Bootstrap Installer${NC}" +echo -e "This script will install the latest version from the git repository." +echo + +# Check for git installation +echo -e "${YELLOW}Checking dependencies...${NC}" +if ! command -v git &> /dev/null; then + echo -e "Git not found. Installing git..." + apt-get update + apt-get install -y git +fi + +# Check if installation directory exists +if [ -d "$INSTALL_DIR" ]; then + echo -e "${YELLOW}Installation directory already exists.${NC}" + read -p "Do you want to remove it and perform a fresh install? (y/n): " choice + if [[ "$choice" =~ ^[Yy]$ ]]; then + echo "Removing existing installation..." + rm -rf "$INSTALL_DIR" + else + echo -e "${RED}Installation aborted.${NC}" + exit 1 + fi +fi + +# Create installation directory +echo -e "${YELLOW}Creating installation directory...${NC}" +mkdir -p "$INSTALL_DIR" + +# Clone the repository +echo -e "${YELLOW}Cloning the latest version from git...${NC}" +git clone "$REPO_URL" "$INSTALL_DIR" +if [ $? -ne 0 ]; then + echo -e "${RED}Failed to clone the repository.${NC}" + exit 1 +fi + +# Run the main installer +echo -e "${YELLOW}Running the main installer...${NC}" +cd "$INSTALL_DIR" +chmod +x main-installer.sh +./main-installer.sh + +# Installation complete +echo -e "${GREEN}${BOLD}Bootstrap installation complete!${NC}" +echo -e "Transmission RSS Manager has been installed in $INSTALL_DIR" +echo -e "You can access the web interface at http://localhost:3000" +echo +echo -e "To update in the future, use the update button in the System Status section of the web interface." \ No newline at end of file diff --git a/main-installer.sh b/main-installer.sh index 0f22305..d927c02 100755 --- a/main-installer.sh +++ b/main-installer.sh @@ -1,6 +1,6 @@ #!/bin/bash # Transmission RSS Manager Modular Installer -# Main installer script that coordinates the installation process +# Modified to work with the git-based approach # Set script to exit on error set -e @@ -15,7 +15,7 @@ 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} Version 1.2.0 - Git Edition ${NC}" echo -e "${BOLD}==================================================${NC}" echo @@ -44,14 +44,13 @@ REQUIRED_MODULES=( "${SCRIPT_DIR}/modules/config-module.sh" "${SCRIPT_DIR}/modules/utils-module.sh" "${SCRIPT_DIR}/modules/dependencies-module.sh" - "${SCRIPT_DIR}/modules/file-creator-module.sh" "${SCRIPT_DIR}/modules/service-setup-module.sh" ) for module in "${REQUIRED_MODULES[@]}"; do if [ ! -f "$module" ]; then echo -e "${RED}Error: Required module file not found: $module${NC}" - echo -e "${YELLOW}Please run the install-script.sh first to generate module files.${NC}" + echo -e "${YELLOW}The module files should be included in the git repository.${NC}" exit 1 fi done @@ -60,7 +59,6 @@ done source "${SCRIPT_DIR}/modules/utils-module.sh" # Load utilities first for logging source "${SCRIPT_DIR}/modules/config-module.sh" source "${SCRIPT_DIR}/modules/dependencies-module.sh" -source "${SCRIPT_DIR}/modules/file-creator-module.sh" source "${SCRIPT_DIR}/modules/service-setup-module.sh" # Function to handle cleanup on error @@ -101,7 +99,7 @@ create_directories || { exit 1 } -# Step 4: Create configuration files and scripts +# Step 4: Create configuration files only (no application files since they're from git) log "INFO" "Creating configuration files..." create_config_files || { log "ERROR" "Configuration file creation failed" @@ -115,7 +113,110 @@ setup_service || { exit 1 } -# Step 6: Final setup and permissions +# Step 6: Install npm dependencies +log "INFO" "Installing npm dependencies..." +cd "$SCRIPT_DIR" +npm install || { + log "ERROR" "NPM installation failed" + exit 1 +} + +# Step 7: Set up update script +log "INFO" "Setting up update script..." +mkdir -p "${SCRIPT_DIR}/scripts" +cp "${SCRIPT_DIR}/scripts/update.sh" "${SCRIPT_DIR}/scripts/update.sh" 2>/dev/null || { + # If copy fails, it probably doesn't exist, so we'll create it + cat > "${SCRIPT_DIR}/scripts/update.sh" << 'EOL' +#!/bin/bash + +# Transmission RSS Manager - Update Script +# This script pulls the latest version from git and runs necessary updates + +# Color and formatting +GREEN='\033[0;32m' +RED='\033[0;31m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color +BOLD='\033[1m' + +# Installation directory (should be current directory) +INSTALL_DIR=$(pwd) + +# Check if we're in the right directory +if [ ! -f "$INSTALL_DIR/package.json" ] || [ ! -d "$INSTALL_DIR/modules" ]; then + echo -e "${RED}Error: This script must be run from the installation directory.${NC}" + exit 1 +fi + +# Get the current version +CURRENT_VERSION=$(grep -oP '"version": "\K[^"]+' package.json) +echo -e "${YELLOW}Current version: ${BOLD}$CURRENT_VERSION${NC}" + +# Check for git repository +if [ ! -d ".git" ]; then + echo -e "${RED}Error: This installation was not set up using git.${NC}" + echo -e "Please use the bootstrap installer to perform a fresh installation." + exit 1 +fi + +# Stash any local changes +echo -e "${YELLOW}Backing up any local configuration changes...${NC}" +git stash -q + +# Pull the latest changes +echo -e "${YELLOW}Pulling latest updates from git...${NC}" +git pull +if [ $? -ne 0 ]; then + echo -e "${RED}Failed to pull updates. Restoring original state...${NC}" + git stash pop -q + exit 1 +fi + +# Get the new version +NEW_VERSION=$(grep -oP '"version": "\K[^"]+' package.json) +echo -e "${GREEN}New version: ${BOLD}$NEW_VERSION${NC}" + +# Check if update is needed +if [ "$CURRENT_VERSION" == "$NEW_VERSION" ]; then + echo -e "${GREEN}You already have the latest version.${NC}" + exit 0 +fi + +# Install any new npm dependencies +echo -e "${YELLOW}Installing dependencies...${NC}" +npm install + +# Apply any local configuration changes +if git stash list | grep -q "stash@{0}"; then + echo -e "${YELLOW}Restoring local configuration changes...${NC}" + git stash pop -q + # Handle conflicts if any + if [ $? -ne 0 ]; then + echo -e "${RED}There were conflicts when restoring your configuration.${NC}" + echo -e "Please check the files and resolve conflicts manually." + echo -e "Your original configuration is saved in .git/refs/stash" + fi +fi + +# Restart the service +echo -e "${YELLOW}Restarting service...${NC}" +if command -v systemctl &> /dev/null; then + sudo systemctl restart transmission-rss-manager +else + echo -e "${RED}Could not restart service automatically.${NC}" + echo -e "Please restart the service manually." +fi + +# Update complete +echo -e "${GREEN}${BOLD}Update complete!${NC}" +echo -e "Updated from version $CURRENT_VERSION to $NEW_VERSION" +echo -e "Changes will take effect immediately." +EOL + + chmod +x "${SCRIPT_DIR}/scripts/update.sh" +} + +# Step 8: Final setup and permissions log "INFO" "Finalizing setup..." finalize_setup || { log "ERROR" "Setup finalization failed" @@ -134,6 +235,7 @@ echo -e "${BOLD}Useful Commands:${NC}" echo -e " To check the service status: ${YELLOW}systemctl status $SERVICE_NAME${NC}" echo -e " To view logs: ${YELLOW}journalctl -u $SERVICE_NAME${NC}" echo -e " To restart the service: ${YELLOW}systemctl restart $SERVICE_NAME${NC}" +echo -e " To update the application: ${YELLOW}Use the Update button in the System Status section${NC}" echo echo -e "Thank you for installing Transmission RSS Manager!" -echo -e "${BOLD}==================================================${NC}" +echo -e "${BOLD}==================================================${NC}" \ No newline at end of file diff --git a/modules/config-module.sh b/modules/config-module.sh index 0f07350..55204d7 100644 --- a/modules/config-module.sh +++ b/modules/config-module.sh @@ -88,18 +88,10 @@ function gather_configuration() { fi fi - # Get and validate port - while true; do - read -p "Web interface port [$PORT]: " input_port - if [ -z "$input_port" ]; then - break - elif validate_port "$input_port"; then - PORT="$input_port" - break - else - log "WARN" "Invalid port number. Port must be between 1 and 65535." - fi - done + # Using fixed port 3000 to avoid permission issues with ports below 1024 + log "INFO" "Using port 3000 for the web interface" + log "INFO" "This is to avoid permission issues with ports below 1024 (like port 80)" + PORT=3000 # Get user read -p "Run as user [$USER]: " input_user @@ -233,6 +225,43 @@ function gather_configuration() { # Set Transmission download dir for configuration TRANSMISSION_DOWNLOAD_DIR=$REMOTE_DOWNLOAD_DIR else + # Local Transmission selected + echo -e "${YELLOW}You've selected to use a local Transmission installation.${NC}" + + # Check if Transmission is already installed + if command -v transmission-daemon &> /dev/null; then + echo -e "${GREEN}Transmission is already installed on this system.${NC}" + else + echo -e "${YELLOW}NOTE: Transmission does not appear to be installed on this system.${NC}" + echo -e "${YELLOW}You will be prompted to install it during the dependency installation step.${NC}" + fi + + # Get and validate port + while true; do + read -p "Local Transmission port [9091]: " input_trans_port + if [ -z "$input_trans_port" ]; then + break + elif validate_port "$input_trans_port"; then + TRANSMISSION_PORT="$input_trans_port" + break + else + log "WARN" "Invalid port number. Port must be between 1 and 65535." + fi + done + + # Get credentials if any + read -p "Local Transmission username (leave empty if authentication is disabled) []: " input_trans_user + TRANSMISSION_USER=${input_trans_user:-$TRANSMISSION_USER} + + if [ -n "$input_trans_user" ]; then + # Use read -s for password to hide it + read -s -p "Local Transmission password []: " input_trans_pass + echo # Add a newline after the password input + if [ -n "$input_trans_pass" ]; then + TRANSMISSION_PASS="$input_trans_pass" + fi + fi + read -p "Transmission download directory [/var/lib/transmission-daemon/downloads]: " input_trans_dir if [ -n "$input_trans_dir" ]; then if [[ ! "$input_trans_dir" =~ ^/ ]]; then @@ -342,4 +371,4 @@ function gather_configuration() { log "INFO" "Configuration gathering complete" echo -e "${GREEN}Configuration complete!${NC}" echo -} +} \ No newline at end of file diff --git a/modules/dependencies-module.sh b/modules/dependencies-module.sh index ecec2de..9422336 100644 --- a/modules/dependencies-module.sh +++ b/modules/dependencies-module.sh @@ -35,9 +35,61 @@ function install_dependencies() { log "INFO" "Node.js is already installed." fi + # Check if we need to install Transmission (only if local transmission was selected) + if [ "$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..." - apt-get install -y unrar unzip p7zip-full nginx + # 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:" @@ -47,19 +99,37 @@ function install_dependencies() { 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" "unrar" "unzip" "7z" "nginx") + local dependencies=("node" "npm" "unzip" "nginx") local missing_deps=() + # Add transmission to dependencies check if local installation was selected + if [ "$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 @@ -75,6 +145,11 @@ function install_dependencies() { 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 } @@ -106,4 +181,4 @@ function create_directories() { done log "INFO" "Directories created successfully." -} +} \ No newline at end of file diff --git a/public/index.html b/public/index.html index 8480227..d5f9158 100644 --- a/public/index.html +++ b/public/index.html @@ -105,6 +105,48 @@
Loading system status...