Projects
openEuler:20.03:LTS:SP1
oemaker
_service:tar_scm_kernel_repo:0005-restore-env-a...
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:tar_scm_kernel_repo:0005-restore-env-after-selinux-status-changes.patch of Package oemaker
From d83f8048f054db89c2a00f0d252ae58b8ea6a8bb Mon Sep 17 00:00:00 2001 From: xyn-coder <xiangyuning@huawei.com> Date: Tue, 15 Mar 2022 15:17:52 +0800 Subject: [PATCH] restore env after selinux status changes --- isomaker/env_record.sh | 49 +++++++++++++++++++++++++++++++++++++++++ isomaker/env_restore.sh | 30 +++++++++++++++++++++++++ isomaker/img_repo.sh | 3 +++ isomaker/oemaker.sh | 9 +++++++- 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100755 isomaker/env_record.sh create mode 100755 isomaker/env_restore.sh diff --git a/isomaker/env_record.sh b/isomaker/env_record.sh new file mode 100755 index 0000000..e52495b --- /dev/null +++ b/isomaker/env_record.sh @@ -0,0 +1,49 @@ +:<<! + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved. + * oemaker licensed under the Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR + * PURPOSE. + * See the Mulan PSL v2 for more details. + * Author: + * Create: 2022-03-08 + * Description: provide container buffer functions +! + +#!/bin/bash + +set -e +function env_record() +{ + # 记录环境 + selinux_flag=-1 + se_status=$(getenforce) + if [ "$se_status" == "Enforcing" ]; then + selinux_flag=1 + elif [ "$se_status" == "Permissive" ]; then + selinux_flag=0 + else + echo "Selinux status is $se_status, can't restore" + return 0 + fi + + env_value_name="SELINUX_FLAG" + if [ "$selinux_flag" -ne -1 ]; then + # 先删除(/d)环境变量,再添加环境变量 + sed -i "/${env_value_name}=.*/d" /etc/profile + echo "export ${env_value_name}=${selinux_flag}" >> /etc/profile + fi + + echo "the current env has been recorded. " + echo "If oemaker run failed, run the following cmd restore current env" + echo "sh ${CPATH}/env_restore.sh" +} + + +function env_restore() +{ + sh "${CPATH}"/env_restore.sh +} diff --git a/isomaker/env_restore.sh b/isomaker/env_restore.sh new file mode 100755 index 0000000..15f6311 --- /dev/null +++ b/isomaker/env_restore.sh @@ -0,0 +1,30 @@ +:<<! + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved. + * oemaker licensed under the Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR + * PURPOSE. + * See the Mulan PSL v2 for more details. + * Author: + * Create: 2022-03-08 + * Description: provide container buffer functions +! + +#!/bin/bash + +set -e +function env_restore() +{ + # 使用环境变量执行恢复 + source /etc/profile >> /dev/null + if [ "$SELINUX_FLAG" -eq 0 ] || [ "$SELINUX_FLAG" -eq 1 ]; then + setenforce "${SELINUX_FLAG}" + else + echo "/etc/profile have no value: SELINUX_FLAG" + fi +} + +env_restore diff --git a/isomaker/img_repo.sh b/isomaker/img_repo.sh index a226220..4da74a1 100755 --- a/isomaker/img_repo.sh +++ b/isomaker/img_repo.sh @@ -24,12 +24,15 @@ function create_install_img() else vertmp=${VERSION} fi + + set +e lorax --isfinal -p "${PRODUCT}" -v "${vertmp}" -r "${RELEASE}" -t "${VARIANT}" --sharedir 80-openeuler --rootfs-size=4 --buildarch="$ARCH" $(cat yumrepo.file) --nomacboot --noupgrade "${BUILD}"/iso > lorax.logfile 2>&1 if [ $? != 0 ] ; then cat lorax.logfile exit 1 fi + set -e } function create_repos() diff --git a/isomaker/oemaker.sh b/isomaker/oemaker.sh index 74d923e..cd49f87 100755 --- a/isomaker/oemaker.sh +++ b/isomaker/oemaker.sh @@ -29,6 +29,7 @@ source "${CPATH}"/iso.sh source "${CPATH}"/rpm.sh source "${CPATH}"/img_repo.sh source "${CPATH}"/make_debug.sh +source "${CPATH}"/env_record.sh function mkclean() { @@ -149,8 +150,14 @@ function mk_euleros_main() return 0 } +env_record + mk_euleros_main "$@" -if [ $? -ne 0 ]; then +main_ret="$?" + +env_restore + +if [ "$main_ret" -ne 0 ]; then echo "make iso failed" exit 1 fi -- 2.27.0
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.