182 lines
4.5 KiB
Bash
Executable File
182 lines
4.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Default Version
|
|
VERSION="1.0.0"
|
|
# usage
|
|
usage() {
|
|
echo "Usage: bash $0 [OPTION]"
|
|
echo
|
|
echo "Build Software Package OPTION:"
|
|
echo " -v Specify the version"
|
|
echo " -h Display this help message"
|
|
echo
|
|
exit 1
|
|
}
|
|
# Read command line arguments
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
-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"
|
|
elif command -v dpkg &> /dev/null; then
|
|
echo "deb"
|
|
else
|
|
echo "unknown manager"
|
|
cat /etc/os-release
|
|
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
|
|
x86_64) echo "amd64" ;;
|
|
aarch64) echo "arm64" ;;
|
|
i386|i686) echo "i386" ;;
|
|
*)
|
|
echo "unknown architecture: $ARCH_UNAME"
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
# Get the architecture of the current system
|
|
PACKAGE_ARCH=$(get_arch)
|
|
echo "Architecture: $PACKAGE_ARCH"
|
|
|
|
# Operating System Name Version
|
|
get_os_name_version() {
|
|
if [ -f /etc/os-release ]; then
|
|
. /etc/os-release
|
|
# 检查 $ID 是否为空
|
|
if [ -z "$ID" ]; then
|
|
echo "ID is not defined in /etc/os-release"
|
|
exit 1
|
|
fi
|
|
echo "$ID$VERSION_ID"
|
|
else
|
|
echo "unknown ID: /etc/os-release not found"
|
|
exit 1
|
|
fi
|
|
}
|
|
# 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)
|
|
# 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() {
|
|
# Database scripts within common are rebuild scripts
|
|
modeList="std lite"
|
|
for v in ${modeList}; do
|
|
path=./usr/local/etc/omc/database/${v}
|
|
cp -rf $path/common/* $path/install/
|
|
cp -rf $path/common/* $path/upgrade/
|
|
rm -rf $path/common
|
|
done
|
|
}
|
|
|
|
|
|
# =================== system package manager
|
|
|
|
# deb package manager
|
|
deb() {
|
|
cd ${BuildDir}
|
|
|
|
# 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
|
|
|
|
# Packaging deb
|
|
chmod 755 -R ${BuildDir}
|
|
dpkg -b ${BuildDir} ${ReleaseDir}/${ReleaseFileName}
|
|
|
|
# Generate MD5 file
|
|
rm -f omc_md5sum.txt
|
|
md5sum ${ReleaseDir}/${ReleaseFileName} >${ReleaseDir}/omc_md5sum.txt
|
|
cat ${ReleaseDir}/omc_md5sum.txt
|
|
}
|
|
|
|
# rpm package manager
|
|
rpm() {
|
|
cd ${BuildDir}
|
|
ARCH_UNAME=$(uname -m)
|
|
# 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
|
|
|
|
# Packaging rpm
|
|
chmod 755 -R ${BuildDir}
|
|
rpmbuild -bb -D "_topdir ${BuildDir}" ${BuildDir}/SPECS/omc.spec
|
|
# 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
|
|
|
|
# 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}
|
|
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
|