From 28c3291d771087e49773d115b590649672e878b0 Mon Sep 17 00:00:00 2001 From: Tian jianyong <11429339@qq.com> Date: Fri, 20 Dec 2024 18:52:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=83=A8=E7=BD=B2=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/deploy.sh | 52 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index d5516c6..e2c2840 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -1,5 +1,10 @@ #!/bin/bash +# Set up logging +LOGFILE="/tmp/deploy.log" +exec 1> >(tee -a "$LOGFILE") +exec 2> >(tee -a "$LOGFILE" >&2) + # Color definitions for output RED='\033[0;31m' GREEN='\033[0;32m' @@ -48,10 +53,37 @@ rpm -Uvh --nodeps python3*.rpm WORK_DIR="/opt/collision_avoidance" log_info "Creating work directory: $WORK_DIR" mkdir -p $WORK_DIR +mkdir -p $WORK_DIR/bin +mkdir -p $WORK_DIR/lib mkdir -p $WORK_DIR/tools +mkdir -p $WORK_DIR/config # Copy files log_info "Copying files..." + +# Check SELinux status +log_info "Checking SELinux status..." +if command -v getenforce &> /dev/null; then + selinux_status=$(getenforce) + log_info "SELinux status: $selinux_status" + if [ "$selinux_status" = "Enforcing" ]; then + log_info "Setting SELinux contexts..." + + # 设置应用目录的 SELinux 上下文 + log_info "Setting context for application directories..." + chcon -R -t usr_t $WORK_DIR + chcon -t bin_t $WORK_DIR/bin + chcon -t lib_t $WORK_DIR/lib + chcon -t etc_t $WORK_DIR/config + + # 恢复默认上下文 + log_info "Restoring default contexts..." + restorecon -Rv $WORK_DIR + fi +else + log_warn "SELinux tools not found" +fi + for dir in bin lib python tools config; do if [ ! -d "${PROJECT_ROOT}/${dir}" ]; then log_error "Directory not found: ${PROJECT_ROOT}/${dir}" @@ -61,14 +93,16 @@ done # Copy executable log_info "Copying executable..." -if ! cp -v "${PROJECT_ROOT}/bin/"* "/usr/local/bin/"; then - log_error "Failed to copy executable" - exit 1 +if [ "$EXECUTABLE_COPIED" != "1" ]; then + if ! cp -v "${PROJECT_ROOT}/bin/"* "$WORK_DIR/bin/"; then + log_error "Failed to copy executable" + exit 1 + fi fi # Copy libraries log_info "Copying libraries..." -if ! cp -v "${PROJECT_ROOT}/lib/"* "/usr/lib64/"; then +if ! cp -v "${PROJECT_ROOT}/lib/"* "$WORK_DIR/lib/"; then log_error "Failed to copy libraries" exit 1 fi @@ -88,7 +122,7 @@ if ! cp -v "${PROJECT_ROOT}/tools/"* "$WORK_DIR/tools/"; then fi # Create config directory -CONFIG_DIR="/etc/collision_avoidance" +CONFIG_DIR="$WORK_DIR/config" log_info "Creating config directory: $CONFIG_DIR" mkdir -p $CONFIG_DIR cp -r "${PROJECT_ROOT}/config/"* "$CONFIG_DIR/" @@ -111,13 +145,13 @@ After=network.target [Service] Type=simple -ExecStart=/usr/local/bin/collision_avoidance -WorkingDirectory=/usr/local/bin +ExecStart=$WORK_DIR/bin/collision_avoidance +WorkingDirectory=$WORK_DIR/bin User=root Restart=always RestartSec=3 -Environment=CONFIG_PATH=/etc/collision_avoidance -Environment=LD_LIBRARY_PATH=/usr/lib64 +Environment=CONFIG_PATH=$WORK_DIR/config +Environment=LD_LIBRARY_PATH=$WORK_DIR/lib [Install] WantedBy=multi-user.target