-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy pathcompile.sh
More file actions
executable file
·213 lines (177 loc) · 5.45 KB
/
Copy pathcompile.sh
File metadata and controls
executable file
·213 lines (177 loc) · 5.45 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env bash
# Bash3 Boilerplate. Copyright (c) 2014, kvz.io
set -o errexit
set -o pipefail
set -o nounset
# set -o xtrace
trap 'echo -e "Aborted, error $? in command: $BASH_COMMAND"; trap ERR; exit 1' ERR
# Set magic variables for current file & dir
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
__root="$(cd "$(dirname "${__dir}")" && pwd)" # <-- change this as it depends on your app
arg1="${1:-}"
rpmtopdir=
# WITH_OPENSSL=
# Control openssl dependency
# 0: build without openssl
# 1: use system openssl
# 2: build openssl statically
CHECKEXISTS() {
if [[ ! -f $__dir/downloads/$1 ]];then
echo "$1 not found, run 'pullsrc.sh', or manually put it in the downloads dir."
exit 1
fi
}
GUESS_DIST() {
# will not work if rpm cmd not exists
if ! type -p rpm > /dev/null;then
echo 'unknown' && return 0
fi
local dist=$(rpm --eval '%{?dist}' | tr -d '.')
# fallback to el7
[[ $dist == "el9" ]] && dist="el8"
[[ $dist == "el8" ]] && dist="el8"
[[ $dist == "an8" ]] && dist="el8" # Anolis 8
[[ $dist == "an7" ]] && dist="el7" # Anolis 7
[[ $dist == uel* ]] && dist="el8" # UOS20+
[[ -n $dist ]] && echo $dist && return 0
local glibcver=$(ldd --version | head -n1 | grep -Eo '[0-9]+' | tr -d '\n')
# centos 5 uses glibc 2.5
[[ $glibcver -eq 25 ]] && echo 'el5' && return 0
# centos 6 uses glibc 2.12
[[ $glibcver -eq 212 ]] && echo 'el6' && return 0
# centos 7 uses glibc 2.17
[[ $glibcver -eq 217 ]] && echo 'el7' && return 0
# centos 8 uses glibc 2.28, not yet to be in a seprate dir
[[ $glibcver -eq 228 ]] && echo 'el8' && return 0
# some centos-like dists ships higher version of glibc, fallback to el7
[[ $glibcver -gt 217 ]] && echo 'el8' && return 0
}
TOPDIR_SELECT() {
local DISTVER=$(GUESS_DIST)
case $DISTVER in
el8)
rpmtopdir=el7
WITH_OPENSSL=${WITH_OPENSSL:-1}
;;
el7)
rpmtopdir=el7
WITH_OPENSSL=${WITH_OPENSSL:-2}
;;
el6)
rpmtopdir=el6
WITH_OPENSSL=${WITH_OPENSSL:-2}
;;
el5)
rpmtopdir=el5
WITH_OPENSSL=${WITH_OPENSSL:-2}
;;
*)
echo "Distro undefined, please specify manually: el5 el6 el7"
echo -e "\nCurrent OS:"
[[ -f /etc/os-release ]] && cat /etc/os-release
[[ -f /etc/redhat-release ]] && cat /etc/redhat-release
[[ -f /etc/system-release ]] && cat /etc/system-release
echo -e "Current OS vendor: $(rpm --eval '%{?_vendor}') \n"
return 1
;;
esac
}
BUILD_RPM() {
source version.env
[[ -f version-local.env ]] && source version-local.env
local SOURCES=( $OPENSSHSRC \
$OPENSSLSRC \
$ASKPASSSRC \
)
local RPMBUILDOPTS=( \
--define "with_openssl ${WITH_OPENSSL:-2}" \
--define "opensslver ${OPENSSLVER}" \
--define "opensshver ${OPENSSHVER}" \
--define "opensshpkgrel ${PKGREL:-1}" \
--define 'debug_package %{nil}' \
--define 'no_gtk2 1' \
--define 'skip_gnome_askpass 1' \
--define 'skip_x11_askpass 1' \
)
# EL5 dist fixes
if [[ $rpmtopdir == *el5 ]]; then
SOURCES+=($PERLSRC)
# Hack: fake the perl src when perl is ready already(docker images)
[[ $(perl -e 'print $] >= 5.010 ? 1 : 0') -eq 1 ]] && \
touch ./downloads/$PERLSRC
RPMBUILDOPTS+=('--define' "perlver ${PERLVER}" '--define' 'dist .el5')
export CC=gcc44
fi
# add dist variable if not defined
[[ $rpmtopdir == *el7 ]] && [[ -z $(rpm --eval '%{?dist}') ]] && \
RPMBUILDOPTS+=('--define' "dist .$(rpm -q glibc | rev | cut -d. -f2 | rev)")
pushd $rpmtopdir
RPMBUILDOPTS+=('--define' "_topdir $PWD")
for fn in ${SOURCES[@]}; do
CHECKEXISTS $fn && \
install -v -m666 $__dir/downloads/$fn ./SOURCES/
done
if [[ ${M32:-0} != 0 ]]; then
local SETARCH="setarch i386"
RPMBUILDOPTS+=('--target' i686)
export CFLAGS="${CFLAGS:-} -m32" LDFLAGS="${LDFLAGS:-} -m32"
fi
${SETARCH:-} \
rpmbuild -bb ./SPECS/${SPECFILE:-openssh.spec} "${RPMBUILDOPTS[@]}"
if [[ $? -ne 0 ]]; then
echo "Error: rpmbuild failed with exit code $?"
exit 1
fi
mkdir -p $__dir/output
find ./RPMS -type f -name '*.rpm' -exec install -v -m644 {} $__dir/output/ \;
popd
}
LIST_RPMDIR(){
local RPMDIR=$__dir/${rpmtopdir}/RPMS/$(rpm --eval '%{_arch}')
[[ -d $RPMDIR ]] && echo $RPMDIR
}
LIST_RPMS() {
local RPMDIR=$(LIST_RPMDIR)
[[ -d $RPMDIR ]] && find $RPMDIR -type f -name '*.rpm'
}
# sub cmds
case $arg1 in
GETEL)
GUESS_DIST
exit 0
;;
GETRPM)
TOPDIR_SELECT
LIST_RPMS
exit 0
;;
RPMDIR)
TOPDIR_SELECT
LIST_RPMDIR
exit 0
;;
*)
if [[ -n $arg1 && ! -d $arg1 ]]; then
echo -e "Subcmd: $arg1 not found.\n GETEL, GETRPM, RPMDIR"
exit 1
fi
;;
esac
# manual specified dist
if [[ -n $arg1 && -d $arg1 ]]; then
rpmtopdir=$arg1
BUILD_RPM
exit 0
fi
# auto select dist
TOPDIR_SELECT
if [[ ! -d $rpmtopdir ]]; then
echo "This script works only in el5/el6/el7"
echo "eg: ${0} el7"
exit 1
fi
if [[ -d $rpmtopdir ]]; then
BUILD_RPM
fi