1- #! /usr/ bin/env bash
1+ #! /bin/sh
22
33# getNonPortableDistroRid
44#
1111# non-portable rid
1212getNonPortableDistroRid ()
1313{
14- local targetOs=" $1 "
15- local targetArch=" $2 "
16- local rootfsDir=" $3 "
17- local nonPortableRid=" "
14+ targetOs=" $1 "
15+ targetArch=" $2 "
16+ rootfsDir=" $3 "
17+ nonPortableRid=" "
1818
1919 if [ " $targetOs " = " linux" ]; then
20+ # shellcheck disable=SC1091
2021 if [ -e " ${rootfsDir} /etc/os-release" ]; then
21- source " ${rootfsDir} /etc/os-release"
22-
23- if [[ " ${ID} " == " rhel" || " ${ID} " == " rocky" || " ${ID} " == " alpine" ]]; then
24- # remove the last version digit
25- VERSION_ID=" ${VERSION_ID% .* } "
22+ . " ${rootfsDir} /etc/os-release"
23+ if [ " ${ID} " = " rhel" ] || [ " ${ID} " = " rocky" ] || [ " ${ID} " = " alpine" ]; then
24+ VERSION_ID=" ${VERSION_ID% .* } " # Remove the last version digit for these distros
2625 fi
2726
28- if [[ " ${VERSION_ID:- } " =~ ^([[:digit:]]| \. )+$ ]] ; then
27+ if echo " ${VERSION_ID:- } " | grep -qE ' ^([[:digit:]]|\.)+$' ; then
2928 nonPortableRid=" ${ID} .${VERSION_ID} -${targetArch} "
3029 else
3130 # Rolling release distros either do not set VERSION_ID, set it as blank or
3231 # set it to non-version looking string (such as TEMPLATE_VERSION_ID on ArchLinux);
3332 # so omit it here to be consistent with everything else.
3433 nonPortableRid=" ${ID} -${targetArch} "
3534 fi
36-
3735 elif [ -e " ${rootfsDir} /android_platform" ]; then
38- source " $rootfsDir " /android_platform
36+ # shellcheck disable=SC1091
37+ . " ${rootfsDir} /android_platform"
3938 nonPortableRid=" $RID "
4039 fi
4140 fi
4241
4342 if [ " $targetOs " = " freebsd" ]; then
44- # $rootfsDir can be empty. freebsd-version is shell script and it should always work.
45- __freebsd_major_version=$( $rootfsDir /bin/freebsd-version | { read v ; echo " ${v %% . * } " ; } )
43+ # $rootfsDir can be empty. freebsd-version is a shell script and should always work.
44+ __freebsd_major_version=$( " $rootfsDir " /bin/freebsd-version | cut -d ' . ' -f1 )
4645 nonPortableRid=" freebsd.$__freebsd_major_version -${targetArch} "
47- elif command -v getprop && getprop ro.product.system.model 2>&1 | grep -qi android; then
46+ elif command -v getprop > /dev/null && getprop ro.product.system.model | grep -qi android; then
4847 __android_sdk_version=$( getprop ro.build.version.sdk)
4948 nonPortableRid=" android.$__android_sdk_version -${targetArch} "
5049 elif [ " $targetOs " = " illumos" ]; then
5150 __uname_version=$( uname -v)
5251 case " $__uname_version " in
5352 omnios-* )
54- __omnios_major_version=$( echo " ${ __uname_version: 8 : 2} " )
55- nonPortableRid=omnios." $__omnios_major_version " - " $ targetArch"
56- ;;
53+ __omnios_major_version=$( echo " $__uname_version " | cut -c9-10 )
54+ nonPortableRid=" omnios.$__omnios_major_version - ${ targetArch} "
55+ ;;
5756 joyent_* )
58- __smartos_major_version=$( echo " ${ __uname_version: 7 : 4} " )
59- nonPortableRid=smartos." $__smartos_major_version " - " $ targetArch"
60- ;;
61- illumos_ * )
62- nonPortableRid=openindiana- " $ targetArch"
63- ;;
57+ __smartos_major_version=$( echo " $__uname_version " | cut -c9-10 )
58+ nonPortableRid=" smartos.$__smartos_major_version - ${ targetArch} "
59+ ;;
60+ * )
61+ nonPortableRid=" illumos- ${ targetArch} "
62+ ;;
6463 esac
6564 elif [ " $targetOs " = " solaris" ]; then
6665 __uname_version=$( uname -v)
67- __solaris_major_version=$( echo " ${ __uname_version% . * } " )
68- nonPortableRid=solaris." $__solaris_major_version " - " $ targetArch"
66+ __solaris_major_version=$( echo " $__uname_version " | cut -d ' . ' -f1 )
67+ nonPortableRid=" solaris.$__solaris_major_version - ${ targetArch} "
6968 elif [ " $targetOs " = " haiku" ]; then
70- __uname_release=$( uname -r)
69+ __uname_release=" $( uname -r) "
7170 nonPortableRid=haiku.r" $__uname_release " -" $targetArch "
7271 fi
7372
74- echo " $( echo $ nonPortableRid | tr ' [:upper:]' ' [:lower:]' ) "
73+ echo " $nonPortableRid " | tr ' [:upper:]' ' [:lower:]'
7574}
7675
7776# initDistroRidGlobal
@@ -85,26 +84,23 @@ getNonPortableDistroRid()
8584# None
8685#
8786# Notes:
88- #
89- # It is important to note that the function does not return anything, but it
90- # exports the following variables on success:
91- #
92- # __DistroRid : Non-portable rid of the target platform.
93- # __PortableTargetOS : OS-part of the portable rid that corresponds to the target platform.
94- #
87+ # It is important to note that the function does not return anything, but it
88+ # exports the following variables on success:
89+ # __DistroRid : Non-portable rid of the target platform.
90+ # __PortableTargetOS : OS-part of the portable rid that corresponds to the target platform.
9591initDistroRidGlobal ()
9692{
97- local targetOs=" $1 "
98- local targetArch=" $2 "
99- local rootfsDir=" "
100- if [ " $# " -ge 3 ]; then
93+ targetOs=" $1 "
94+ targetArch=" $2 "
95+ rootfsDir=" "
96+ if [ $# -ge 3 ]; then
10197 rootfsDir=" $3 "
10298 fi
10399
104100 if [ -n " ${rootfsDir} " ]; then
105101 # We may have a cross build. Check for the existence of the rootfsDir
106102 if [ ! -e " ${rootfsDir} " ]; then
107- echo " Error rootfsDir has been passed, but the location is not valid."
103+ echo " Error: rootfsDir has been passed, but the location is not valid."
108104 exit 1
109105 fi
110106 fi
@@ -119,7 +115,7 @@ initDistroRidGlobal()
119115 STRINGS=" $( command -v llvm-strings || true) "
120116 fi
121117
122- # Check for musl-based distros (e.g Alpine Linux, Void Linux).
118+ # Check for musl-based distros (e.g. Alpine Linux, Void Linux).
123119 if " ${rootfsDir} /usr/bin/ldd" --version 2>&1 | grep -q musl ||
124120 ( [ -n " $STRINGS " ] && " $STRINGS " " ${rootfsDir} /usr/bin/ldd" 2>&1 | grep -q musl ); then
125121 __PortableTargetOS=" linux-musl"
0 commit comments