Enhance installer to detect existing installations and update seamlessly
This commit is contained in:
@@ -30,10 +30,28 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||
|
||||
# Check for installation type
|
||||
IS_UPDATE=false
|
||||
INSTALLATION_DETECTED=false
|
||||
|
||||
# Check for config.json file (primary indicator)
|
||||
if [ -f "${SCRIPT_DIR}/config.json" ]; then
|
||||
INSTALLATION_DETECTED=true
|
||||
fi
|
||||
|
||||
# Check for service file (secondary indicator)
|
||||
if [ -f "/etc/systemd/system/transmission-rss-manager.service" ]; then
|
||||
INSTALLATION_DETECTED=true
|
||||
fi
|
||||
|
||||
# Check for data directory (tertiary indicator)
|
||||
if [ -d "${SCRIPT_DIR}/data" ] && [ "$(ls -A "${SCRIPT_DIR}/data" 2>/dev/null)" ]; then
|
||||
INSTALLATION_DETECTED=true
|
||||
fi
|
||||
|
||||
if [ "$INSTALLATION_DETECTED" = true ]; then
|
||||
IS_UPDATE=true
|
||||
echo -e "${YELLOW}Existing installation detected. Running in update mode.${NC}"
|
||||
echo -e "${GREEN}Your existing configuration will be preserved.${NC}"
|
||||
echo -e "${GREEN}Only application files will be updated.${NC}"
|
||||
else
|
||||
echo -e "${GREEN}Fresh installation. Will create new configuration.${NC}"
|
||||
fi
|
||||
@@ -45,6 +63,7 @@ REQUIRED_MODULES=(
|
||||
"${SCRIPT_DIR}/modules/utils-module.sh"
|
||||
"${SCRIPT_DIR}/modules/dependencies-module.sh"
|
||||
"${SCRIPT_DIR}/modules/service-setup-module.sh"
|
||||
"${SCRIPT_DIR}/modules/file-creator-module.sh"
|
||||
)
|
||||
|
||||
for module in "${REQUIRED_MODULES[@]}"; do
|
||||
@@ -60,6 +79,7 @@ source "${SCRIPT_DIR}/modules/utils-module.sh" # Load utilities first for loggin
|
||||
source "${SCRIPT_DIR}/modules/config-module.sh"
|
||||
source "${SCRIPT_DIR}/modules/dependencies-module.sh"
|
||||
source "${SCRIPT_DIR}/modules/service-setup-module.sh"
|
||||
source "${SCRIPT_DIR}/modules/file-creator-module.sh"
|
||||
|
||||
# Function to handle cleanup on error
|
||||
function cleanup_on_error() {
|
||||
@@ -78,48 +98,80 @@ trap 'cleanup_on_error "$BASH_COMMAND"' ERR
|
||||
# Execute the installation steps in sequence
|
||||
log "INFO" "Starting installation process..."
|
||||
|
||||
# Step 1: Gather configuration from user
|
||||
log "INFO" "Gathering configuration..."
|
||||
gather_configuration || {
|
||||
log "ERROR" "Configuration gathering failed"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Step 2: Install dependencies
|
||||
log "INFO" "Installing dependencies..."
|
||||
install_dependencies || {
|
||||
log "ERROR" "Dependency installation failed"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Step 3: Create installation directories
|
||||
log "INFO" "Creating directories..."
|
||||
create_directories || {
|
||||
log "ERROR" "Directory creation failed"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 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"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Step 5: Create service files and install the service
|
||||
log "INFO" "Setting up service..."
|
||||
setup_service || {
|
||||
log "ERROR" "Service setup failed"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Step 6: Install npm dependencies
|
||||
log "INFO" "Installing npm dependencies..."
|
||||
cd "$SCRIPT_DIR"
|
||||
npm install || {
|
||||
log "ERROR" "NPM installation failed"
|
||||
exit 1
|
||||
}
|
||||
if [ "$IS_UPDATE" = true ]; then
|
||||
log "INFO" "Running in update mode - preserving existing configuration..."
|
||||
|
||||
# When updating, we only need to update core files and dependencies
|
||||
# Configuration should be preserved
|
||||
|
||||
# Step 1: Check dependencies (but don't reconfigure)
|
||||
log "INFO" "Checking dependencies..."
|
||||
install_dependencies || {
|
||||
log "ERROR" "Dependency check failed"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Step the service configuration (will preserve existing settings)
|
||||
log "INFO" "Updating service configuration..."
|
||||
setup_service || {
|
||||
log "ERROR" "Service update failed"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Install npm dependencies
|
||||
log "INFO" "Updating npm dependencies..."
|
||||
cd "$SCRIPT_DIR"
|
||||
npm install || {
|
||||
log "ERROR" "NPM installation failed"
|
||||
exit 1
|
||||
}
|
||||
|
||||
else
|
||||
# This is a fresh installation - run all steps
|
||||
|
||||
# Step 1: Gather configuration from user
|
||||
log "INFO" "Gathering configuration..."
|
||||
gather_configuration || {
|
||||
log "ERROR" "Configuration gathering failed"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Step 2: Install dependencies
|
||||
log "INFO" "Installing dependencies..."
|
||||
install_dependencies || {
|
||||
log "ERROR" "Dependency installation failed"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Step 3: Create installation directories
|
||||
log "INFO" "Creating directories..."
|
||||
create_directories || {
|
||||
log "ERROR" "Directory creation failed"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 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"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Step 5: Create service files and install the service
|
||||
log "INFO" "Setting up service..."
|
||||
setup_service || {
|
||||
log "ERROR" "Service setup failed"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Step 6: Install npm dependencies
|
||||
log "INFO" "Installing npm dependencies..."
|
||||
cd "$SCRIPT_DIR"
|
||||
npm install || {
|
||||
log "ERROR" "NPM installation failed"
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
|
||||
# Step 7: Set up update script
|
||||
log "INFO" "Setting up update script..."
|
||||
@@ -226,7 +278,13 @@ finalize_setup || {
|
||||
# Installation complete
|
||||
echo
|
||||
echo -e "${BOLD}${GREEN}==================================================${NC}"
|
||||
echo -e "${BOLD}${GREEN} Installation Complete! ${NC}"
|
||||
|
||||
if [ "$IS_UPDATE" = true ]; then
|
||||
echo -e "${BOLD}${GREEN} Update Complete! ${NC}"
|
||||
else
|
||||
echo -e "${BOLD}${GREEN} Installation Complete! ${NC}"
|
||||
fi
|
||||
|
||||
echo -e "${BOLD}${GREEN}==================================================${NC}"
|
||||
echo -e "You can access the web interface at: ${BOLD}http://localhost:$PORT${NC} or ${BOLD}http://your-server-ip:$PORT${NC}"
|
||||
echo -e "You may need to configure your firewall to allow access to port $PORT"
|
||||
@@ -237,5 +295,12 @@ 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!"
|
||||
|
||||
if [ "$IS_UPDATE" = true ]; then
|
||||
echo -e "Thank you for updating Transmission RSS Manager!"
|
||||
echo -e "The service has been restarted with the new version."
|
||||
else
|
||||
echo -e "Thank you for installing Transmission RSS Manager!"
|
||||
fi
|
||||
|
||||
echo -e "${BOLD}==================================================${NC}"
|
||||
Reference in New Issue
Block a user