From 02e6dac4d64819a9c33f2240cf30b08b5b7d42ab Mon Sep 17 00:00:00 2001 From: Tian jianyong <11429339@qq.com> Date: Thu, 19 Dec 2024 18:09:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E7=A6=BB=E7=BA=BF?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E8=84=9A=E6=9C=AC=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E9=83=A8=E7=BD=B2=E9=AA=8C=E8=AF=81=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/prepare_offline_packages.sh | 68 ++++++++++++++++++----- scripts/verify_offline_packages.sh | 84 +++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+), 13 deletions(-) create mode 100644 scripts/verify_offline_packages.sh diff --git a/scripts/prepare_offline_packages.sh b/scripts/prepare_offline_packages.sh index 56bb5d6..bdd979a 100644 --- a/scripts/prepare_offline_packages.sh +++ b/scripts/prepare_offline_packages.sh @@ -49,21 +49,55 @@ cd "${PACKAGES_DIR}" || { exit 1 } -# Download system dependencies -log_info "Downloading system packages..." -yum install --downloadonly --downloaddir=. \ - cmake3 \ - git \ - nlohmann-json-devel \ - boost-devel \ - openssl-devel \ - python3 \ - python3-pip \ - "Development Tools" || { - log_error "Failed to download system packages" - exit 1 +# Function to get package dependencies +get_dependencies() { + local pkg=$1 + yum deplist "$pkg" | grep provider: | awk '{print $2}' | sort -u } +# Download system dependencies +log_info "Downloading system packages and their dependencies..." + +# Define base packages +PACKAGES=( + "cmake3" + "nlohmann-json-devel" + "boost-devel" + "openssl-devel" + "python3" + "python3-pip" + "@Development Tools" +) + +# Create a temporary file for all packages including dependencies +TEMP_PKGS=$(mktemp) + +# Get all dependencies +for pkg in "${PACKAGES[@]}"; do + log_info "Checking dependencies for $pkg..." + if [[ "$pkg" == @* ]]; then + # Handle package groups + yum groupinfo "${pkg#@}" | grep "Mandatory Packages:" -A 100 | grep "^[[:space:]]*[^[:space:]]*" >> "$TEMP_PKGS" + else + echo "$pkg" >> "$TEMP_PKGS" + get_dependencies "$pkg" >> "$TEMP_PKGS" + fi +done + +# Remove duplicates and sort +sort -u "$TEMP_PKGS" -o "$TEMP_PKGS" + +# Download all packages +log_info "Downloading packages..." +while read -r pkg; do + log_info "Downloading $pkg..." + yum install --downloadonly --downloaddir=. "$pkg" || { + log_warn "Failed to download $pkg, continuing..." + } +done < "$TEMP_PKGS" + +rm "$TEMP_PKGS" + # Create Python requirements file log_info "Creating Python requirements file..." cat > requirements.txt << EOL @@ -93,6 +127,14 @@ ls *.rpm > offline-deps.txt || { exit 1 } +# Sort package list to handle dependencies +log_info "Sorting package list for dependency order..." +# Move boost packages to the beginning of the list +grep "boost-.*\.rpm" offline-deps.txt > boost-deps.txt +grep -v "boost-.*\.rpm" offline-deps.txt > other-deps.txt +cat boost-deps.txt other-deps.txt > offline-deps.txt +rm boost-deps.txt other-deps.txt + # Return to project root directory cd "${PROJECT_ROOT}" || { log_error "Failed to return to project root directory" diff --git a/scripts/verify_offline_packages.sh b/scripts/verify_offline_packages.sh new file mode 100644 index 0000000..02f8e99 --- /dev/null +++ b/scripts/verify_offline_packages.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +# Color definitions for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +# Logging functions +log_info() { + echo -e "${GREEN}[INFO]${NC} $1" +} + +log_warn() { + echo -e "${YELLOW}[WARN]${NC} $1" +} + +log_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +# Get script directory and project root +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(dirname "${SCRIPT_DIR}")" +PROJECT_NAME="$(basename "${PROJECT_ROOT}")" + +# Check if the archive exists +ARCHIVE_PATH="${PROJECT_ROOT}/../${PROJECT_NAME}.tar.gz" +if [ ! -f "${ARCHIVE_PATH}" ]; then + log_error "Archive file not found: ${ARCHIVE_PATH}" + log_error "Please run prepare_offline_packages.sh first" + exit 1 +fi + +# Create a temporary test directory +TEST_DIR=$(mktemp -d) +log_info "Creating test directory: ${TEST_DIR}" + +# Copy archive to test directory +cp "${ARCHIVE_PATH}" "${TEST_DIR}/" + +# Print verification steps +echo -e "\n${GREEN}Verification Steps:${NC}" +echo "1. Prepare a clean CentOS 7 system (physical machine or VM)" +echo "2. Copy these files to the test system:" +echo " - ${ARCHIVE_PATH}" +echo "" +echo "3. On the test system, run:" +echo " cd /tmp" +echo " tar xzf ${PROJECT_NAME}.tar.gz" +echo " cd ${PROJECT_NAME}" +echo " sudo ./scripts/deploy.sh" +echo "" +echo "4. Verify the installation:" +echo " - Check if all packages are installed:" +echo " rpm -qa | grep -E 'boost|cmake3|python3'" +echo "" +echo " - Check Python packages:" +echo " pip3 list | grep -E 'flask|werkzeug|click|itsdangerous|Jinja2|MarkupSafe'" +echo "" +echo " - Check if service is running:" +echo " systemctl status collision-avoidance" +echo "" +echo " - Check service logs:" +echo " journalctl -u collision-avoidance" +echo "" +echo " - Check ports:" +echo " ss -tunlp | grep -E '8010|8081'" +echo "" +echo "5. Test the service:" +echo " - Open http://localhost:8010 in browser" +echo " - Check if mock server is running on port 8081" +echo "" +echo "If any step fails, please check:" +echo "1. /var/log/messages for system errors" +echo "2. journalctl -u collision-avoidance for service errors" +echo "3. Check if all required ports are available" +echo "4. Verify system requirements (memory, disk space)" +echo "" +log_info "Verification guide has been created" +echo -e "Follow the steps above to verify the installation in a clean environment" + +# Clean up +rm -rf "${TEST_DIR}" \ No newline at end of file