新增离线打包脚本
This commit is contained in:
parent
37e657eaea
commit
c9d0f6cf86
111
scripts/prepare_offline_packages.sh
Normal file
111
scripts/prepare_offline_packages.sh
Normal file
@ -0,0 +1,111 @@
|
||||
#!/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
|
||||
|
||||
# Create packages directory
|
||||
PACKAGES_DIR="packages"
|
||||
log_info "Creating packages directory..."
|
||||
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="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 parent directory
|
||||
cd ..
|
||||
|
||||
# Create archive of the project
|
||||
log_info "Creating project archive..."
|
||||
PROJECT_NAME="collision_avoidance"
|
||||
if [ -d "${PROJECT_NAME}" ]; then
|
||||
tar czf "${PROJECT_NAME}.tar.gz" \
|
||||
"${PROJECT_NAME}" \
|
||||
"${PACKAGES_DIR}" || {
|
||||
log_error "Failed to create project archive"
|
||||
exit 1
|
||||
}
|
||||
log_info "Successfully created ${PROJECT_NAME}.tar.gz"
|
||||
else
|
||||
log_error "Project directory ${PROJECT_NAME} not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 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 " - ${PROJECT_NAME}.tar.gz (Complete project archive)"
|
||||
echo -e "\nNext steps:"
|
||||
echo "1. Transfer ${PROJECT_NAME}.tar.gz to the target server"
|
||||
echo "2. Extract the archive on the target server"
|
||||
echo "3. Run the deployment script"
|
||||
Loading…
Reference in New Issue
Block a user