-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathbuild_packages.sh
executable file
·160 lines (129 loc) · 3.81 KB
/
build_packages.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
#
# Create package of various environments from the source
# Wed, 24 Jul 2024 10:59:35 +0900
# Kevin Kim ([email protected])
#
# ./build_packages.sh rpm
# ./build_packages.sh deb
# ./build_packages.sh arch
# ./build_packages.sh rpm deb arch # All
# Exit immediately if a command exits with a non-zero status
set -e
# Enable extended globbing for excluding the build directory
shopt -s extglob
# Define project root directory
PROJECT_ROOT=$(pwd)
# Define build directories
BUILD_DIR="${PROJECT_ROOT}/build"
RPMS_DIR="${BUILD_DIR}/RPMS"
DEBS_DIR="${BUILD_DIR}/DEBS"
ARCH_DIR="${BUILD_DIR}/ARCH"
SOURCES_DIR="${BUILD_DIR}/SOURCES"
NIMF_SRC="${PROJECT_ROOT}"
# Function to build RPM package
build_rpm() {
SPEC_FILE="${PROJECT_ROOT}/nimf.spec"
SPECS_DIR="${BUILD_DIR}/SPECS"
# Create required directories
mkdir -p "${BUILD_DIR}" "${RPMS_DIR}" "${SOURCES_DIR}" "${SPECS_DIR}"
# Install required packages
. /etc/os-release
if [[ "$ID" = "opensuse-leap" ]] ; then
sudo zypper install -y rpm-build rpmdevtools
else
sudo yum install -y rpm-build rpmdevtools
fi
# Setup rpmbuild environment
rpmdev-setuptree
# Copy spec file to SPECS directory
cp "${SPEC_FILE}" "${SPECS_DIR}"
# Prepare sources
cd "${SOURCES_DIR}"
if [ -d "nimf" ]; then
rm -rf nimf
fi
mkdir nimf
# Copy all contents except the build directory
cp -r ${NIMF_SRC}/!(build) nimf/
tar -czf nimf-1.3.8.tar.gz -C "${SOURCES_DIR}" nimf
# Return to the project root directory
cd "${PROJECT_ROOT}"
# Build the RPM
rpmbuild --define "_topdir ${BUILD_DIR}" -ba "${SPECS_DIR}/nimf.spec"
# Output the location of the built RPMs
echo "RPMs have been built and are located in: ${RPMS_DIR}"
}
# Function to build DEB package
build_deb() {
DEBIAN_DIR="${PROJECT_ROOT}/debian"
# Create required directories
mkdir -p "${BUILD_DIR}" "${DEBS_DIR}"
# Install required packages
sudo apt-get update
sudo apt-get install -y build-essential devscripts debhelper
# Prepare sources
cd "${BUILD_DIR}"
if [ -d "nimf" ]; then
rm -rf nimf
fi
mkdir nimf
# Copy all contents except the build directory
cp -r ${NIMF_SRC}/!(build) nimf/
# Build the DEB package
cd nimf
debuild -us -uc
# Move DEB files to DEBS_DIR
mv ../*.deb "${DEBS_DIR}"
# Return to the project root directory
cd "${PROJECT_ROOT}"
# Output the location of the built DEBs
echo "DEB packages have been built and are located in: ${DEBS_DIR}"
}
# Function to build Arch Linux package
build_arch() {
PKGBUILD_FILE="${PROJECT_ROOT}/PKGBUILD"
# Create required directories
mkdir -p "${BUILD_DIR}" "${ARCH_DIR}"
# Install required packages
sudo pacman -Sy --needed base-devel
# Prepare sources
cd "${BUILD_DIR}"
if [ -d "nimf" ]; then
rm -rf nimf
fi
mkdir nimf
# Copy all contents except the build directory
cp -r ${NIMF_SRC}/!(build) nimf/
# Build the Arch package
cd nimf
makepkg -si
# Move package files to ARCH_DIR
mv *.pkg.tar.zst "${ARCH_DIR}"
# Return to the project root directory
cd "${PROJECT_ROOT}"
# Output the location of the built Arch packages
echo "Arch packages have been built and are located in: ${ARCH_DIR}"
}
# Check for command line arguments and call respective functions
if [ "$#" -eq 0 ]; then
echo "No package type specified. Please use 'rpm', 'deb', or 'arch' as arguments."
exit 1
fi
for arg in "$@"; do
case $arg in
rpm)
build_rpm
;;
deb)
build_deb
;;
arch)
build_arch
;;
*)
echo "Invalid argument: $arg. Please use 'rpm', 'deb', or 'arch'."
exit 1
;;
esac
done