-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove bash dep from init scripts #98781
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env bash | ||
#!/bin/sh | ||
|
||
# getNonPortableDistroRid | ||
# | ||
|
@@ -11,67 +11,66 @@ | |
# non-portable rid | ||
getNonPortableDistroRid() | ||
{ | ||
local targetOs="$1" | ||
local targetArch="$2" | ||
local rootfsDir="$3" | ||
local nonPortableRid="" | ||
targetOs="$1" | ||
targetArch="$2" | ||
rootfsDir="$3" | ||
nonPortableRid="" | ||
|
||
if [ "$targetOs" = "linux" ]; then | ||
# shellcheck disable=SC1091 | ||
if [ -e "${rootfsDir}/etc/os-release" ]; then | ||
source "${rootfsDir}/etc/os-release" | ||
|
||
if [[ "${ID}" == "rhel" || "${ID}" == "rocky" || "${ID}" == "alpine" ]]; then | ||
# remove the last version digit | ||
VERSION_ID="${VERSION_ID%.*}" | ||
. "${rootfsDir}/etc/os-release" | ||
if [ "${ID}" = "rhel" ] || [ "${ID}" = "rocky" ] || [ "${ID}" = "alpine" ]; then | ||
VERSION_ID="${VERSION_ID%.*}" # Remove the last version digit for these distros | ||
fi | ||
|
||
if [[ "${VERSION_ID:-}" =~ ^([[:digit:]]|\.)+$ ]]; then | ||
if echo "${VERSION_ID:-}" | grep -qE '^([[:digit:]]|\.)+$'; then | ||
nonPortableRid="${ID}.${VERSION_ID}-${targetArch}" | ||
else | ||
# Rolling release distros either do not set VERSION_ID, set it as blank or | ||
# set it to non-version looking string (such as TEMPLATE_VERSION_ID on ArchLinux); | ||
# so omit it here to be consistent with everything else. | ||
nonPortableRid="${ID}-${targetArch}" | ||
fi | ||
|
||
elif [ -e "${rootfsDir}/android_platform" ]; then | ||
source "$rootfsDir"/android_platform | ||
# shellcheck disable=SC1091 | ||
. "${rootfsDir}/android_platform" | ||
nonPortableRid="$RID" | ||
fi | ||
fi | ||
|
||
if [ "$targetOs" = "freebsd" ]; then | ||
# $rootfsDir can be empty. freebsd-version is shell script and it should always work. | ||
__freebsd_major_version=$($rootfsDir/bin/freebsd-version | { read v; echo "${v%%.*}"; }) | ||
# $rootfsDir can be empty. freebsd-version is a shell script and should always work. | ||
__freebsd_major_version=$("$rootfsDir"/bin/freebsd-version | cut -d'.' -f1) | ||
nonPortableRid="freebsd.$__freebsd_major_version-${targetArch}" | ||
elif command -v getprop && getprop ro.product.system.model 2>&1 | grep -qi android; then | ||
elif command -v getprop >/dev/null && getprop ro.product.system.model | grep -qi android; then | ||
__android_sdk_version=$(getprop ro.build.version.sdk) | ||
nonPortableRid="android.$__android_sdk_version-${targetArch}" | ||
elif [ "$targetOs" = "illumos" ]; then | ||
__uname_version=$(uname -v) | ||
case "$__uname_version" in | ||
omnios-*) | ||
__omnios_major_version=$(echo "${__uname_version:8:2}") | ||
nonPortableRid=omnios."$__omnios_major_version"-"$targetArch" | ||
;; | ||
__omnios_major_version=$(echo "$__uname_version" | cut -c9-10) | ||
nonPortableRid="omnios.$__omnios_major_version-${targetArch}" | ||
;; | ||
joyent_*) | ||
__smartos_major_version=$(echo "${__uname_version:7:4}") | ||
nonPortableRid=smartos."$__smartos_major_version"-"$targetArch" | ||
;; | ||
illumos_*) | ||
nonPortableRid=openindiana-"$targetArch" | ||
;; | ||
__smartos_major_version=$(echo "$__uname_version" | cut -c9-10) | ||
nonPortableRid="smartos.$__smartos_major_version-${targetArch}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a typo? Or is the range also 9-10? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bash syntax was 'skip 8 chars and select next two', new syntax is 'cut/select characters 9 and 10'. |
||
;; | ||
*) | ||
nonPortableRid="illumos-${targetArch}" | ||
;; | ||
esac | ||
elif [ "$targetOs" = "solaris" ]; then | ||
__uname_version=$(uname -v) | ||
__solaris_major_version=$(echo "${__uname_version%.*}") | ||
nonPortableRid=solaris."$__solaris_major_version"-"$targetArch" | ||
__solaris_major_version=$(echo "$__uname_version" | cut -d'.' -f1) | ||
nonPortableRid="solaris.$__solaris_major_version-${targetArch}" | ||
elif [ "$targetOs" = "haiku" ]; then | ||
__uname_release=$(uname -r) | ||
__uname_release="$(uname -r)" | ||
nonPortableRid=haiku.r"$__uname_release"-"$targetArch" | ||
fi | ||
|
||
echo "$(echo $nonPortableRid | tr '[:upper:]' '[:lower:]')" | ||
echo "$nonPortableRid" | tr '[:upper:]' '[:lower:]' | ||
} | ||
|
||
# initDistroRidGlobal | ||
|
@@ -85,26 +84,23 @@ getNonPortableDistroRid() | |
# None | ||
# | ||
# Notes: | ||
# | ||
# It is important to note that the function does not return anything, but it | ||
# exports the following variables on success: | ||
# | ||
# __DistroRid : Non-portable rid of the target platform. | ||
# __PortableTargetOS : OS-part of the portable rid that corresponds to the target platform. | ||
# | ||
# It is important to note that the function does not return anything, but it | ||
# exports the following variables on success: | ||
# __DistroRid : Non-portable rid of the target platform. | ||
# __PortableTargetOS : OS-part of the portable rid that corresponds to the target platform. | ||
initDistroRidGlobal() | ||
{ | ||
local targetOs="$1" | ||
local targetArch="$2" | ||
local rootfsDir="" | ||
if [ "$#" -ge 3 ]; then | ||
targetOs="$1" | ||
targetArch="$2" | ||
rootfsDir="" | ||
if [ $# -ge 3 ]; then | ||
rootfsDir="$3" | ||
fi | ||
|
||
if [ -n "${rootfsDir}" ]; then | ||
# We may have a cross build. Check for the existence of the rootfsDir | ||
if [ ! -e "${rootfsDir}" ]; then | ||
echo "Error rootfsDir has been passed, but the location is not valid." | ||
echo "Error: rootfsDir has been passed, but the location is not valid." | ||
exit 1 | ||
fi | ||
fi | ||
|
@@ -119,7 +115,7 @@ initDistroRidGlobal() | |
STRINGS="$(command -v llvm-strings || true)" | ||
fi | ||
|
||
# Check for musl-based distros (e.g Alpine Linux, Void Linux). | ||
# Check for musl-based distros (e.g. Alpine Linux, Void Linux). | ||
if "${rootfsDir}/usr/bin/ldd" --version 2>&1 | grep -q musl || | ||
( [ -n "$STRINGS" ] && "$STRINGS" "${rootfsDir}/usr/bin/ldd" 2>&1 | grep -q musl ); then | ||
__PortableTargetOS="linux-musl" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We stopped using it this trimming type of expansion for __solaris_major_version but not here. Is there difference in shell supports?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ChatGPT thinks this is the way to go, and shellcheck doesn't complain.

Bourne Shell:
But good eye! I'll make it consistent later today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ChatGPT's reply:
so advanced ops like substring extraction
${string:position:length}
are bash-specific. So I think we can safely use that parameter expansion syntax for now.