Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
songlinfeng
container-toolkit
Commits
1a0cbe54
Commit
1a0cbe54
authored
Dec 09, 2025
by
songlinfeng
💬
Browse files
support deb offline build
parent
4b9ce81e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
27 deletions
+93
-27
build.sh
build.sh
+93
-27
No files found.
build.sh
View file @
1a0cbe54
...
...
@@ -2,8 +2,24 @@
set
-ex
# 从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_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
echo
"Error: 无法从versions.mk读取版本信息"
>
&2
exit
1
...
...
@@ -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
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
""
)
PKG_VERS
=
"
$PACKAGE_VERSION
"
PKG_REV
=
"
$PACKAGE_REVISION
"
if
[
!
-d
dist
]
;
then
mkdir
dist
if
[
"
$PACKAGE_TYPE
"
=
"rpm"
]
;
then
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
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
;
}
if
[
"
$PACKAGE_TYPE
"
=
"deb"
]
;
then
ARCH
=
"
$(
dpkg-architecture
-qDEB_HOST_ARCH
)
"
if
[
-d
${
PKG_NAME
}
]
;
then
rm
-rf
${
PKG_NAME
}
fi
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment