1
- #! /usr/ bin/env bash
1
+ #! /bin/sh
2
2
3
3
# getNonPortableDistroRid
4
4
#
11
11
# non-portable rid
12
12
getNonPortableDistroRid ()
13
13
{
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=" "
18
18
19
19
if [ " $targetOs " = " linux" ]; then
20
+ # shellcheck disable=SC1091
20
21
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
26
25
fi
27
26
28
- if [[ " ${VERSION_ID:- } " =~ ^([[:digit:]]| \. )+$ ]] ; then
27
+ if echo " ${VERSION_ID:- } " | grep -qE ' ^([[:digit:]]|\.)+$' ; then
29
28
nonPortableRid=" ${ID} .${VERSION_ID} -${targetArch} "
30
29
else
31
30
# Rolling release distros either do not set VERSION_ID, set it as blank or
32
31
# set it to non-version looking string (such as TEMPLATE_VERSION_ID on ArchLinux);
33
32
# so omit it here to be consistent with everything else.
34
33
nonPortableRid=" ${ID} -${targetArch} "
35
34
fi
36
-
37
35
elif [ -e " ${rootfsDir} /android_platform" ]; then
38
- source " $rootfsDir " /android_platform
36
+ # shellcheck disable=SC1091
37
+ . " ${rootfsDir} /android_platform"
39
38
nonPortableRid=" $RID "
40
39
fi
41
40
fi
42
41
43
42
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 )
46
45
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
48
47
__android_sdk_version=$( getprop ro.build.version.sdk)
49
48
nonPortableRid=" android.$__android_sdk_version -${targetArch} "
50
49
elif [ " $targetOs " = " illumos" ]; then
51
50
__uname_version=$( uname -v)
52
51
case " $__uname_version " in
53
52
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
+ ;;
57
56
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
+ ;;
64
63
esac
65
64
elif [ " $targetOs " = " solaris" ]; then
66
65
__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} "
69
68
elif [ " $targetOs " = " haiku" ]; then
70
- __uname_release=$( uname -r)
69
+ __uname_release=" $( uname -r) "
71
70
nonPortableRid=haiku.r" $__uname_release " -" $targetArch "
72
71
fi
73
72
74
- echo " $( echo $ nonPortableRid | tr ' [:upper:]' ' [:lower:]' ) "
73
+ echo " $nonPortableRid " | tr ' [:upper:]' ' [:lower:]'
75
74
}
76
75
77
76
# initDistroRidGlobal
@@ -85,26 +84,23 @@ getNonPortableDistroRid()
85
84
# None
86
85
#
87
86
# 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.
95
91
initDistroRidGlobal ()
96
92
{
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
101
97
rootfsDir=" $3 "
102
98
fi
103
99
104
100
if [ -n " ${rootfsDir} " ]; then
105
101
# We may have a cross build. Check for the existence of the rootfsDir
106
102
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."
108
104
exit 1
109
105
fi
110
106
fi
@@ -119,7 +115,7 @@ initDistroRidGlobal()
119
115
STRINGS=" $( command -v llvm-strings || true) "
120
116
fi
121
117
122
- # Check for musl-based distros (e.g Alpine Linux, Void Linux).
118
+ # Check for musl-based distros (e.g. Alpine Linux, Void Linux).
123
119
if " ${rootfsDir} /usr/bin/ldd" --version 2>&1 | grep -q musl ||
124
120
( [ -n " $STRINGS " ] && " $STRINGS " " ${rootfsDir} /usr/bin/ldd" 2>&1 | grep -q musl ); then
125
121
__PortableTargetOS=" linux-musl"
0 commit comments