#!/bin/bash #bash -x ./build_package.sh -a aarch64 -w `pud` -i 123abc -v 1,4.0 -r 3 -b /root/packaging_releases/build_root_a3860623d/virtual_rootfs/usr/local/ -l /usr/local -t deb OS=Kylin VERSION= WORK_ROOT= PACKAGE_TYPE=deb BUILD_ID= RELEASE= DISTRO_ID=`cat /etc/*-release | grep ^ID= | awk -F'=' '{print $2}' | sed '/\"//g'` DISTRO _VERSION_ID=`cat /etc/*-release | grep ^VERSION_ID= | awk -F'=' '{print $2}' | sed "s/\"//g'` usage() { echo "Usage:" echo "build_package.sh " } build_rpm_package() { mkdir -p $BUILD ROOT pushd $BUILD ROOT RPMBUILD=$BUILD_ROOT/rpmbuild_$BUILD_ID rpmbuild --bb --target=$ARCH \ -D "_topdir $RPMBUILD" \ -D "_arch $ARCH" \ -D "current_version $VERSION" \ -D "current_release $RELEASE.$DISTRO_ID$DISTRO_VERSION_ID" \ -D "lib $BIN PATH" \ -D "lib_prefix $_LIB_PREFTX" \ $WORK_ROOT/rpm_package/package.spec cp `find ./ -name *.rpm` $WORK_ROOT; popd exit } build_deb_package() { mkdir -p $BUILD_ROOT pushd $BUILD_ROOT PACKAGE_NAME="sietium-umod-drv_"$VERSION"-"$RELEASE"."$DISTRO_ID$DISTRO_VERSION_ID"_"$ARCH DEBBUILD=$BUILD_ROOT/debbuild_$BUILD_ID mkdir -p $DEBBUILD/$_LIB_PREFIX sed-i "s/Version:/Version:$VERSION-$RELEASE/g" $WORK_ROOT/deb_package/DEBIAN/control sed -i "s/Architecture:/Architecture:$ARCH/g"$WORK_ROOT/deb_package/DEBIAN/control rsync -rat $WORK_ROOT/deb_package/DEBIAN $DEBBUILD rsync -rat $BIN_PATH $DEBBUILD/$_LIB_PREFIX pushd $DEBBUILD mv ./DEBIAN ./debian mv usr/local/sietium/lib64/pkgconfig . dpkg-shlibdeps usr/local/sietium/lib64/* mv ./pkgconfig usr/local/sietium/lib64/ DEPS=`cat debian/substvars | awk -F'shlibs:Depends=' '{print $2}'` sed -i "s/Depends:/Depends:$DEPS/g" debian/control mv ./debian ./DEBIAN popd dpkg-deb--build $DEBBUILD $WORK_ROOT/$PACKAGE_NAME.deb Popd exit } while getopts a:b:d:o:v:w:t:i:h:r:l:c:h: option do case $option in a) ARCH=$OPTARG;; b) BIN_PATH=$OPTARG;; f) CONF_PATH=$OPTARG;; o) OS=$OPTARG;; v) VERSION=$OPTARG;; w)WORK_ROOT=$OPTARG;; t) PACKAGE_TYPE=$OPTARG;; i) BUILD_ID=$OPTARG;; r) RELEASE=$OPTARG;; l) _LIB_PREFIX=$OPTARG;; c)_CONF_PREFIX=$OPTARG;; h) usage;; ?) usage;; esac done echo "build env:" echo " Arch:" $ARCH echo " OS:" $OS echo " Version:" $VERSION echo " RELEASE:" $RELEASE echo " Work dir:" SWORK_ROOT echo " Package type:" $PACKAGE_TYPE BUILD_ROOT=$WORK_ROOT/build _package_$BUILD_ID if [ $PACKAGE_TYPE =='rpm']; then build_rpm_package elif[$PACKAGE_TYPE =='deb']; then build_deb_package else build_rpm_package build_deb_package fi解释脚本意义
时间: 2024-04-07 16:29:28 浏览: 119
这是一个 Bash 脚本,用于构建软件包。它包含了两个函数 `build_rpm_package()` 和 `build_deb_package()`,分别用于构建 RPM 和 DEB 类型的软件包。脚本接受一些参数,如架构 `-a`、二进制文件路径 `-b`、操作系统 `-o`、版本号 `-v`、工作目录 `-w`、软件包类型 `-t`、构建 ID `-i`、发布版本号 `-r`、库路径前缀 `-l` 等等。脚本中使用了一些 Linux 命令,如 `mkdir`、`pushd`、`popd`、`rsync`、`sed`、`awk`、`dpkg-shlibdeps`、`dpkg-deb` 等等,用于创建目录、切换工作目录、复制文件、修改文件内容、生成软件包依赖信息等等。脚本最后根据软件包类型调用相应的构建函数,如果类型不是 RPM 或 DEB,则默认同时构建 RPM 和 DEB。
阅读全文