-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.sh
executable file
·172 lines (158 loc) · 4.92 KB
/
build.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
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
### Build using:
#DIST=ubuntu_bionic ; docker run -it --rm -v `dirname $PWD`:/home/build $DIST /home/build/`basename $PWD`/build.sh `basename $PWD` $DIST $PKG_NAME
## ASSUMPTION: /home/build/$PACKAGE holds the sources for the package to be built
## ASSUMPTION: /home/build is on the host system.
## PKG_NAME is optional, defaults to $PACKAGE when not given
BASE="/home/build"
PACKAGE=$1
DIST=$2
OUTPUT="$BASE/results"
PKG_NAME=$3
test -z $PKG_NAME && {
echo "Package name not specified, using $PACKAGE"
PKG_NAME=$PACKAGE
}
echo "PACKAGE=$PACKAGE"
echo "DIST=$DIST"
echo "PKG_NAME=$PKG_NAME"
test -z $DIST && {
echo "Must specify DIST as 2nd parameter"
exit
}
common_prepare_dirs() {
mkdir -p /tmp/build
mkdir -p $OUTPUT/$DIST
cp -af $BASE/$PACKAGE /tmp/build
cd /tmp/build/$PACKAGE
}
common_fix_output_permissions() {
UP_UID=`stat -c '%u' $BASE`
UP_GID=`stat -c '%g' $BASE`
chown $UP_UID:$UP_GID $OUTPUT
chown -R $UP_UID:$UP_GID $OUTPUT/$DIST
}
debian_install_dependencies() {
apt-get update
apt-get -y install libffi-dev \
python3 python3-dev python3-pip python3-setuptools
}
debian_build_package() {
make debsource && \
dpkg-buildpackage -uc -us
}
debian_copy_output() {
echo "Moving output:"
ls -l ..
mv ../${PKG_NAME}_[0-9]* $OUTPUT/$DIST
mv ../${PKG_NAME}-dbgsym_* $OUTPUT/$DIST 2>/dev/null
}
ubuntu_focal_install_dependencies() {
apt-get update
apt-get -y install software-properties-common
add-apt-repository -y ppa:jyrki-pulliainen/dh-virtualenv
apt-get update
apt-get -y install dh-virtualenv
}
ubuntu_bionic_install_dependencies() {
apt-get update
apt-get -y install python3.8 python3.8-dev python3.8-venv python3-pip libffi-dev
update-alternatives --install /usr/bin/python3 python /usr/bin/python3.8 1
python3 -m pip install -U pip
git config --global --add safe.directory /tmp/build/$PACKAGE
}
rocky8_install_dependencies() {
yum -y install python39 python39-devel python3-policycoreutils
pip3 install -U pip
pip install virtualenv
}
centos7_install_dependencies() {
yum -y install centos-release-scl-rh centos-release-scl
yum -y install rh-python38 rh-python38-python-devel
yum -y install policycoreutils policycoreutils-python
echo -e "source /opt/rh/rh-python38/enable\n"\
"export X_SCLS=\"\`scl enable rh-python38 'echo $X_SCLS'\`\""\
>> /etc/profile.d/python38.sh
source /opt/rh/rh-python38/enable
pip install virtualenv
}
opensuse15_install_dependencies() {
zypper -n install libcurl-devel pam-devel zypper audit-devel git \
python311 python311-devel python311-pip python311-setuptools
zypper -n install policycoreutils
zypper -n install python3-policycoreutils
pip3.11 install -U pip
pip3 install virtualenv || {
/usr/local/bin/pip3 install virtualenv
}
git config --global --add safe.directory /tmp/build/$PACKAGE
}
opensuse154_install_dependencies() {
zypper -n install libcurl-devel pam-devel zypper audit-devel git \
python39 python39-devel python39-pip python39-setuptools
zypper -n install policycoreutils
zypper -n install python3-policycoreutils
pip3.9 install -U pip
pip3 install virtualenv || {
/usr/local/bin/pip3 install virtualenv
}
git config --global --add safe.directory /tmp/build/$PACKAGE
}
centos7_patch_rpm() {
# Force RPM's python-bytecompile script to use python3
sed "s@^default_python@default_python=python3\n#default_python@" -i /usr/lib/rpm/brp-python-bytecompile
echo "typing-extensions" >> requirements.txt
}
rpm_build_package() {
cd /tmp/build/$PACKAGE
make rpms
}
rpm_copy_output() {
ls -l rpm/rpmbuild/RPMS/*/*
ls -l rpm/rpmbuild/SRPMS/
echo "-----"
mv rpm/rpmbuild/RPMS/*/${PKG_NAME}*rpm $OUTPUT/$DIST/
mv rpm/rpmbuild/SRPMS/*rpm $OUTPUT/$DIST
}
###########################################################################
common_prepare_dirs
case "$DIST" in
debian_buster|debian_bullseye|debian_bookworm)
debian_install_dependencies
debian_build_package
debian_copy_output
;;
ubuntu_focal)
ubuntu_focal_install_dependencies
debian_install_dependencies
debian_build_package
debian_copy_output
;;
ubuntu_bionic)
ubuntu_bionic_install_dependencies
debian_build_package
debian_copy_output
;;
centos7)
centos7_install_dependencies
centos7_patch_rpm
rpm_build_package
rpm_copy_output
;;
centos_stream|rocky8*|centos8)
rocky8_install_dependencies
rpm_build_package
rpm_copy_output
;;
opensuse15.5|opensuse_tumbleweed|sle*)
opensuse15_install_dependencies
rpm_build_package
rpm_copy_output
;;
opensuse15.4)
opensuse154_install_dependencies
rpm_build_package
rpm_copy_output
;;
esac
common_fix_output_permissions