194 lines
5.1 KiB
Bash
194 lines
5.1 KiB
Bash
#!/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"
|
|
}
|
|
|
|
# Print usage
|
|
usage() {
|
|
echo "Usage: $0"
|
|
echo "This script prepares packages"
|
|
}
|
|
|
|
# Parse command line arguments
|
|
if [ $# -gt 0 ]; then
|
|
log_error "This script does not accept any arguments"
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
# Check if running on CentOS
|
|
if [ ! -f /etc/centos-release ]; then
|
|
log_error "This script must be run on CentOS"
|
|
exit 1
|
|
fi
|
|
|
|
# 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 running from the correct directory
|
|
if [ ! -f "${PROJECT_ROOT}/CMakeLists.txt" ] || \
|
|
[ ! -d "${PROJECT_ROOT}/src" ] || \
|
|
[ ! -d "${PROJECT_ROOT}/scripts" ]; then
|
|
log_error "This script must be run from the project root directory (CollisionAvoidance)"
|
|
log_error "Current directory: $(pwd)"
|
|
log_error "Please run: cd /path/to/CollisionAvoidance && ./scripts/prepare_offline_packages.sh"
|
|
exit 1
|
|
fi
|
|
|
|
# Create packages directory
|
|
PACKAGES_DIR="${PROJECT_ROOT}/packages"
|
|
log_info "Creating packages directory: ${PACKAGES_DIR}"
|
|
mkdir -p "${PACKAGES_DIR}"
|
|
|
|
# Install necessary tools
|
|
log_info "Installing required tools..."
|
|
yum install -y yum-utils createrepo || {
|
|
log_error "Failed to install required tools"
|
|
exit 1
|
|
}
|
|
|
|
# Define base packages
|
|
PACKAGES=(
|
|
"cmake3"
|
|
"json-devel"
|
|
"boost-devel"
|
|
"openssl-devel"
|
|
"python3"
|
|
"python3-pip"
|
|
"python3-devel"
|
|
"python3-libs"
|
|
"python3-setuptools"
|
|
"gcc"
|
|
"gcc-c++"
|
|
"make"
|
|
"autoconf"
|
|
"automake"
|
|
"libtool"
|
|
)
|
|
|
|
# Download packages
|
|
log_info "Downloading packages and their dependencies..."
|
|
cd "${PACKAGES_DIR}" || {
|
|
log_error "Failed to enter packages directory"
|
|
exit 1
|
|
}
|
|
|
|
for pkg in "${PACKAGES[@]}"; do
|
|
log_info "Downloading $pkg and its dependencies..."
|
|
yumdownloader --resolve --destdir="${PACKAGES_DIR}" --arch=x86_64 "$pkg" || {
|
|
log_error "Failed to download $pkg"
|
|
exit 1
|
|
}
|
|
done
|
|
|
|
# Create local repository
|
|
log_info "Creating local repository..."
|
|
createrepo "${PACKAGES_DIR}" || {
|
|
log_error "Failed to create local repository"
|
|
exit 1
|
|
}
|
|
|
|
# Create repository configuration file
|
|
cat > "${PACKAGES_DIR}/local.repo" << EOL
|
|
[local]
|
|
name=Local Repository
|
|
baseurl=file://${PACKAGES_DIR}
|
|
enabled=1
|
|
gpgcheck=0
|
|
EOL
|
|
|
|
# Create Python requirements file
|
|
log_info "Creating Python requirements file..."
|
|
cat > requirements.txt << EOL
|
|
flask==2.0.1
|
|
werkzeug==2.0.1
|
|
click==8.0.1
|
|
itsdangerous==2.0.1
|
|
Jinja2==3.0.1
|
|
MarkupSafe==2.0.1
|
|
EOL
|
|
|
|
# Create Python packages directory
|
|
PYTHON_PACKAGES_DIR="${PACKAGES_DIR}/python_packages"
|
|
mkdir -p "${PYTHON_PACKAGES_DIR}"
|
|
|
|
# Download Python packages
|
|
log_info "Downloading Python packages..."
|
|
if ! pip3 download -r requirements.txt -d "${PYTHON_PACKAGES_DIR}"; then
|
|
log_error "Failed to download Python packages"
|
|
exit 1
|
|
fi
|
|
|
|
# Create package list
|
|
log_info "Creating package list..."
|
|
if ! ls *.rpm > offline-deps.txt 2>/dev/null; then
|
|
log_error "No RPM packages found in the directory"
|
|
log_error "Please check the previous error messages"
|
|
exit 1
|
|
fi
|
|
|
|
# Sort package list to handle dependencies
|
|
log_info "Sorting package list for dependency order..."
|
|
if ! grep "boost-.*\.rpm" offline-deps.txt > boost-deps.txt 2>/dev/null; then
|
|
log_warn "No boost packages found"
|
|
fi
|
|
if ! grep -v "boost-.*\.rpm" offline-deps.txt > other-deps.txt 2>/dev/null; then
|
|
log_warn "No non-boost packages found"
|
|
fi
|
|
cat boost-deps.txt other-deps.txt > offline-deps.txt 2>/dev/null
|
|
rm -f boost-deps.txt other-deps.txt
|
|
|
|
# Return to project root directory
|
|
cd "${PROJECT_ROOT}" || {
|
|
log_error "Failed to return to project root directory"
|
|
exit 1
|
|
}
|
|
|
|
# Create archive of the project
|
|
log_info "Creating project archive..."
|
|
ARCHIVE_NAME="${PROJECT_NAME}.tar.gz"
|
|
ARCHIVE_PATH="${PROJECT_ROOT}/../${ARCHIVE_NAME}"
|
|
|
|
tar czf "${ARCHIVE_PATH}" \
|
|
--exclude=".git" \
|
|
--exclude="build" \
|
|
--exclude="*.tar.gz" \
|
|
-C "${PROJECT_ROOT}/.." "${PROJECT_NAME}" || {
|
|
log_error "Failed to create project archive"
|
|
exit 1
|
|
}
|
|
log_info "Successfully created ${ARCHIVE_NAME}"
|
|
|
|
# Print summary
|
|
echo -e "\n${GREEN}Offline package preparation completed!${NC}"
|
|
echo "Created files:"
|
|
echo " - ${PACKAGES_DIR}/offline-deps.txt (System package list)"
|
|
echo " - ${PACKAGES_DIR}/requirements.txt (Python package list)"
|
|
echo " - ${PACKAGES_DIR}/local.repo (Local repository configuration)"
|
|
echo " - ${PACKAGES_DIR}/*.rpm (System packages)"
|
|
echo " - ${PACKAGES_DIR}/repodata/* (Repository metadata)"
|
|
echo " - ${PACKAGES_DIR}/${PYTHON_PACKAGES_DIR}/* (Python packages)"
|
|
echo " - ${ARCHIVE_PATH} (Complete project archive)"
|
|
echo -e "\nNext steps:"
|
|
echo "1. Transfer ${ARCHIVE_NAME} to the target server"
|
|
echo "2. Extract the archive on the target server"
|
|
echo "3. Copy local.repo to /etc/yum.repos.d/ on the target server"
|
|
echo "4. Run the deployment script" |