Files
ja4sentinel/packaging/test/test-rpm.sh
Jacquin Antoine 86649b1630
Some checks failed
Build RPM Package / Build RPM Package (Rocky Linux) (push) Has been cancelled
Build DEB Package / Build DEB Package (Debian/Ubuntu) (push) Has been cancelled
feat: generate RPM packages for CentOS 7, Rocky Linux 8/9/10
- Update Dockerfile.package to build RPMs for multiple distributions
  using a unified fpm-based approach
- Add RPM maintainer scripts (postinst, prerm, postrm) for proper
  installation and service management
- Update ja4sentinel.spec for CentOS 7+ compatibility
- Add packaging/systemd/config.yml as default configuration
- Update test-rpm.sh to test installation on all 4 target distributions
- Fix CentOS 7 repository configuration (EOL - vault.centos.org)

Generated RPMs:
- el7: CentOS 7 (libpcap >= 1.4.0)
- el8: Rocky Linux 8 (libpcap >= 1.9.0)
- el9: Rocky Linux 9 (libpcap >= 1.9.0)
- el10: AlmaLinux 10 / Rocky Linux 10 (libpcap >= 1.9.0)

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-02-28 17:02:58 +01:00

112 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
# Test RPM package installation on CentOS 7, Rocky Linux 8/9/10
# Note: We don't use set -e here because we want to continue testing even if one fails
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")"
BUILD_DIR="${PROJECT_ROOT}/build/rpm"
echo "=========================================="
echo " Testing RPM Package Installation"
echo "=========================================="
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to test RPM installation on a specific distribution
test_rpm_install() {
local distro=$1
local image=$2
local rpm_dir=$3
echo ""
echo -e "${YELLOW}Testing on ${distro} (${image})...${NC}"
# Check if RPM files exist in the directory
if [ ! -d "${BUILD_DIR}/${rpm_dir}" ] || [ -z "$(ls -A ${BUILD_DIR}/${rpm_dir}/*.rpm 2>/dev/null)" ]; then
echo -e "${RED} Warning: No RPM packages found in ${BUILD_DIR}/${rpm_dir}${NC}"
echo " Skipping ${distro} test..."
return 1
fi
# Determine package manager and install command
# CentOS 7 is EOL, need to configure vault.centos.org
local setup_cmd=""
local install_cmd=""
case "$image" in
centos:7)
setup_cmd="sed -i 's/mirror.centos.org/vault.centos.org/g' /etc/yum.repos.d/*.repo && sed -i 's/^#.*baseurl=http/baseurl=http/g' /etc/yum.repos.d/*.repo && sed -i 's/^mirrorlist=http/#mirrorlist=http/g' /etc/yum.repos.d/*.repo"
install_cmd="${setup_cmd} && yum install -y libpcap && yum install -y /packages/*.rpm"
;;
rockylinux:*|almalinux:*)
install_cmd="dnf install -y libpcap && dnf install -y /packages/*.rpm"
;;
*)
install_cmd="dnf install -y libpcap && dnf install -y /packages/*.rpm"
;;
esac
# Test installation
if docker run --rm \
-v "${BUILD_DIR}/${rpm_dir}:/packages:ro" \
"${image}" \
sh -c "${install_cmd}"; then
echo -e " ${GREEN}${NC} ${distro}: Installation successful"
return 0
else
echo -e " ${RED}${NC} ${distro}: Installation failed"
return 1
fi
}
# Track test results
TESTS_PASSED=0
TESTS_FAILED=0
# Test on CentOS 7
if test_rpm_install "CentOS 7" "centos:7" "el7"; then
((TESTS_PASSED++))
else
((TESTS_FAILED++))
fi
# Test on Rocky Linux 8
if test_rpm_install "Rocky Linux 8" "rockylinux:8" "el8"; then
((TESTS_PASSED++))
else
((TESTS_FAILED++))
fi
# Test on Rocky Linux 9
if test_rpm_install "Rocky Linux 9" "rockylinux:9" "el9"; then
((TESTS_PASSED++))
else
((TESTS_FAILED++))
fi
# Test on AlmaLinux 10 (Rocky Linux 10 compatible)
if test_rpm_install "AlmaLinux 10" "almalinux:10" "el10"; then
((TESTS_PASSED++))
else
((TESTS_FAILED++))
fi
echo ""
echo "=========================================="
echo " Test Summary"
echo "=========================================="
echo -e " Passed: ${GREEN}${TESTS_PASSED}${NC}"
echo -e " Failed: ${RED}${TESTS_FAILED}${NC}"
echo "=========================================="
if [ ${TESTS_FAILED} -gt 0 ]; then
echo -e "${RED}Some tests failed!${NC}"
exit 1
else
echo -e "${GREEN}All RPM package tests passed!${NC}"
exit 0
fi