Commit 1a0cbe54 authored by songlinfeng's avatar songlinfeng 💬
Browse files

support deb offline build

parent 4b9ce81e
...@@ -2,8 +2,24 @@ ...@@ -2,8 +2,24 @@
set -ex set -ex
# 从versions.mk读取版本信息 # 从versions.mk读取版本信息
OS_NAME=$(grep '^NAME=' /etc/os-release | cut -d= -f2 | tr -d '"')
PACKAGE_TYPE="rpm"
case "$OS_NAME" in
"Red Hat Enterprise Linux"*|"CentOS"*|"Rocky Linux"*|"AlmaLinux"*|"Oracle Linux"*|"Amazon Linux"*|"Fedora"*)
PACKAGE_TYPE="rpm"
;;
"Debian"*|"Ubuntu"*|"Linux Mint"*|"Kali"*|"Raspbian"*|"Elementary"*|"Pop!_OS"*|"Zorin"*)
PACKAGE_TYPE="deb"
;;
*)
echo "Error: 不支持的操作系统 $OS_NAME" >&2
exit 1
;;
esac
PACKAGE_VERSION=$(grep '^LIB_VERSION :=' versions.mk | awk '{print $3}') PACKAGE_VERSION=$(grep '^LIB_VERSION :=' versions.mk | awk '{print $3}')
PACKAGE_REVISION=$(grep '^PACKAGE_REVISION :=' versions.mk | awk '{print $3}') PACKAGE_REVISION=$(grep '^PACKAGE_REVISION :=' versions.mk | awk '{print $3}')
PKG_NAME=$(grep '^LIB_NAME :=' versions.mk | awk '{print $3}')
if [ -z "$PACKAGE_VERSION" ] || [ -z "$PACKAGE_REVISION" ]; then if [ -z "$PACKAGE_VERSION" ] || [ -z "$PACKAGE_REVISION" ]; then
echo "Error: 无法从versions.mk读取版本信息" >&2 echo "Error: 无法从versions.mk读取版本信息" >&2
exit 1 exit 1
...@@ -20,34 +36,84 @@ mv -T golang.org/toolchain@v0.0.1-go1.24.6.linux-amd64/ ${HOME}/go || { echo "Er ...@@ -20,34 +36,84 @@ mv -T golang.org/toolchain@v0.0.1-go1.24.6.linux-amd64/ ${HOME}/go || { echo "Er
export PATH=${HOME}/go/bin:$PATH export PATH=${HOME}/go/bin:$PATH
make cmds make cmds
source=("dcu-container-runtime" "dcu-cdi-hook" "dcu-ctk" "dcu-docker")
dirs=("SOURCES" "RPMS" "BUILD" "SRPMS" "BUILDROOT")
for dir in "${dirs[@]}"
do
if [ ! -d $dir ];then
mkdir $dir
fi
done
for file in "${source[@]}"
do
rm -rf SOURCES/$file > /dev/null 2>&1
cp -r $file SOURCES/$file
done
cp -rf packaging/rpm/SOURCES/* SOURCES/ > /dev/null 2>&1
# 使用现代命令替换语法,提高可读性
GIT_COMMIT=$(git describe --match="" --dirty --long --always --abbrev=40 2> /dev/null || echo "") GIT_COMMIT=$(git describe --match="" --dirty --long --always --abbrev=40 2> /dev/null || echo "")
PKG_VERS="$PACKAGE_VERSION" PKG_VERS="$PACKAGE_VERSION"
PKG_REV="$PACKAGE_REVISION" PKG_REV="$PACKAGE_REVISION"
if [ ! -d dist ];then if [ "$PACKAGE_TYPE" = "rpm" ]; then
mkdir dist source=("dcu-container-runtime" "dcu-cdi-hook" "dcu-ctk" "dcu-docker")
dirs=("SOURCES" "RPMS" "BUILD" "SRPMS" "BUILDROOT")
for dir in "${dirs[@]}"
do
if [ ! -d $dir ];then
mkdir $dir
fi
done
for file in "${source[@]}"
do
rm -rf SOURCES/$file > /dev/null 2>&1
cp -r $file SOURCES/$file
done
cp -rf packaging/rpm/SOURCES/* SOURCES/ > /dev/null 2>&1
# 使用现代命令替换语法,提高可读性
if [ ! -d dist ];then
mkdir dist
fi
arch=$(uname -m) && \
rpmbuild --clean --target="$arch" -bb \
-D "_topdir $PWD" \
-D "release_date $(date +'%a %b %d %Y')" \
-D "git_commit ${GIT_COMMIT}" \
-D "version ${PKG_VERS}" \
-D "release ${PKG_REV}" \
packaging/rpm/SPECS/dcu-container-toolkit.spec && \
# 检查并移动RPM包,添加错误提示
mv RPMS/"$arch"/*.rpm dist || { echo "Error: 未找到生成的RPM包" >&2; exit 1; }
fi fi
arch=$(uname -m) && \
rpmbuild --clean --target="$arch" -bb \
-D "_topdir $PWD" \ if [ "$PACKAGE_TYPE" = "deb" ]; then
-D "release_date $(date +'%a %b %d %Y')" \ ARCH="$(dpkg-architecture -qDEB_HOST_ARCH)"
-D "git_commit ${GIT_COMMIT}" \
-D "version ${PKG_VERS}" \ if [ -d ${PKG_NAME} ];then
-D "release ${PKG_REV}" \ rm -rf ${PKG_NAME}
packaging/rpm/SPECS/dcu-container-toolkit.spec && \ fi
# 检查并移动RPM包,添加错误提示
mv RPMS/"$arch"/*.rpm dist || { echo "Error: 未找到生成的RPM包" >&2; exit 1; } if [ ! -d dist ];then
mkdir dist
fi
mkdir -p ${PKG_NAME}/DEBIAN
mkdir -p ${PKG_NAME}/usr/bin
cp dcu-container-runtime ${PKG_NAME}/usr/bin/
cp dcu-cdi-hook ${PKG_NAME}/usr/bin/
cp dcu-ctk ${PKG_NAME}/usr/bin/
cp dcu-docker ${PKG_NAME}/usr/bin/
chmod 755 ${PKG_NAME}/usr/bin/*
cp packaging/debian/dcu-container-toolkit.postinst ${PKG_NAME}/DEBIAN/postinst
chmod 755 ${PKG_NAME}/DEBIAN/postinst
cp packaging/debian/dcu-container-toolkit.postrm ${PKG_NAME}/DEBIAN/postrm
chmod 755 ${PKG_NAME}/DEBIAN/postrm
cat > ${PKG_NAME}/DEBIAN/control << EOF
Package: ${PKG_NAME}
Version: ${PACKAGE_VERSION}-${PACKAGE_REVISION}
Section: utils
Priority: optional
Architecture: ${ARCH}
Maintainer: Your Name <you@example.com>
Description: DCU runtime and related utilities
This package contains dcu-container-runtime, dcu-ctk, dcu-docker, dcu-cdi-hook.
EOF
dpkg-deb --build ${PKG_NAME} dist/${PKG_NAME}_${PACKAGE_VERSION}-${PACKAGE_REVISION}_${ARCH}.deb
rm -rf ${PKG_NAME}
fi
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment