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

Improve OS version detection in nvm debug #1746

Merged

Conversation

PeterDaveHello
Copy link
Collaborator

nvm debug result in #1744 didn't detect the os version properly, this PR could solve it.

nvm.sh Outdated
@@ -2405,8 +2406,17 @@ nvm() {
nvm_err "uname -a: '$(uname -a | awk '{$2=""; print}' | xargs)'"
if [ "$(nvm_get_os)" = "darwin" ] && nvm_has sw_vers; then
nvm_err "OS version: $(sw_vers | command awk '{print $2}' | command xargs)"
elif [ -r "/etc/issue" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

this seems like it could stay an elif, and the other logic added in an else?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nope, as we need to confirm the content of it first

nvm.sh Outdated
if [ -r "/etc/issue" ]; then
nvm_err "OS version: $(command head -n 1 /etc/issue | command sed 's/\\.//g')"
fi
if [ -r "/etc/os-release" ] && [ "${OS_VERSION}" = "" ] ; then
Copy link
Member

Choose a reason for hiding this comment

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

[ -z "${OS_VERSION-}" ]?

nvm.sh Outdated
# shellcheck disable=SC1091
OS_VERSION="$(. /etc/os-release && echo "${NAME}" "${VERSION}")"
fi
if [ "${OS_VERSION}" != "" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

[ -n "${OS_VERSION-}" ]

nvm.sh Outdated
fi
if [ -r "/etc/os-release" ] && [ "${OS_VERSION}" = "" ] ; then
# shellcheck disable=SC1091
OS_VERSION="$(. /etc/os-release && echo "${NAME}" "${VERSION}")"
Copy link
Member

Choose a reason for hiding this comment

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

it seems risky to be sourcing a random file; is this necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is it random? I don't think so. It's a built-in of most of the modern Linux distros, and it has clearly definition: https://www.freedesktop.org/software/systemd/man/os-release.html

@PeterDaveHello PeterDaveHello force-pushed the improve-nvm-debug-os-version-info branch from 13e710e to 9e334a9 Compare February 25, 2018 08:40
nvm.sh Outdated
elif [ -r "/etc/issue" ]; then
nvm_err "OS version: $(command head -n 1 /etc/issue | command sed 's/\\.//g')"
else
if [ -r "/etc/issue" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

what i mean is, instead of putting three "if"s in this "else", it could be an "elif" for /etc/issue, and then an else for the final two "if"s.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

what if /etc/issue doesn't exist?

Copy link
Member

Choose a reason for hiding this comment

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

then wouldn't -r return false, and the condition be skipped?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry that I asked a wrong question.

I wanna say if "/etc/issue" exists, but the content may be empty in some cases, so I put it with the next detection in the same level code block, we can test both of the conditions, otherwise, the existing but empty /etc/issue will cause the next condition and code block not be running.

Will this make sense to you?

Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure if I do explain well, I need the conditions below this one also be tested, even if this condition is true.

nvm.sh Outdated
if [ -r "/etc/issue" ]; then
nvm_err "OS version: $(command head -n 1 /etc/issue | command sed 's/\\.//g')"
fi
if [ -r "/etc/os-release" ] && [ -z "${OS_VERSION}" ] ; then
Copy link
Member

Choose a reason for hiding this comment

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

When would OS_VERSION be set prior to this line?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

should be in the previous condition, will update it in the next push

nvm.sh Outdated
nvm_err "OS version: $(command head -n 1 /etc/issue | command sed 's/\\.//g')"
else
if [ -r "/etc/issue" ]; then
nvm_err "OS version: $(command head -n 1 /etc/issue | command sed 's/\\.//g')"
Copy link
Member

Choose a reason for hiding this comment

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

is perhaps this line meant to set OS_VERSION instead of logging it with nvm_err?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, that's what I want to do

@PeterDaveHello PeterDaveHello force-pushed the improve-nvm-debug-os-version-info branch from 9e334a9 to 28f8870 Compare February 26, 2018 05:58
@PeterDaveHello PeterDaveHello force-pushed the improve-nvm-debug-os-version-info branch from 28f8870 to d3206f6 Compare April 12, 2018 10:16
@ljharb ljharb force-pushed the improve-nvm-debug-os-version-info branch from d3206f6 to ca66a13 Compare April 15, 2018 04:32
@ljharb ljharb merged commit ca66a13 into nvm-sh:master Apr 15, 2018
@PeterDaveHello PeterDaveHello deleted the improve-nvm-debug-os-version-info branch April 15, 2018 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants