1
0

feat: 添加Docker构建

This commit is contained in:
TsMask
2025-05-15 14:40:57 +08:00
parent bbbd5471c7
commit 7891d268cb
12 changed files with 591 additions and 44 deletions

View File

@@ -1,6 +1,6 @@
#!/bin/bash
# 默认版本值
# Default Version
VERSION="1.0.0"
# usage
usage() {
@@ -12,19 +12,19 @@ usage() {
echo
exit 1
}
# 读取命令行参数
# Read command line arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-v) VERSION="$2"; shift 2 ;; # 处理 -v 后面的版本
-v) VERSION="$2"; shift 2 ;; # Processing the version after -v
*) usage ;;
esac
done
# 输出结果
# output result
echo "Version: $VERSION"
# ===================
# =================== Compile System Information
# 包管理器
# package manager
get_manager() {
if command -v rpm &> /dev/null; then
echo "rpm"
@@ -36,11 +36,11 @@ get_manager() {
exit 1
fi
}
# 获取当前系统的包管理器
# Get the package manager of the current system
PACKAGE_MANAGER=$(get_manager)
echo "Package Manager: $PACKAGE_MANAGER"
# 架构
# System Architecture
get_arch() {
ARCH_UNAME=$(uname -m)
case $ARCH_UNAME in
@@ -53,12 +53,12 @@ get_arch() {
;;
esac
}
# 获取当前系统的架构
# Get the architecture of the current system
PACKAGE_ARCH=$(get_arch)
echo "Architecture: $PACKAGE_ARCH"
# 操作系统名称
get_os_name() {
# Operating System Name Version
get_os_name_version() {
if [ -f /etc/os-release ]; then
. /etc/os-release
# 检查 $ID 是否为空
@@ -72,32 +72,34 @@ get_os_name() {
exit 1
fi
}
# 获取当前操作系统名称
OS_NAME=$(get_os_name)
echo "OS: $OS_NAME"
# Get the current operating system name version
OS_NAME=$(get_os_name_version)
echo "OS Version: $OS_NAME"
# ===================
# 编译日期
# =================== Compile Variable Information
# Compile Date
Date=`date +%Y%m%d`
# 脚本所在路径
# Script Path
RootDir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# 编译Linux目录
# Compile Linux System Directory
BuildLinuxDir=${RootDir}/linux
# 编译包管理目录
# Compile Package Management Directory
BuildPackagelDir=${RootDir}/pkg
# 编译目录
# Compile the build directory
BuildDir=${RootDir}/tmp
# 发布包目录
# Release Package directory
ReleaseDir=${RootDir}/release/${PACKAGE_MANAGER}/${PACKAGE_ARCH}
# 发布包文件名称
# Release Package name file
ReleaseFileName=omc-r${VERSION}-${Date}-${OS_NAME}-${PACKAGE_ARCH}.${PACKAGE_MANAGER}
# ===================
# 应用文件处理 ./位于临时目录
# =================== file processing
# Apply file handling . /Located in the temporary directory
app() {
# 数据库脚本 common属于重建脚本
# Database scripts within common are rebuild scripts
modeList="std lite"
for v in ${modeList}; do
path=./usr/local/etc/omc/database/${v}
@@ -107,54 +109,56 @@ app() {
done
}
# ===================
# deb包管理器
# =================== system package manager
# deb package manager
deb() {
cd ${BuildDir}
# 替换标签 {version} {arch}
# Replacement Tags {version} {arch}
sed -i "s/{arch}/${PACKAGE_ARCH}/g" ./DEBIAN/control
sed -i "s/{version}/${VERSION}/g" ./DEBIAN/control
sed -i "s/{date}/${Date}/g" ./DEBIAN/control
# 打包deb
# Packaging deb
chmod 755 -R ${BuildDir}
dpkg -b ${BuildDir} ${ReleaseDir}/${ReleaseFileName}
# 生成MD5文件
# Generate MD5 file
rm -f omc_md5sum.txt
md5sum ${ReleaseDir}/${ReleaseFileName} >${ReleaseDir}/omc_md5sum.txt
cat ${ReleaseDir}/omc_md5sum.txt
}
# rpm包管理器
# rpm package manager
rpm() {
cd ${BuildDir}
ARCH_UNAME=$(uname -m)
# 替换标签 {version} {arch} {date}
# Replacement Tags {version} {arch} {date}
sed -i "s/{version}/${VERSION}/g" ./SPECS/omc.spec
sed -i "s/{arch}/${ARCH_UNAME}/g" ./SPECS/omc.spec
sed -i "s/{date}/${Date}/g" ./SPECS/omc.spec
# 打包rpm
# Packaging rpm
chmod 755 -R ${BuildDir}
rpmbuild -bb -D "_topdir ${BuildDir}" ${BuildDir}/SPECS/omc.spec
# 移动rpm包到发布目录
if [[ "$OS_NAME" == kylin* ]]; then # 麒麟系统有ky10标签
# Moving package to the distribution directory
if [[ "$OS_NAME" = "kylinV10" ]]; then # kylin system has ky10 tags
mv ${BuildDir}/RPMS/${ARCH_UNAME}/omc-${VERSION}-${Date}.ky10.${ARCH_UNAME}.rpm ${ReleaseDir}/${ReleaseFileName}
else
mv ${BuildDir}/RPMS/${ARCH_UNAME}/omc-${VERSION}-${Date}.${ARCH_UNAME}.rpm ${ReleaseDir}/${ReleaseFileName}
fi
rm -rf ${BuildDir}/RPMS
# 生成MD5文件
# Generate MD5 file
rm -f omc_md5sum.txt
md5sum ${ReleaseDir}/${ReleaseFileName} >${ReleaseDir}/omc_md5sum.txt
cat ${ReleaseDir}/omc_md5sum.txt
}
# ===================
# =================== building
echo
echo "building omc..."
rm -rf ${BuildDir} && mkdir -p ${BuildDir}
@@ -162,18 +166,16 @@ cp -rf ${BuildPackagelDir}/${PACKAGE_MANAGER}/* ${BuildDir}
if [[ $PACKAGE_MANAGER = "deb" ]]; then
cp -rf ${BuildLinuxDir}/* ${BuildDir}
cd ${BuildDir}
# 应用文件处理
app
# 打包
deb
elif [[ $PACKAGE_MANAGER = "rpm" ]]; then
cp -rf ${BuildLinuxDir}/* ${BuildDir}/BUILD
cd ${BuildDir}/BUILD
# 应用文件处理
app
# 打包
rpm
else
echo "unknown runing: $PACKAGE_MANAGER"
exit 1
fi
# bash build.sh -v 2.2505.2