WITH_OPENSSL accepts as env variable

This commit is contained in:
boypt
2025-12-26 15:55:15 +08:00
parent 9de9103bed
commit a2ab36729c
4 changed files with 107 additions and 103 deletions

View File

@@ -17,7 +17,7 @@ __root="$(cd "$(dirname "${__dir}")" && pwd)" # <-- change this as it depends on
arg1="${1:-}"
rpmtopdir=
WITH_OPENSSL=0
# WITH_OPENSSL=
# Control openssl dependency
# 0: build without openssl
# 1: use system openssl
@@ -32,139 +32,143 @@ CHECKEXISTS() {
GUESS_DIST() {
# will not work if rpm cmd not exists
if ! type -p rpm > /dev/null;then
echo 'unknown' && return 0
fi
# 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+
# 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')
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 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 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 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
# 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
# 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
[[ -z ${WITH_OPENSSL:-} ]] && WITH_OPENSSL=1
;;
el7)
rpmtopdir=el7
[[ -z ${WITH_OPENSSL:-} ]] && WITH_OPENSSL=2
;;
el6)
rpmtopdir=el6
[[ -z ${WITH_OPENSSL:-} ]] && WITH_OPENSSL=0
;;
el5)
rpmtopdir=el5
[[ -z ${WITH_OPENSSL:-} ]] && WITH_OPENSSL=0
# on centos5, it's prefered to use gcc44
rpm -q gcc44 2>&1 >/dev/null && export CC=gcc44
;;
*)
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
local SOURCES=( $OPENSSHSRC \
$OPENSSLSRC \
$ASKPASSSRC \
)
local RPMBUILDOPTS=( \
--define "with_openssl ${WITH_OPENSSL}" \
--define "opensslver ${OPENSSLVER}" \
--define "opensshver ${OPENSSHVER}" \
--define "opensshpkgrel ${PKGREL}" \
--define 'debug_package %{nil}' \
--define 'no_gtk2 1' \
--define 'skip_gnome_askpass 1' \
--define 'skip_x11_askpass 1' \
)
source version.env
local SOURCES=( $OPENSSHSRC \
$OPENSSLSRC \
$ASKPASSSRC \
)
local RPMBUILDOPTS=( \
--define "with_openssl ${WITH_OPENSSL}" \
--define "opensslver ${OPENSSLVER}" \
--define "opensshver ${OPENSSHVER}" \
--define "opensshpkgrel ${PKGREL}" \
--define 'debug_package %{nil}' \
--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')
# 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)")
# 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
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/$(rpm --eval '%{_arch}')
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' ! -name '*debug*'
[[ -d $RPMDIR ]] && find $RPMDIR -type f -name '*.rpm'
}
# sub cmds
case $arg1 in
GETEL)
GUESS_DIST && exit 0
;;
GETRPM)
LIST_RPMS && exit 0
;;
RPMDIR)
LIST_RPMDIR && exit 0
;;
GETEL)
GUESS_DIST
exit 0
;;
GETRPM)
TOPDIR_SELECT
LIST_RPMS
exit 0
;;
RPMDIR)
TOPDIR_SELECT
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
el8)
rpmtopdir=el7
WITH_OPENSSL=1
;;
el7)
rpmtopdir=el7
WITH_OPENSSL=2
;;
el6)
rpmtopdir=el6
WITH_OPENSSL=0
;;
el5)
rpmtopdir=el5
WITH_OPENSSL=0
# on centos5, it's prefered to use gcc44
rpm -q gcc44 && export CC=gcc44
;;
*)
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"
;;
esac
fi
TOPDIR_SELECT
if [[ ! -d $rpmtopdir ]]; then
echo "This script works only in el5/el6/el7"