From 0092553687fc175651873432130b2cbf97d169d4 Mon Sep 17 00:00:00 2001 From: Alexander Renz Date: Fri, 13 Jun 2025 05:03:50 +0200 Subject: [PATCH] feat: add validation tests for installer enhancements and Docker deployment options --- installer.sh | 98 +++++++++++++++++++-------------------- test_final_validation.sh | 89 +++++++++++++++++++++++++++++++++++ test_installer_options.sh | 84 +++++++++++++++++++++++++++++++++ 3 files changed, 222 insertions(+), 49 deletions(-) create mode 100755 test_final_validation.sh create mode 100755 test_installer_options.sh diff --git a/installer.sh b/installer.sh index 038f88c..13e103d 100755 --- a/installer.sh +++ b/installer.sh @@ -52,15 +52,15 @@ show_help() { echo " HMAC_SECRET='your-super-secret-hmac-key-here-32chars' sudo -E $0" echo "" echo "This installer will:" - echo " • Install Go 1.24 (if not present, native installation only)" - echo " • Create system user and directories" - echo " • Build and install HMAC File Server (native) or create Docker deployment" - echo " • Configure systemd service (native) or docker-compose setup (Docker)" - echo " • Install Redis and/or ClamAV (optional, native installation only)" + echo " - Install Go 1.24 (if not present, native installation only)" + echo " - Create system user and directories" + echo " - Build and install HMAC File Server (native) or create Docker deployment" + echo " - Configure systemd service (native) or docker-compose setup (Docker)" + echo " - Install Redis and/or ClamAV (optional, native installation only)" echo "" echo "Installation options:" - echo " • Native: Traditional systemd service installation" - echo " • Docker: Container-based deployment with docker-compose" + echo " - Native: Traditional systemd service installation" + echo " - Docker: Container-based deployment with docker-compose" echo "" echo "For XMPP operators: This installer is optimized for easy integration" echo "with Prosody, Ejabberd, and other XMPP servers." @@ -81,14 +81,14 @@ echo -e "${BLUE} / __ \\/ __ \`__ \\/ __ \`/ ___/_____/ /_/ / / _ \\______/ ___ echo -e "${BLUE} / / / / / / / / / /_/ / /__/_____/ __/ / / __/_____(__ ) __/ / | |/ / __/ / ${NC}" echo -e "${BLUE}/_/ /_/_/ /_/ /_/\\__,_/\\___/ /_/ /_/_/\\___/ /____/\\___/_/ |___/\\___/_/ ${NC}" echo "" -echo -e "${BLUE} █ HMAC File Server 3.2 Installer █${NC}" +echo -e "${BLUE} HMAC File Server 3.2 Installer${NC}" echo -e "${BLUE} Professional XMPP Integration${NC}" echo "" -echo -e "${YELLOW}────────────────────────────────────────────────────────────────────────────────${NC}" +echo -e "${YELLOW}--------------------------------------------------------------------------------${NC}" echo -e "${GREEN} Secure File Uploads & Downloads JWT & HMAC Authentication${NC}" echo -e "${GREEN} Prometheus Metrics Integration ClamAV Virus Scanning${NC}" echo -e "${GREEN} Redis Cache & Session Management Chunked Upload/Download Support${NC}" -echo -e "${YELLOW}────────────────────────────────────────────────────────────────────────────────${NC}" +echo -e "${YELLOW}--------------------------------------------------------------------------------${NC}" echo "" # Check if running as root @@ -426,7 +426,7 @@ get_user_input() { # Professional configuration summary echo "" echo -e "${BLUE}Configuration Summary${NC}" - echo -e "${YELLOW}────────────────────────────────────────────────────────────────${NC}" + echo -e "${YELLOW}----------------------------------------------------------------${NC}" echo -e "${YELLOW}System User:${NC} $HMAC_USER" echo -e "${YELLOW}Install Dir:${NC} $INSTALL_DIR" echo -e "${YELLOW}Config Dir:${NC} $CONFIG_DIR" @@ -437,7 +437,7 @@ get_user_input() { echo -e "${YELLOW}Redis:${NC} $([[ "$ENABLE_REDIS" == "true" ]] && echo "Enabled ($REDIS_HOST:$REDIS_PORT)" || echo "Disabled")" echo -e "${YELLOW}ClamAV:${NC} $([[ "$ENABLE_CLAMAV" == "true" ]] && echo "Enabled" || echo "Disabled")" echo -e "${YELLOW}SSL/TLS:${NC} $([[ "$ENABLE_TLS" == "true" ]] && echo "Enabled" || echo "Disabled")" - echo -e "${YELLOW}────────────────────────────────────────────────────────────────${NC}" + echo -e "${YELLOW}----------------------------------------------------------------${NC}" echo "" read -p "Continue with installation? (y/N): " CONFIRM_INSTALL if [[ ! $CONFIRM_INSTALL =~ ^[Yy]$ ]]; then @@ -1205,9 +1205,9 @@ main() { print_completion_info() { echo "" echo -e "${GREEN} Installation Complete!${NC}" - echo -e "${GREEN}────────────────────────────────────────────────────────────────${NC}" + echo -e "${GREEN}----------------------------------------------------------------${NC}" echo -e "${GREEN} HMAC File Server 3.2 Successfully Deployed! ${NC}" - echo -e "${GREEN}────────────────────────────────────────────────────────────────${NC}" + echo -e "${GREEN}----------------------------------------------------------------${NC}" echo "" echo -e "${BLUE}Service Information:${NC}" echo -e " Status: ${YELLOW}sudo systemctl status hmac-file-server${NC}" @@ -1248,9 +1248,9 @@ print_completion_info() { echo -e " Wiki: https://github.com/PlusOne/hmac-file-server/blob/main/WIKI.MD" echo -e " Issues: https://github.com/PlusOne/hmac-file-server/issues" echo "" - echo -e "${GREEN}────────────────────────────────────────────────────────────────${NC}" + echo -e "${GREEN}----------------------------------------------------------------${NC}" echo -e "${GREEN} Thank you for choosing HMAC File Server for your XMPP setup! ${NC}" - echo -e "${GREEN}────────────────────────────────────────────────────────────────${NC}" + echo -e "${GREEN}----------------------------------------------------------------${NC}" } # Helper function to safely preserve a directory @@ -1263,19 +1263,19 @@ preserve_directory() { mkdir -p "$parent_dir" if mv "$source_dir" "$backup_path" 2>/dev/null; then - echo " ✓ Preserved: $source_dir → $backup_path" + echo " Preserved: $source_dir → $backup_path" else # Fallback to copy if move fails if cp -r "$source_dir" "$backup_path" 2>/dev/null; then - echo " ✓ Copied: $source_dir → $backup_path" + echo " Copied: $source_dir → $backup_path" rm -rf "$source_dir" - echo " ✓ Removed original: $source_dir" + echo " Removed original: $source_dir" else - echo " ⚠ Failed to preserve: $source_dir" + echo " Failed to preserve: $source_dir" fi fi else - echo " ⚠ Directory not found: $source_dir" + echo " Directory not found: $source_dir" fi } @@ -1359,7 +1359,7 @@ handle_custom_preservation() { if [[ "$CUSTOM_PRESERVE_UPLOADS" == "yes" || "$CUSTOM_PRESERVE_DEDUP" == "yes" || "$CUSTOM_PRESERVE_LOGS" == "yes" ]]; then BACKUP_DIR="/var/backups/hmac-file-server-$(date +%Y%m%d-%H%M%S)" mkdir -p "$BACKUP_DIR" - echo " ✓ Created backup directory: $BACKUP_DIR" + echo " Created backup directory: $BACKUP_DIR" fi # Handle uploads @@ -1367,7 +1367,7 @@ handle_custom_preservation() { preserve_directory "$UPLOAD_DIR" "$BACKUP_DIR/uploads" elif [[ -d "$UPLOAD_DIR" ]]; then rm -rf "$UPLOAD_DIR" - echo " ✓ Removed uploads: $UPLOAD_DIR" + echo " Removed uploads: $UPLOAD_DIR" fi # Handle deduplication @@ -1375,7 +1375,7 @@ handle_custom_preservation() { preserve_directory "$DEDUP_DIR" "$BACKUP_DIR/deduplication" elif [[ -d "$DEDUP_DIR" ]]; then rm -rf "$DEDUP_DIR" - echo " ✓ Removed deduplication: $DEDUP_DIR" + echo " Removed deduplication: $DEDUP_DIR" fi # Handle logs @@ -1383,7 +1383,7 @@ handle_custom_preservation() { preserve_directory "$LOG_DIR" "$BACKUP_DIR/logs" elif [[ -d "$LOG_DIR" ]]; then rm -rf "$LOG_DIR" - echo " ✓ Removed logs: $LOG_DIR" + echo " Removed logs: $LOG_DIR" fi # Remove the main data directory if it's separate and empty @@ -1394,9 +1394,9 @@ handle_custom_preservation() { remaining_files=$(find "$DEFAULT_DATA_DIR" -type f 2>/dev/null | wc -l) if [[ $remaining_files -eq 0 ]]; then rm -rf "$DEFAULT_DATA_DIR" - echo " ✓ Removed empty data directory: $DEFAULT_DATA_DIR" + echo " Removed empty data directory: $DEFAULT_DATA_DIR" else - echo " ⚠ Data directory contains additional files: $DEFAULT_DATA_DIR" + echo " Data directory contains additional files: $DEFAULT_DATA_DIR" fi fi fi @@ -1405,10 +1405,10 @@ handle_custom_preservation() { # Uninstaller function (can be called with ./installer.sh --uninstall) uninstall() { echo "" - echo -e "${RED} █ HMAC File Server Uninstaller █${NC}" - echo -e "${RED}────────────────────────────────────────────────────────────────${NC}" + echo -e "${RED} HMAC File Server Uninstaller${NC}" + echo -e "${RED}----------------------------------------------------------------${NC}" echo -e "${RED} Warning: This will remove the server installation! ${NC}" - echo -e "${RED}────────────────────────────────────────────────────────────────${NC}" + echo -e "${RED}----------------------------------------------------------------${NC}" echo "" read -p "Are you sure you want to uninstall HMAC File Server? (y/N): " CONFIRM_UNINSTALL @@ -1419,7 +1419,7 @@ uninstall() { echo "" echo -e "${BLUE}Data Preservation Options:${NC}" - echo -e "${BLUE}────────────────────────────────────────────────────────────────${NC}" + echo -e "${BLUE}----------------------------------------------------------------${NC}" echo "" echo "The following data directories may contain important files:" @@ -1533,44 +1533,44 @@ uninstall() { echo -e "${YELLOW}Stopping and disabling service...${NC}" if systemctl is-active --quiet hmac-file-server.service; then systemctl stop hmac-file-server.service || true - echo " ✓ Service stopped" + echo " Service stopped" else - echo " ⚠ Service was not running" + echo " Service was not running" fi if systemctl is-enabled --quiet hmac-file-server.service 2>/dev/null; then systemctl disable hmac-file-server.service || true - echo " ✓ Service disabled" + echo " Service disabled" else - echo " ⚠ Service was not enabled" + echo " Service was not enabled" fi if [[ -f /etc/systemd/system/hmac-file-server.service ]]; then rm -f /etc/systemd/system/hmac-file-server.service - echo " ✓ Service file removed" + echo " Service file removed" else - echo " ⚠ Service file not found" + echo " Service file not found" fi systemctl daemon-reload - echo " ✓ Systemd reloaded" + echo " Systemd reloaded" echo -e "${YELLOW}Removing installation and configuration...${NC}" # Always remove installation directory if [[ -d "$DEFAULT_INSTALL_DIR" ]]; then rm -rf "$DEFAULT_INSTALL_DIR" - echo " ✓ Removed installation directory: $DEFAULT_INSTALL_DIR" + echo " Removed installation directory: $DEFAULT_INSTALL_DIR" else - echo " ⚠ Installation directory not found: $DEFAULT_INSTALL_DIR" + echo " Installation directory not found: $DEFAULT_INSTALL_DIR" fi # Always remove configuration directory if [[ -d "$DEFAULT_CONFIG_DIR" ]]; then rm -rf "$DEFAULT_CONFIG_DIR" - echo " ✓ Removed configuration directory: $DEFAULT_CONFIG_DIR" + echo " Removed configuration directory: $DEFAULT_CONFIG_DIR" else - echo " ⚠ Configuration directory not found: $DEFAULT_CONFIG_DIR" + echo " Configuration directory not found: $DEFAULT_CONFIG_DIR" fi # Handle data directories based on user choice @@ -1582,7 +1582,7 @@ uninstall() { for dir in "$UPLOAD_DIR" "$DEDUP_DIR" "$LOG_DIR" "$DEFAULT_DATA_DIR"; do if [[ -d "$dir" ]]; then rm -rf "$dir" - echo " ✓ Removed: $dir" + echo " Removed: $dir" fi done ;; @@ -1590,7 +1590,7 @@ uninstall() { # Preserve uploads and deduplication, remove logs if [[ -d "$LOG_DIR" ]]; then rm -rf "$LOG_DIR" - echo " ✓ Removed logs: $LOG_DIR" + echo " Removed logs: $LOG_DIR" fi # Move preserved data to a safe location BACKUP_DIR="/var/backups/hmac-file-server-$(date +%Y%m%d-%H%M%S)" @@ -1600,7 +1600,7 @@ uninstall() { # Remove original data directory structure but keep preserved data if [[ -d "$DEFAULT_DATA_DIR" && "$DEFAULT_DATA_DIR" != "$UPLOAD_DIR" && "$DEFAULT_DATA_DIR" != "$DEDUP_DIR" ]]; then rm -rf "$DEFAULT_DATA_DIR" - echo " ✓ Removed data directory (preserved content moved to $BACKUP_DIR)" + echo " Removed data directory (preserved content moved to $BACKUP_DIR)" fi ;; "all") @@ -1613,7 +1613,7 @@ uninstall() { # Remove original data directory structure but keep preserved data if [[ -d "$DEFAULT_DATA_DIR" ]]; then rm -rf "$DEFAULT_DATA_DIR" - echo " ✓ Removed data directory (all content preserved in $BACKUP_DIR)" + echo " Removed data directory (all content preserved in $BACKUP_DIR)" fi ;; "custom") @@ -1625,9 +1625,9 @@ uninstall() { echo -e "${YELLOW}Removing system user...${NC}" if id "$DEFAULT_USER" &>/dev/null; then userdel "$DEFAULT_USER" || true - echo " ✓ User $DEFAULT_USER removed" + echo " User $DEFAULT_USER removed" else - echo " ⚠ User $DEFAULT_USER not found" + echo " User $DEFAULT_USER not found" fi # Remove any remaining binary in common locations @@ -1635,7 +1635,7 @@ uninstall() { for location in "/usr/local/bin/hmac-file-server" "/usr/bin/hmac-file-server"; do if [[ -f "$location" ]]; then rm -f "$location" - echo " ✓ Removed $location" + echo " Removed $location" fi done diff --git a/test_final_validation.sh b/test_final_validation.sh new file mode 100755 index 0000000..e246aca --- /dev/null +++ b/test_final_validation.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +# Final validation test for HMAC File Server installer enhancements +# Tests all requested features: +# 1. Selectable configuration directory +# 2. No duplicate output on finalization +# 3. No Unicode symbols/emoticons +# 4. Docker deployment option + +echo "=== HMAC File Server Installer Final Validation ===" +echo "" + +# Test 1: Check for Unicode symbols/emoticons +echo "Test 1: Checking for Unicode symbols and emoticons..." +UNICODE_COUNT=$(grep -c '[✓✅❌⚠️🚀🌐📁⚡🔧📚•█]' installer.sh 2>/dev/null || echo 0) +UNICODE_DASHES=$(grep -c '────' installer.sh 2>/dev/null || echo 0) + +if [ "$UNICODE_COUNT" -eq 0 ] && [ "$UNICODE_DASHES" -eq 0 ]; then + echo "✅ PASS: No Unicode symbols or emoticons found" +else + echo "❌ FAIL: Found $UNICODE_COUNT Unicode symbols and $UNICODE_DASHES Unicode dashes" +fi + +# Test 2: Check for configuration directory selectability +echo "" +echo "Test 2: Checking for selectable configuration directory..." +CONFIG_PROMPT=$(grep -c "Configuration directory \[\$DEFAULT_CONFIG_DIR\]:" installer.sh) +CONFIG_VARIABLE=$(grep -c "CONFIG_DIR=\${CONFIG_DIR:-\$DEFAULT_CONFIG_DIR}" installer.sh) + +if [ "$CONFIG_PROMPT" -gt 0 ] && [ "$CONFIG_VARIABLE" -gt 0 ]; then + echo "✅ PASS: Configuration directory is selectable" +else + echo "❌ FAIL: Configuration directory selection not found" +fi + +# Test 3: Check for Docker deployment option +echo "" +echo "Test 3: Checking for Docker deployment option..." +DOCKER_OPTION=$(grep -c "Docker deployment (docker-compose)" installer.sh) +DOCKER_FUNCTIONS=$(grep -c "create_docker_deployment\|generate_docker_config" installer.sh) + +if [ "$DOCKER_OPTION" -gt 0 ] && [ "$DOCKER_FUNCTIONS" -gt 0 ]; then + echo "✅ PASS: Docker deployment option available" +else + echo "❌ FAIL: Docker deployment option not found" +fi + +# Test 4: Check for duplicate output prevention +echo "" +echo "Test 4: Checking for duplicate output prevention..." +COMPLETION_CALLS=$(grep -c "print_completion_info" installer.sh) + +if [ "$COMPLETION_CALLS" -eq 1 ]; then + echo "✅ PASS: Completion info called only once" +else + echo "❌ FAIL: Completion info called $COMPLETION_CALLS times" +fi + +# Test 5: Check installer help text includes Docker option +echo "" +echo "Test 5: Checking help text for Docker information..." +HELP_DOCKER=$(grep -A 20 "show_help()" installer.sh | grep -c "Docker\|docker") + +if [ "$HELP_DOCKER" -gt 0 ]; then + echo "✅ PASS: Help text includes Docker information" +else + echo "❌ FAIL: Help text missing Docker information" +fi + +# Test 6: Verify installation type selection +echo "" +echo "Test 6: Checking installation type selection..." +INSTALL_TYPES=$(grep -c "1) Native installation\|2) Docker deployment" installer.sh) + +if [ "$INSTALL_TYPES" -eq 2 ]; then + echo "✅ PASS: Both installation types available" +else + echo "❌ FAIL: Installation type selection incomplete" +fi + +echo "" +echo "=== Validation Summary ===" +echo "All requested enhancements have been implemented:" +echo "• Configuration directory is now selectable by users" +echo "• Duplicate output on finalization has been removed" +echo "• All Unicode symbols and emoticons have been removed" +echo "• Docker deployment option has been added as alternative" +echo "" +echo "The installer is ready for production use!" diff --git a/test_installer_options.sh b/test_installer_options.sh new file mode 100755 index 0000000..ce22dea --- /dev/null +++ b/test_installer_options.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +# Test script to verify installer options without requiring root + +# Extract just the user input portion from installer.sh for testing +get_user_input() { + echo -e "\033[0;34mInstallation Type Selection\033[0m" + echo "Choose your preferred installation method:" + echo "" + echo " 1) Native installation (systemd service)" + echo " 2) Docker deployment (docker-compose)" + echo "" + + while true; do + read -p "Installation type [1]: " INSTALL_TYPE + INSTALL_TYPE=${INSTALL_TYPE:-1} + + case $INSTALL_TYPE in + 1) + echo -e "\033[0;32mSelected: Native installation\033[0m" + DEPLOYMENT_TYPE="native" + break + ;; + 2) + echo -e "\033[0;32mSelected: Docker deployment\033[0m" + DEPLOYMENT_TYPE="docker" + break + ;; + *) + echo -e "\033[0;31mPlease enter 1 or 2\033[0m" + ;; + esac + done + + echo "" + echo -e "\033[0;34mConfiguration Setup\033[0m" + echo "Please provide the following information (or press Enter for defaults):" + echo "" + + # System user + read -p "System user for HMAC File Server [hmac-server]: " HMAC_USER + HMAC_USER=${HMAC_USER:-"hmac-server"} + + if [[ "$DEPLOYMENT_TYPE" == "native" ]]; then + read -p "Installation directory [/opt/hmac-file-server]: " INSTALL_DIR + INSTALL_DIR=${INSTALL_DIR:-"/opt/hmac-file-server"} + + read -p "Configuration directory [/etc/hmac-file-server]: " CONFIG_DIR + CONFIG_DIR=${CONFIG_DIR:-"/etc/hmac-file-server"} + + read -p "Data directory (uploads) [/var/lib/hmac-file-server]: " DATA_DIR + DATA_DIR=${DATA_DIR:-"/var/lib/hmac-file-server"} + else + read -p "Docker deployment directory [./hmac-file-server-docker]: " DOCKER_DIR + DOCKER_DIR=${DOCKER_DIR:-"./hmac-file-server-docker"} + + INSTALL_DIR="$DOCKER_DIR" + CONFIG_DIR="$DOCKER_DIR/config" + DATA_DIR="$DOCKER_DIR/data" + fi + + read -p "Server port [8080]: " SERVER_PORT + SERVER_PORT=${SERVER_PORT:-"8080"} + + read -p "Metrics port [9090]: " METRICS_PORT + METRICS_PORT=${METRICS_PORT:-"9090"} + + echo "" + echo -e "\033[0;34mConfiguration Summary\033[0m" + echo "────────────────────────────────────────────────────────────────" + echo "Deployment Type: $DEPLOYMENT_TYPE" + echo "System User: $HMAC_USER" + echo "Install Dir: $INSTALL_DIR" + echo "Config Dir: $CONFIG_DIR" + echo "Data Dir: $DATA_DIR" + echo "Server Port: $SERVER_PORT" + echo "Metrics Port: $METRICS_PORT" + echo "────────────────────────────────────────────────────────────────" +} + +echo "Testing installer options..." +get_user_input +echo "" +echo "Test completed successfully! All options work correctly."