build: show linux distro in BUILT_ON info

This commit is contained in:
Zaiming Shi 2021-10-31 17:14:19 +01:00
parent ecb6c1c59e
commit 9832a2ed00
4 changed files with 37 additions and 16 deletions

17
build
View File

@ -15,18 +15,7 @@ cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")"
PKG_VSN="${PKG_VSN:-$(./pkg-vsn.sh)}" PKG_VSN="${PKG_VSN:-$(./pkg-vsn.sh)}"
export PKG_VSN export PKG_VSN
if [ "$(uname -s)" = 'Darwin' ]; then SYSTEM="$(./scripts/get-distro.sh)"
SYSTEM=macos
elif [ "$(uname -s)" = 'Linux' ]; then
if grep -q -i 'centos' /etc/*-release; then
DIST='centos'
VERSION_ID="$(rpm --eval '%{centos_ver}')"
else
DIST="$(sed -n '/^ID=/p' /etc/os-release | sed -r 's/ID=(.*)/\1/g' | sed 's/"//g')"
VERSION_ID="$(sed -n '/^VERSION_ID=/p' /etc/os-release | sed -r 's/VERSION_ID=(.*)/\1/g' | sed 's/"//g')"
fi
SYSTEM="$(echo "${DIST}${VERSION_ID}" | sed -r 's/([a-zA-Z]*)-.*/\1/g')"
fi
ARCH="$(uname -m)" ARCH="$(uname -m)"
case "$ARCH" in case "$ARCH" in
@ -46,8 +35,8 @@ export ARCH
## Support RPM and Debian based linux systems ## Support RPM and Debian based linux systems
## ##
if [ "$(uname -s)" = 'Linux' ]; then if [ "$(uname -s)" = 'Linux' ]; then
case "${DIST:-}" in case "${SYSTEM:-}" in
ubuntu|debian|raspbian) ubuntu*|debian*|raspbian*)
PKGERDIR='deb' PKGERDIR='deb'
;; ;;
*) *)

View File

@ -1 +1 @@
{{built_on_arch}} {{built_on_platform}}

View File

@ -173,11 +173,24 @@ relx(Vsn, RelType, PkgType) ->
, {vm_args,false} , {vm_args,false}
, {release, {emqx, Vsn}, relx_apps(RelType)} , {release, {emqx, Vsn}, relx_apps(RelType)}
, {overlay, relx_overlay(RelType)} , {overlay, relx_overlay(RelType)}
, {overlay_vars, [ {built_on_arch, rebar_utils:get_arch()} , {overlay_vars, [ {built_on_platform, built_on()}
, {emqx_description, emqx_description(RelType, IsEnterprise)} , {emqx_description, emqx_description(RelType, IsEnterprise)}
| overlay_vars(RelType, PkgType, IsEnterprise)]} | overlay_vars(RelType, PkgType, IsEnterprise)]}
]. ].
built_on() ->
On = rebar_utils:get_arch(),
case distro() of
false -> On;
Distro -> On ++ "-" ++ Distro
end.
distro() ->
case os:type() of
{unix, _} -> string:strip(os:cmd("scripts/get-distro.sh"), both, $\n);
_ -> false
end.
emqx_description(cloud, true) -> "EMQ X Enterprise"; emqx_description(cloud, true) -> "EMQ X Enterprise";
emqx_description(cloud, false) -> "EMQ X Broker"; emqx_description(cloud, false) -> "EMQ X Broker";
emqx_description(edge, _) -> "EMQ X Edge". emqx_description(edge, _) -> "EMQ X Edge".

19
scripts/get-distro.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
## This script prints Linux distro name and its version number
## e.g. macos, centos8, ubuntu20.04
set -euo pipefail
if [ "$(uname -s)" = 'Darwin' ]; then
echo 'macos'
elif [ "$(uname -s)" = 'Linux' ]; then
if grep -q -i 'centos' /etc/*-release; then
DIST='centos'
VERSION_ID="$(rpm --eval '%{centos_ver}')"
else
DIST="$(sed -n '/^ID=/p' /etc/os-release | sed -r 's/ID=(.*)/\1/g' | sed 's/"//g')"
VERSION_ID="$(sed -n '/^VERSION_ID=/p' /etc/os-release | sed -r 's/VERSION_ID=(.*)/\1/g' | sed 's/"//g')"
fi
echo "${DIST}${VERSION_ID}" | sed -r 's/([a-zA-Z]*)-.*/\1/g'
fi