Skip to content
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

Update os.sh #28

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions modules/bash-commons/src/os.sh
Expand Up @@ -36,6 +36,10 @@ function os_is_redhat {
grep -q "Red Hat Enterprise Linux Server release $version" /etc/*release
}

# Returns true (0) if this is a WSL kernel or false (1) otherwise.
function os_is_wsl_kernel {
[[ $(uname -r | tail -c19) == "microsoft-standard" ]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How stable / reliable is looking at column 19? Could that change in a future release?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does seem brittle... Maybe use grep instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bash supports regex, no need to grep, /etc/os-release would be Ubuntu/Redhat etc, whatever WSL2 container the user has loaded. It's a config string in their build, https://github.com/microsoft/WSL2-Linux-Kernel/blob/master/Microsoft/config-wsl#L22

I used tail instead of head so the version number length is variable.

}

# Returns true (0) if this is an OS X server or false (1) otherwise.
function os_is_darwin {
Expand Down