!147 restore env after selinux status changes

From: @xyncoder 
Reviewed-by: @zhuchunyi 
Signed-off-by: @zhuchunyi
This commit is contained in:
openeuler-ci-bot 2022-03-15 12:19:12 +00:00 committed by Gitee
commit a4eb371006
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 165 additions and 1 deletions

View File

@ -0,0 +1,156 @@
From 48c8515627514e7d3556ae315cdb9db009b23f9b Mon Sep 17 00:00:00 2001
From: xyn-coder <xiangyuning@huawei.com>
Date: Tue, 15 Mar 2022 15:21:51 +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 100644 isomaker/env_record.sh
create mode 100644 isomaker/env_restore.sh
diff --git a/isomaker/env_record.sh b/isomaker/env_record.sh
new file mode 100644
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 100644
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 9135b39..5e956c7 100644
--- a/isomaker/img_repo.sh
+++ b/isomaker/img_repo.sh
@@ -35,12 +35,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 c5d85fb..9fa8e08 100644
--- 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()
{
@@ -156,8 +157,14 @@ function mk_oe_main()
return 0
}
+env_record
+
mk_oe_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

View File

@ -11,7 +11,7 @@ Summary: a duilding tool for DVD ISO making and ISO cutting
License: Mulan PSL v2
Group: System/Management
Version: 2.0.3
Release: 3
Release: 4
BuildRoot: %{_tmppath}/%{name}
Source: https://gitee.com/openeuler/oemaker/repository/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
@ -30,6 +30,7 @@ Patch0003: 0003-change-for-edge-computing.patch
Patch0004: 0004-bugfix-I3OGUT.patch
Patch0005: 0005-add-fpi_tail-param-for-grub.patch
Patch0006: 0006-support-usb-flash-drive-mode.patch
Patch0007: 0007-restore-env-after-selinux-status-changes.patch
%description
a building tool for DVD ISO making and ISO cutting
@ -75,6 +76,8 @@ install -m 700 %{name}/isomaker/img_repo.sh %{buildroot}/opt/oemaker/img_repo.sh
install -m 700 %{name}/isomaker/init.sh %{buildroot}/opt/oemaker/init.sh
install -m 700 %{name}/isomaker/iso.sh %{buildroot}/opt/oemaker/iso.sh
install -m 700 %{name}/isomaker/rpm.sh %{buildroot}/opt/oemaker/rpm.sh
install -m 700 %{name}/isomaker/env_record.sh %{buildroot}/opt/oemaker/env_record.sh
install -m 700 %{name}/isomaker/env_restore.sh %{buildroot}/opt/oemaker/env_restore.sh
install -m 400 %{name}/isomaker/config/rpmlist.xml %{buildroot}/opt/oemaker/config/rpmlist.xml
install -m 400 %{name}/isomaker/config/x86_64/* %{buildroot}/opt/oemaker/config/x86_64/
install -m 400 %{name}/isomaker/config/aarch64/* %{buildroot}/opt/oemaker/config/aarch64/
@ -131,6 +134,11 @@ rm -rf %{buildroot}
rm -rf $RPM_BUILD_DIR/%{name}
%changelog
* Tue Mar 15 2022 xiangyuning <xiangyuning@huawei.com> - 2.0.3-4
- ID:NA
- SUG:NA
- DESC: restore env after selinux status changes
* Mon Feb 14 2022 wangchong <952173335@qq.com> - 2.0.3-3
- ID:NA
- SUG:NA