Skip to content

cmd/version: print os/version, kernel and bitness - #5204

Merged
ivandeex merged 2 commits into
rclone:masterfrom
ivandeex:pr-osversion
Apr 5, 2021
Merged

ivandeex merged 2 commits into
rclone:masterfrom
ivandeex:pr-osversion

Conversation

@ivandeex

@ivandeex ivandeex commented Apr 3, 2021 •

Copy link
Copy Markdown
Member

What is the purpose of this change?

Make rclone version print runtime OS version, kernel and architecture bitness.

The implementation is based on https://github.com/shirou/gopsutil (namely gopsutil/host)

The detection on OpenBSD is limited to OS name because base package fails to build on it.

Was the change discussed in an issue or in the forum before?

Related to #5121 (comment)

References:

Checklist

  • I have read the contribution guidelines.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • I'm done, this Pull Request is ready for review :-)

Testing

Instead of writing a unit test which is rather useless in this case, I will publish
beta releases for linux/windows tagged with v1.55.0-osversionNN.
See https://github.com/ivandeex/rclone/releases
Beta testers can download a beta and decide whether rclone version output feels correct or not.

@ivandeex

ivandeex commented Apr 3, 2021 •

Copy link
Copy Markdown
Member Author

v1.55.0-osversion01 prints for me

on Linux:

- os/version: ubuntu 18.04 (64 bit)
- os/kernel: 4.15.0-136-generic (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.13.4
...

on Windows:

- os/version: Microsoft Windows 8.1 Pro 6.3.9600 Build 9600 (64 bit)
- os/kernel: 6.3.9600 Build 9600 (x86_64)
- os/type: windows
- os/arch: amd64
- go/version: go1.13.4
- go/linking: dynamic
- go/tags: cmount

@ncw @albertony @darthShadow
Your comments are welcome

@albertony

Copy link
Copy Markdown
Contributor

Great, useful with all those details!
A bit long os/version string on Windows, and some overlap with the os/kernel string, but i suppose thats the way the third party lib returns it? Better too much than too little, anyway..

@ivandeex

ivandeex commented Apr 3, 2021

Copy link
Copy Markdown
Member Author

osversion02
Linux: same
Windows:

- os/version: Microsoft Windows 8.1 Pro (64 bit)
- os/kernel: 6.3.9600 Build 9600 (x86_64)
- os/type: windows
- os/arch: amd64
- go/version: go1.13.4
- go/linking: dynamic
- go/tags: cmount

@albertony

Copy link
Copy Markdown
Contributor

Win10 computer:

rclone v1.55.0-osversion02
- os/version: Microsoft Windows 10 Enterprise (64 bit)
- os/kernel: 10.0.18363 Build 18363 (x86_64)
- os/type: windows
- os/arch: amd64
- go/version: go1.13.4
- go/linking: dynamic
- go/tags: cmount

Arch in WSL:

rclone v1.55.0-osversion02
- os/version: arch (64 bit)
- os/kernel: 5.4.72-microsoft-standard-WSL2 (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.13.4
- go/linking: dynamic
- go/tags: cmount

Looks much better! Ship it! :)

PS:

Wonder why the version "name" is not included, though.. I mean like "1909", "2004", "20H2" etc.. Thats the names that are usually used to describe minimum requirements etc. I don't have the build numbers in my head, so usually have to look them up in wikipedia.

Also the version number in os/kernel includes the build number twice and does not include the patch version: "10.0.18363 Build 18363"..

From About section in settings panel:

image

From winver:

image

Nothing of this is important, though, I'm just wondering.. May have to have a look into what the gopsutil does some day, if nothing else just to satisfy my curiosity.

@ivandeex
ivandeex requested a review from ncw April 3, 2021 18:28
@ivandeex

ivandeex commented Apr 3, 2021

Copy link
Copy Markdown
Member Author

v1.55.0-osversion03:

Windows 8:

- os/version: Microsoft Windows 8.1 Pro (64 bit)
- os/kernel: 6.3.9600 (x86_64)
- os/type: windows
- os/arch: amd64
- go/version: go1.13.4
- go/linking: dynamic
- go/tags: cmount

Linux - the same:

rclone v1.55.0-osversion03
- os/version: ubuntu 18.04 (64 bit)
- os/kernel: 4.15.0-136-generic (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.13.4
- go/linking: dynamic
- go/tags: cmount

Wonder why the version "name" is not included, though.. I mean like "1909", "2004", "20H2" etc..

Also for linux I would expect os/version: ubuntu 18.04 (bionic). I think it's a limitation of gopsutil, though it's not critical.

what the gopsutil does

I guess on Windows it potters around registry, on Linux - in /etc/xxx_release and uname -a

@albertony

Copy link
Copy Markdown
Contributor

Quick retest: Windows 10 output is similar to your Windows 8 output, WSL identical to before:

rclone v1.55.0-osversion03
- os/version: Microsoft Windows 10 Enterprise (64 bit)
- os/kernel: 10.0.18363 (x86_64)
- os/type: windows
- os/arch: amd64
- go/version: go1.13.4
- go/linking: dynamic
- go/tags: cmount

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is looking great!

I put an idea for OpenBSD inline


// GetOSVersion returns OS version, kernel and bitness
func GetOSVersion() (osVersion, osKernel string) {
return "OpenBSD", ""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You could call syscall.Uname here and return some things out of there.

This should work on OpenBSD I think...

@ivandeex ivandeex Apr 4, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

  1. The catch is how to test it. I don't have openbsd within reach. We will have to wait for a beta volunteer.
  2. The main idea was to delegate testing to external package
  3. uname can usually return kernel and arch but not a logical OS version

@ivandeex ivandeex Apr 4, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We can try with virtualbox and https://app.vagrantup.com/generic/boxes/openbsd6 but there is no strict guarantee that resulting code won't panic with other actual flavors of OpenBSD.

@ivandeex ivandeex Apr 4, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think I can open an upstream issue asking to make gopsutil work on OpenBSD. This OS is not primary for rclone. We can wait.

@ivandeex ivandeex Apr 4, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

They already have PR shirou/gopsutil#965. I'm subscribed on it. We can either put this one on hold waiting for upstream or postpone dependency upgrade to a later PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

What do you think @ncw ?

@ncw ncw Apr 5, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That sounds fine - it is a minority platform (sorry OpenBSD users) so happy to wait until that PR is merged.

@ivandeex ivandeex Apr 5, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

OK. Will submit another PR when shirou/gopsutil#965 ticks for me.

@ivandeex

ivandeex commented Apr 4, 2021 •

Copy link
Copy Markdown
Member Author

It would be interesting to look at MacOS output.
MacOS is the 3rd important rclone OS after Linux and Windows.
Let me setup a temporary github job on the fork.

@albertony

Copy link
Copy Markdown
Contributor

The Windows 10 "version friendly-name" is easy enough to find from registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion, value ReleaseId. On Windows 8 it does not exist, though (ref). Patch number is also there as registry value UBR (Update Build Revision), not sure if that is Windows 10 specific also.

So instead of:

- os/version: Microsoft Windows 10 Enterprise (64 bit)
- os/kernel: 10.0.18363 (x86_64)

We could have gotten something like:

- os/version: Microsoft Windows 10 Enterprise 1909 (64 bit)
- os/kernel: 10.0.18363.1440 (x86_64)

But then this requires Windows-specific registry access (if only a few lines), which I know you are not overly exited about 😉, and for me also would just be "nice to have" at this point, so I'm fine with it as is.

Regarding:

Also the version number in os/kernel includes the build number twice and does not include the patch version: "10.0.18363 Build 18363"..

Just checked the gopsutil src, and it is definitely returning the same dwBuildNumber value twice:

version = fmt.Sprintf("%d.%d.%d Build %d", osInfo.dwMajorVersion, osInfo.dwMinorVersion, osInfo.dwBuildNumber, osInfo.dwBuildNumber)

So your fix should be safe, and always find match:

// Simplify kernel output: `RELEASE.BUILD Build BUILD` -> `RELEASE.BUILD`
match := regexp.MustCompile(`^([\d\.]+?\.)(\d+) Build (\d+)$`).FindStringSubmatch(osKernel)
if len(match) == 4 && match[2] == match[3] {

@ivandeex

ivandeex commented Apr 5, 2021 •

Copy link
Copy Markdown
Member Author

v1.55.0-osversion04 includes ReleaseId and Update Revision (UBR)

my build box (go/version is ancient because I build with xgo):

rclone v1.55.0-osversion04
- os/version: ubuntu 18.04 (64 bit)
- os/kernel: 4.15.0-136-generic (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.13.4
- go/linking: dynamic
- go/tags: cmount

my desktop (includes update revision 18543 now):

rclone v1.55.0-osversion04
- os/version: Microsoft Windows 8.1 Pro (64 bit)
- os/kernel: 6.3.9600.18543 (x86_64)
- os/type: windows
- os/arch: amd64
- go/version: go1.13.4
- go/linking: dynamic
- go/tags: cmount

github runners (https://github.com/ivandeex/rclone/actions/runs/718936549):

ubuntu-latest:

rclone v1.55.0-osversion04
- os/version: ubuntu 20.04 (64 bit)
- os/kernel: 5.4.0-1043-azure (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.16.2
- go/linking: dynamic
- go/tags: cmount

windows_amd64 (confirmed having friendly name 1809 and update revision 1817):

rclone v1.55.0-osversion04
- os/version: Microsoft Windows Server 2019 Datacenter 1809 (64 bit)
- os/kernel: 10.0.17763.1817 (x86_64)
- os/type: windows
- os/arch: amd64
- go/version: go1.16.2
- go/linking: dynamic
- go/tags: cmount

windows_i386 (notice that os/arch and os/kernel arch differ, it's allright)

rclone v1.55.0-osversion04
- os/version: Microsoft Windows Server 2019 Datacenter 1809 (64 bit)
- os/kernel: 10.0.17763.1817 (x86_64)
- os/type: windows
- os/arch: 386
- go/version: go1.16.2
- go/linking: dynamic
- go/tags: cmount

EDIT: corrected copy-paste error

mac_amd64 (macos-latest)

rclone v1.55.0-osversion04
- os/version: darwin 10.15.7 (64 bit)
- os/kernel: 19.6.0 (x86_64)
- os/type: darwin
- os/arch: amd64
- go/version: go1.16.2
- go/linking: dynamic
- go/tags: cmount

mac_ARM64
(runner OS is still macos-latest on x86_64, but go arch amd64 is rather unexpected for me)
github setup job shows: Mac OS X 10.15.7 19H524 (our output below doesn't have friendly name 19H524, but has 19.6 instead)
BUILD_FLAGS: -include "^darwin/arm64" -cgo -macos-arch arm64 -macos-sdk macosx11.1 ...)

rclone v1.55.0-osversion04
- os/version: darwin 10.15.7 (64 bit)
- os/kernel: 19.6.0 (x86_64)
- os/type: darwin
- os/arch: amd64
- go/version: go1.16.2
- go/linking: dynamic
- go/tags: cmount

@albertony

albertony commented Apr 5, 2021 •

Copy link
Copy Markdown
Contributor

We could have gotten something like:

- os/version: Microsoft Windows 10 Enterprise 1909 (64 bit)
- os/kernel: 10.0.18363.1440 (x86_64)

What an easter miracle - now we do:

rclone v1.55.0-osversion04
- os/version: Microsoft Windows 10 Enterprise 1909 (64 bit)
- os/kernel: 10.0.18363.1440 (x86_64)
- os/type: windows
- os/arch: amd64
- go/version: go1.13.4
- go/linking: dynamic
- go/tags: cmount

WSL as before:

rclone v1.55.0-osversion04
- os/version: arch (64 bit)
- os/kernel: 5.4.72-microsoft-standard-WSL2 (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.13.4
- go/linking: dynamic
- go/tags: cmount

PS: Is your "windows_i386" example copy/paste error? Identical to your "windows_amd64" example..
Update: I think so.. Checked the logs and it says:

rclone v1.55.0-osversion04
- os/version: Microsoft Windows Server 2019 Datacenter 1809 (64 bit)
- os/kernel: 10.0.17763.1817 (x86_64)
- os/type: windows
- os/arch: 386
- go/version: go1.16.2
- go/linking: dynamic
- go/tags: cmount

Difference is the - os/arch: 386, where in your "copy" - os/arch: amd64.
Why is it "64 bit" and "x86_64" but "os/arch: 386" though?

@ivandeex

ivandeex commented Apr 5, 2021 •

Copy link
Copy Markdown
Member Author

PS: Is your "windows_i386" example copy/paste error? Identical to your "windows_amd64" example..

Yes, it was copy/paste error. The original was here https://github.com/ivandeex/rclone/runs/2269099401?check_suite_focus=true

Why is it "64 bit" and "x86_64" but "os/arch: 386" though?

Because os/arch shows GOARCH, a build setting (it's actually go/arch).
64 bit and x86_64 are taken from runtime, controlled by github workflow file https://github.com/ivandeex/rclone/actions/runs/718936549/workflow
Compare with https://github.com/rclone/rclone/blob/master/.github/workflows/build.yml#L51
It uses windows-latest runner (which is 64 bit) both for windows_amd64 and windows_386 builds.
Windows x86_64 can emulate 386 transparently for a 386 binary so it runs successfully.

P.S. os/type in fact shows GOOS, a build setting.

@ivandeex
ivandeex requested a review from ncw April 5, 2021 14:11

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM :-)

@ivandeex

ivandeex commented Apr 5, 2021

Copy link
Copy Markdown
Member Author

cmd/version: print os/version, kernel and bitness (#5204)

Related to #5121

Note: OpenBSD is a stub yet. This will be fixed when upstream PR gets resolved:
shirou/gopsutil#993

@ivandeex
ivandeex merged commit 3859fe2 into rclone:master Apr 5, 2021
@ivandeex
ivandeex deleted the pr-osversion branch April 5, 2021 18:53
@ivandeex ivandeex mentioned this pull request Jun 11, 2021
2 of 5 tasks
@ivandeex ivandeex added the UX label Oct 25, 2021
lafkpages pushed a commit to lafkpages/rclone that referenced this pull request Jul 20, 2026
Related to rclone#5121

Note: OpenBSD is stub yet. This will be fixed after upstream PR gets resolved
shirou/gopsutil#993
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants