128 lines
3.4 KiB
Bash
128 lines
3.4 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"
|
|
}
|
|
|
|
# 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}"
|
|
cd "${PACKAGES_DIR}" || {
|
|
log_error "Failed to enter packages directory"
|
|
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
|
|
}
|
|
|
|
# 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..."
|
|
pip3 download -r requirements.txt -d "${PYTHON_PACKAGES_DIR}" || {
|
|
log_error "Failed to download Python packages"
|
|
exit 1
|
|
}
|
|
|
|
# Create package list
|
|
log_info "Creating package list..."
|
|
ls *.rpm > offline-deps.txt || {
|
|
log_error "Failed to create package list"
|
|
exit 1
|
|
}
|
|
|
|
# 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}/*.rpm (System packages)"
|
|
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. Run the deployment script" |