From 260a282eec90878ea2fbef42f29320872d5f4612 Mon Sep 17 00:00:00 2001 From: smj01095381 Date: Fri, 14 Jun 2024 09:59:41 +0800 Subject: [PATCH] Support for building rpm and source code installations on ALinux OS. --- ancert.spec | 30 ++++++++++++++++++------------ build_rpm.sh | 2 ++ install.sh | 20 +++++++++----------- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/ancert.spec b/ancert.spec index 3ad52ad..ae15e2a 100644 --- a/ancert.spec +++ b/ancert.spec @@ -1,9 +1,7 @@ %define anolis_release 1 -%define __lib lib %define __python %(which python3 2>/dev/null) -%define _nonzero_exit_pkgcheck_terminate_build 1 %undefine __brp_mangle_shebangs -%global dist_ver %(rpm -E %{?dist}|awk '{sub(".an","");print}') +%global dist_ver %(rpm -E %{?dist}|awk '{sub(".an|.al","");print}') %global os_id %(cat /etc/os-release|awk -F'"' '/^ID=/{print $(NF-1)}') Name: ancert @@ -23,11 +21,12 @@ Requires: alsa-lib, alsa-utils, virt-what, smartmontools, hdparm Requires: OpenIPMI, ipmitool, freeipmi Requires: iproute, iputils, ethtool, iperf3, sysstat, expect, tree, mdadm %if "%{os_id}" == "anolis" +ExclusiveArch: x86_64 aarch64 loongarch64 %if %{dist_ver} >= 7 %if %{dist_ver} < 23 -Requires: xorg-x11-utils, xorg-x11-server-utils, xorg-x11-apps, memstrack, stress-ng +Requires: xorg-x11-utils, xorg-x11-server-utils, xorg-x11-apps, stress-ng %if %{dist_ver} >= 8 -Requires: python3-pyyaml +Requires: python3-pyyaml, memstrack %else Requires: python36-PyYAML %endif @@ -35,21 +34,28 @@ Requires: python36-PyYAML Requires: xorg-x11-server-Xwayland, x11perf, xdpyinfo, xvinfo, xset, python3-pyyaml, memstrack %endif %else - %{error: getting dist version,it should be greater than 7.x for Anolis OS} + %{lua: error("getting dist version,it should be greater than 7.x for Anolis OS", 0)} %endif %endif -%if "%{os_id}" != "anolis" -%{error: please build rpm in Anolis OS.} +%if "%{os_id}" == "alinux" +ExclusiveArch: x86_64 aarch64 +Requires: xorg-x11-utils, xorg-x11-server-utils, xorg-x11-apps + %if %{dist_ver} == 8 +Requires: python3-pyyaml, memstrack, stress-ng + %endif +%endif + +%if ! ("%{os_id}" == "anolis" || "%{os_id}" == "alinux") +%{lua: error("please build rpm in Anolis/Alinux OS.", 0)} %endif -ExclusiveArch: x86_64 aarch64 loongarch64 %description -This test suite to be used to verify your system or component the compatibility with Anolis OS. +This test suite to be used to verify your system or component the compatibility with Anolis/Alinux OS. %prep %if "nil%{__python}" == "nil" -%{error: Failed to exec which python3} +%{lua: error("Failed to exec it(which python3).", 0)} %endif %setup -qn %{name}-v%{version} @@ -60,7 +66,7 @@ make DESTDIR=%{buildroot}%{_datadir}/%{name} post_install %defattr(-,root,root) %{_datadir}/%{name}/%{name} %{_datadir}/%{name}/etc -%{_datadir}/%{name}/%{__lib} +%{_datadir}/%{name}/lib %{_datadir}/%{name}/tests %{_datadir}/%{name}/utils %{_datadir}/%{name}/README.md diff --git a/build_rpm.sh b/build_rpm.sh index 1273c89..5763f27 100755 --- a/build_rpm.sh +++ b/build_rpm.sh @@ -14,6 +14,8 @@ function build_env() { function build_source_code_pkg() { cd ${BASEDIR} + command -v "rpmspec" &>/dev/null || { echo "-bash: rpmspec: command not found, please exec it(yum install -y rpm-build).";exit 1; } + rpmspec -P ancert.spec 1>/dev/null || { echo "Failed to parse ancert.spec by rpmspec, please check manually!";exit 1; } # Error log retention TAR_NAME=$(rpmspec -P ancert.spec|egrep "Name|Version"|awk '{print $NF}'|xargs|tr " " "-"|awk '{sub("-","-v");print}') rm -rf ${BUILD_PATH}/tmp/${TAR_NAME} mkdir -p ${BUILD_PATH}/tmp/${TAR_NAME} diff --git a/install.sh b/install.sh index 8370770..c7cd841 100644 --- a/install.sh +++ b/install.sh @@ -7,26 +7,24 @@ function get_all_depend_pkgs() { local dist_ver=$(rpm -E %{?dist}|awk '{sub(".an","");print}') cd $BASEDIR - PKGS=$(awk -v RS=" " '!a[$1]++' <<<"`cat ancert.spec|grep -w "Requires:"|awk -F ':' '{print $2}'|awk '/,/gsub(/,/," ")'|xargs echo`") - # Support different Anolis OS version - if test "$dist_ver" -ge 7 && test "$dist_ver" -lt 8;then - PKGS="$(echo $PKGS|sed -e 's/\(python3-pyyaml\|clang\|x11perf\|xdpyinfo\|xvinfo\|xset\|memstrack\)//g')" - elif test "$dist_ver" -ge 8 && test "$dist_ver" -lt 23;then - PKGS="$(echo $PKGS|sed -e 's/\(python36-PyYAML\|x11perf\|xdpyinfo\|xvinfo\|xset\)//g')" - elif test "$dist_ver" -ge 23;then - PKGS="$(echo $PKGS|sed -e 's/\(xorg-x11-utils\|xorg-x11-server-utils\|xorg-x11-apps\|stress-ng\|python36-PyYAML\)//g')" + rpm -qa|grep -E "rpm-build-[0-9]+" || yum install -y rpm-build + command -v "rpmspec" &>/dev/null || { echo "Failed to install rpm-build, please check manually!";exit 1; } + # Support different Anolis/Alinux OS version + if ! rpmspec -q --requires ancert.spec &>/dev/null;then + echo "Failed to parse dependency package by it.(rpmspec -q --requires ancert.spec)";exit 1 fi + PKGS=$(rpmspec -q --requires ancert.spec|grep -v "/bin") echo -e "Get all dependent package information:\n${PKGS}" } function install_all_depend_pkgs() { get_all_depend_pkgs if test -f /etc/os-release;then - if ! cat /etc/os-release|grep PRETTY_NAME|grep -iwq Anolis;then - echo "Error: please install it in Anolis OS system!" && exit 1 + if ! cat /etc/os-release|grep ID= |grep -iEwq "Anolis|Alinux";then + echo "Error: please install it in Anolis/Alinux OS system!" && exit 1 fi else - echo "Error: no such file /etc/os-release, please install it in Anolis OS system!" && exit 1 + echo "Error: no such file /etc/os-release, please install it in Anolis/Alinux OS system!" && exit 1 fi echo -e "\ninstall dependent package information:" for pkg in $PKGS;do -- Gitee