-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathcompile.sh
executable file
·175 lines (143 loc) · 4.24 KB
/
compile.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
173
174
#!/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=
# trap 'echo Signal caught, cleaning up >&2; cd /tmp; /bin/rm -rfv "$TMP"; exit 15' 1 2 3 15
# allow command fail:
# fail_command || true
#
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="el7"
[[ $dist == "el8" ]] && dist="el7"
[[ $dist == "an7" ]] && dist="el7"
[[ $dist == "an8" ]] && dist="el7"
[[ -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 'el7' && return 0
}
BUILD_RPM() {
source version.env
local SOURCES=( $OPENSSHSRC \
$OPENSSLSRC \
$ASKPASSSRC \
)
local RPMBUILDOPTS=( \
--define "opensslver ${OPENSSLVER}" \
--define "opensshver ${OPENSSHVER}" \
--define "opensshpkgrel ${PKGREL}" \
--define 'no_gtk2 1' \
--define 'skip_gnome_askpass 1' \
--define 'skip_x11_askpass 1' \
)
# only on EL5, perl source is needed.
[[ $rpmtopdir == "el5" ]] && \
SOURCES+=($PERLSRC) && \
RPMBUILDOPTS+=('--define' "perlver ${PERLVER}"
'--define' 'dist .el5')
# 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
rpmbuild -ba ./SPECS/openssh.spec "${RPMBUILDOPTS[@]}"
popd
}
LIST_RPMDIR(){
local DISTVER=$(GUESS_DIST)
local RPMDIR=$__dir/$(GUESS_DIST)/RPMS/$(uname -m)
[[ -d $RPMDIR ]] && echo $RPMDIR
}
LIST_RPMS() {
local RPMDIR=$(LIST_RPMDIR)
[[ -d $RPMDIR ]] && find $RPMDIR -type f -name '*.rpm' ! -name '*debug*'
}
# sub cmds
case $arg1 in
GETEL)
GUESS_DIST && exit 0
;;
GETRPM)
LIST_RPMS && exit 0
;;
RPMDIR)
LIST_RPMDIR && exit 0
;;
esac
# manual specified dist
[[ -n $arg1 && -d $__dir/$arg1 ]] && rpmtopdir=$arg1 && BUILD_RPM && exit 0
# auto detect distro
if [[ -z $arg1 ]]; then
DISTVER=$(GUESS_DIST)
case $DISTVER in
amzn1)
rpmtopdir=amzn1
;;
amzn2)
rpmtopdir=amzn2
;;
amzn2023)
rpmtopdir=amzn2023
;;
el7)
rpmtopdir=el7
;;
el6)
rpmtopdir=el6
;;
el5)
rpmtopdir=el5
# on centos5, it's prefered to use gcc44
rpm -q gcc44 && export CC=gcc44
;;
*)
echo "Distro undefined, please specify manually: el5 el6 el7 amzn1 amzn2 amzn2023"
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"
;;
esac
fi
if [[ ! -d $rpmtopdir ]]; then
echo "This script works only in el5/el6/el7/amzn1/amzn2/amzn2023"
echo "eg: ${0} el7"
exit 1
fi
[[ -d $rpmtopdir ]] && BUILD_RPM