pax_global_header00006660000000000000000000000064151563064330014520gustar00rootroot0000000000000052 comment=60e7a355fa51e62376846b74ab53883c2b06568b djberg96-sys-uname-60e7a35/000077500000000000000000000000001515630643300154075ustar00rootroot00000000000000djberg96-sys-uname-60e7a35/.github/000077500000000000000000000000001515630643300167475ustar00rootroot00000000000000djberg96-sys-uname-60e7a35/.github/FUNDING.yml000066400000000000000000000001371515630643300205650ustar00rootroot00000000000000# These are supported funding model platforms github: djberg96 open_collective: daniel-berger djberg96-sys-uname-60e7a35/.github/workflows/000077500000000000000000000000001515630643300210045ustar00rootroot00000000000000djberg96-sys-uname-60e7a35/.github/workflows/ruby.yml000066400000000000000000000022561515630643300225150ustar00rootroot00000000000000name: Ruby on: push: branches: [ main ] paths-ignore: - '**/*.md' pull_request: branches: [ main ] paths-ignore: - '**/*.md' workflow_dispatch: jobs: test: strategy: matrix: ruby-version: ['2.7', '3.0', '3.1', '3.2', '3.3', '3.4', '4.0', 'jruby', 'truffleruby'] platform: [ubuntu-latest, macos-latest, windows-latest] exclude: - ruby-version: truffleruby platform: windows-latest - ruby-version: jruby platform: windows-latest runs-on: ${{ matrix.platform }} steps: - uses: actions/checkout@v3 - name: Setup Ruby uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} bundler-cache: true - name: Run tests run: bundle exec rake freebsd: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Test in FreeBSD id: test uses: vmactions/freebsd-vm@v1 with: usesh: true prepare: | pkg install -y curl ruby devel/ruby-gems run: | gem install bundler --no-document bundle install --quiet bundle exec rspec djberg96-sys-uname-60e7a35/.gitignore000066400000000000000000000000231515630643300173720ustar00rootroot00000000000000*.lock *.swp *.gem djberg96-sys-uname-60e7a35/.rubocop.yml000066400000000000000000000024641515630643300176670ustar00rootroot00000000000000require: rubocop-rspec RSpec/MultipleExpectations: Max: 5 RSpec/ContextWording: Enabled: false RSpec/FilePath: SpecSuffixOnly: true RSpec/InstanceVariable: Enabled: false RSpec/BeforeAfterAll: Enabled: false RSpec/SpecFilePathFormat: Enabled: false AllCops: NewCops: enable Exclude: - sys-uname.gemspec - Rakefile - Gemfile - examples/*.rb Lint/AssignmentInCondition: Enabled: false Style/FetchEnvVar: Enabled: false Style/HashSyntax: Enabled: false Style/MethodCallWithoutArgsParentheses: Enabled: false Style/NumericLiterals: Enabled: false Style/NumericPredicate: Enabled: false Style/ClassAndModuleChildren: Enabled: false Style/ConditionalAssignment: Enabled: false Style/IfUnlessModifier: Enabled: false Layout/EmptyLineAfterGuardClause: Enabled: false Layout/CaseIndentation: IndentOneStep: true Layout/SpaceBeforeBlockBraces: Enabled: false Metrics/AbcSize: Enabled: false Metrics/BlockLength: AllowedMethods: ['describe', 'context'] Metrics/ClassLength: Enabled: false Metrics/MethodLength: Enabled: false Metrics/CyclomaticComplexity: Enabled: false Metrics/PerceivedComplexity: Enabled: false Naming/AccessorMethodName: Enabled: false Naming/RescuedExceptionsVariableName: PreferredName: 'err' Naming/FileName: Exclude: - 'lib/sys-uname.rb' djberg96-sys-uname-60e7a35/CHANGES.md000066400000000000000000000241111515630643300170000ustar00rootroot00000000000000## 1.5.1 - 17-Mar-2026 * Updated the gemspec for Windows. Going forward we'll have to release two versions of each gem since Windows has different dependencies. I already do this for most of my other gems, I was being lazy and hoping it wouldn't matter, but cucumber already puked on it. ## 1.5.0 - 16-Feb-2026 * The win32ole gem is now a dependency for Windows since it's no longer bundled with Ruby 4.x. ## 1.4.1 - 1-Sep-2025 * Use memoist3 instead of memoist since the latter is unmaintained. Thanks got to Matijs van Zuijlen for the suggestion. ## 1.4.0 - 26-Aug-2025 * The sysname, nodename, release, version and machine methods are now memoized. * The memoist gem has been added as a dependency. * Specs added for memoization. ## 1.3.1 - 19-Nov-2024 * Remove a useless ostruct require. Thanks go to Koichi Ito for the spot and patch. ## 1.3.0 - 10-Jun-2024 * Added DragonflyBSD support. * Removed Solaris support, it's dead. ## 1.2.3 - 9-Apr-2023 * Added rubygems_mfa_required and github_repo to metadata. * Miscellaneous rubocop related updates. * Fixed one test for Windows. * The rubocop and rubocop-rspec gems are now development dependencies. * Now assumes Ruby 2.0 or later. ## 1.2.2 - 30-Oct-2020 * Added a Gemfile. * The ffi dependency is now slightly more restrictive. * Added rake as a development dependency (which it really always was). * Switched from rdoc to markdown because github wouldn't render it properly. ## 1.2.1 - 17-Mar-2020 * Properly include a LICENSE file as per the Apache-2.0 license. ## 1.2.0 - 5-Jan-2020 * Changed test suite from test-unit to rspec, which was also added as a development dependency. * Several new fields were added to the returned object on Windows. The fields are encryption_level, product_type, suite_mask and system_drive. ## 1.1.1 - 10-Dec-2019 * Renamed various text files to include explicit .rdoc extension so that they show up more nicely on github. ## 1.1.0 - 29-Aug-2019 * Changed license to Apache-2.0. * Updated the doc/uname.txt file. * Minor test updates. ## 1.0.4 - 4-Nov-2018 * Added metadata to the gemspec. * Updated the cert, which will expire in about 10 years. ## 1.0.3 - 31-Oct-2016 * Updated the gem cert. It will expire on 31-Oct-2019. * Minor updates to the Rakefile and gemspec. ## 1.0.2 - 3-Sep-2015 * The gem is now signed. * Modified gemspec and Rakefile to support signing. ## 1.0.1 - 19-Aug-2015 * Modified Platform::IMPL so that it does not include "32" as part of the symbol name. This isn't useful since it's the same on 32 or 64-bit Windows. * Reorganized code a bit so that the VERSION constant is in a single place. * For consistency, there is also a Platform::VERSION. This is the same value as Uname::VERSION. * Added a test for Sys::Platform::IMPL on Windows. ## 1.0.0 - 19-Aug-2015 * Added a sys-uname.rb shim so that you can require this library with "sys-uname" or "sys/uname". * Added the architecture method for MS Windows. * Added a Sys::Platform class that adds several boolean methods to check your operating system. It also adds the ARCH, OS, and IMPL constants to simulate, and ultimately replace, the old "Platform" gem. * There is now just a single gem, instead of a separate gem for Windows and Unix, so you shouldn't need to worry about platform checking. ## 0.9.2 - 1-May-2013 * Added a workaround for a win32ole thread bug. Thanks go to Tianlong Wu for the spot. * Altered platform handling slightly for Windows in the Rakefile. ## 0.9.1 - 3-Jan-2013 * Made FFI functions private. * Properly alias uname FFI function. * Fixed the QuantumLength and QuantumType bug again (see 0.8.4), which I somehow accidentally reintroduced. ## 0.9.0 - 8-Dec-2011 * Conversion to FFI. * Added some additional methods and information for Solaris. * Minor tweaks for 1.9 to silence warnings. ## 0.8.6 - 2-Sep-2011 * Fixed a failing test for Ruby 1.9.x. * The gemspec for Windows is now 'universal'. * Some minor doc updates. ## 0.8.5 - 11-Dec-2010 * Removed some non-ascii characters that somehow made it into the source. * Some updates to the Rakefile, including a default task. ## 0.8.4 - 29-Jan-2010 * Bug fix for Windows 7, which appears to have removed the QuantumLength and QuantumType members of the Win32_OperatingSystem class. Thanks go to Mark Seymour for the spot. RubyForge bug # 27645. * Changed license to Artistic 2.0. * Refactored the Rakefile and gemspec considerably. The gem building code is now all inlined within the Rakefile build task itself. * Minor doc updates and some code reformatting. ## 0.8.3 - 26-Apr-2008 * Added an explicit "require 'time'" in the Windows version because recent versions of Ruby now need it. * Changed the way I do platform checks in the Rakefile. ## 0.8.2 - 22-Nov-2007 * Fixed an issue where Ruby no longer parsed a certain type of date that MS Windows uses. See RubyForge Bug #10646 for more information. ## 0.8.1 - 29-Aug-2007 * Made a minor modification to the build script for Linux. It turns out Linux has sysctl, but not the necessary mibs for the Uname.model method. Thanks go to Mickey Knox (?) for the spot. * Removed the install.rb file. The code from that program was integrated directly into the Rakefile. ## 0.8.0 - 10-Apr-2007 * The Uname.model method should now work on most BSD platforms, not just OS X, since it uses the sysctl() function behind the scenes. * The 'id' method was changed to 'id_number' on HP-UX to avoid confusion with the Object.id method. * The UnameError class is now Uname::Error. * Added a Rakefile. There are now tasks for building, testing and installing this package. * Removed some pre-setup code from the test suite that was no longer necessary as a result of the Rake test task. ## 0.7.4 - 19-Nov-2006 * Internal layout changes, doc updates and gemspec improvements. * No code changes. ## 0.7.3 - 30-Jul-2006 * Bug fix for 64 bit platforms. * Minor modification of the extconf.rb file. ## 0.7.2 - 5-Jul-2006 * Removed '?' from the struct member names on MS Windows since these are no longer legal. * Removed duplicate definition of Uname.version on MS Windows (oops). * Added a gemspec. * Added inline rdoc documentation to the source files. ## 0.7.1 - 5-May-2005 * Removed the uname.rd file. The uname.txt file is rdoc friendly, so you can autogenerate html from that file if you wish. * Removed the version.h file - no longer needed now that the Windows version is pure Ruby. * Renamed test.rb to uname_test.rb * Minor setup modifications to the test suite. * This package is now hosted on RubyForge. ## 0.7.0 - 11-Jan-2004 * Scrapped the C version for Windows in favor of a pure Ruby version that uses WMI + OLE. I highly recommend using Ruby 1.8.2 or later on Win32 systems. Earlier versions may cause segfaults. * Added the isa_list, hw_provider, hw_serial_number, srpc_domain and dhcp_cache methods for Solaris. * Added install.rb program for Windows, and modified extconf.rb to only run on non-Windows systems. * The 'examples' directory has been moved to the toplevel directory. * Removed the INSTALL file. That information is now included in the README. * Documentation updates. ## 0.6.1 - 25-Apr-2004 * Simplified extconf.rb script and installation instructions. * Combined three test scripts into a single test script. * Warranty information added. ## 0.6.0 - 25-Jun-2003 * Added HP-UX support, including the id() class method (HP-UX only) * Fixed minor bug in extconf.rb (forgot 'require ftools' at top) * Added HP-UX specific tests and support * Made test.rb friendlier for folks without TestUnit installed ## 0.5.0 - 16-Jun-2003 * Added OS X support, including the "model" method. Thanks to Mike Hall for the patch * Removed VERSION() class method. Use the constant instead * Moved rd documentation to its own file (under /doc directory) * Added a version.h file under 'lib' to store VERSION info for all source files * Modified extconf.rb file to handle OS X support. In addition, moved test.rb into a static file under /test, instead of dynamically generating it * Fixed up test suite. Added OS X specific tests and support. Should now work with TestUnit 0.1.6 or later ## 0.4.1 - 7-Feb-2003 * Fixed C89 issue (again) - thanks go to Daniel Zepeda for the spot * Fixed bugs in extconf.rb file (rescue clause, ftools) ## 0.4.0 - 6-Feb-2003 * MS Windows support! * Added a test suite and automatic test.rb creation * Documentation additions/fixes * Internal directory layout and filename changes (Changelog -> CHANGES) ## 0.3.3 - 6-Jan-2003 * Made the code C89 compliant for older compilers. Thanks to Paul Brannan for teaching me how to fix this in general. * Moved README to doc/uname.txt * Created an INSTALL file * Added a copyright notice * Added a VERSION class method * Changed tarball name to reflect RAA package name * Minor doc changes ## 0.3.2 - 8-Aug-2002 * Changed the struct name returned by the 'uname()' method from "Uname::UnameStruct" to just "UnameStruct". This was to make it compliant with future versions of Ruby. The extra namespace was redundant anyway. * I include the documentation now, instead of making you install rd2 :) ## 0.3.1 - 22-Jul-2002 * Added the 'uname' class method, which returns a struct that contains all of the uname information * Added a test script. Do 'ruby test.rb' to run it. * If rd2 is installed on your system, the documentation is automatically generated for you. * Moved html documentation to 'doc' directory. * Changed version number style to be consistent with other 'Sys' modules * Now installs into 'Sys-Uname-x.x.x' directory (instead of just 'Uname') ## 0.03 - 6-June-2002 * rd style documentation now inline * README.html is now uname.html - created via rdtool * The 'platform()' and 'architecture()' methods have been added for Solaris * You can now do an 'include Sys' to shorten your syntax * The whole 'Sys' class has been removed. Delete your sys.so file if you installed a previous version of Sys-Uname ## 0.02 - 3-June-2002 * Potentially fatal memory problems corrected. * Should now build with C++ as well * Thanks to Mike Hall for both the spot and the fix * Added a Changelog file * Added a README.html file * Added a Manifest file ## 0.01 - 31-May-2002 * Initial release (unannounced) djberg96-sys-uname-60e7a35/Gemfile000066400000000000000000000000461515630643300167020ustar00rootroot00000000000000source 'https://rubygems.org' gemspec djberg96-sys-uname-60e7a35/LICENSE000066400000000000000000000236761515630643300164320ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS djberg96-sys-uname-60e7a35/MANIFEST.md000066400000000000000000000003411515630643300171350ustar00rootroot00000000000000* CHANGES.rdoc * MANIFEST.rdoc * README.rdoc * Gemfile * Rakefile * sys-uname.gemspec * certs/djberg96_pub.pem * doc/uname.rdoc * examples/uname_test.rb * lib/sys/uname.rb * spec/sys_uname_spec.rb * spec/sys_platform_spec.rb djberg96-sys-uname-60e7a35/README.md000066400000000000000000000040451515630643300166710ustar00rootroot00000000000000[![Ruby](https://github.com/djberg96/sys-uname/actions/workflows/ruby.yml/badge.svg)](https://github.com/djberg96/sys-uname/actions/workflows/ruby.yml) ## Description A cross-platform Ruby interface for getting operating system information. The name comes from the Unix 'uname' command, but this library works on MS Windows as well. ## Prerequisites ffi 1.0 or later ## Installation `gem install sys-uname` ## Adding the trusted cert `gem cert --add <(curl -Ls https://raw.githubusercontent.com/djberg96/sys-uname/main/certs/djberg96_pub.pem)` ## Synopsis ```ruby require 'sys/uname' # require 'sys-uname' works, too # You now have Sys::Uname and Sys::Platform classes available. # Get full information about your system p Sys::Uname.uname # Check individual platform details about your system p Sys::Platform.linux? # => true p Sys::Platform::ARCH # => :x86_64 ``` ## Memoist Notes As of version 1.4.0 most methods are memoized via the memoist gem since these values are extremely unlikely to change without a restart/reboot. As per the memoist documentation, you can force a cache flush if desired to refresh the values. https://github.com/honzasterba/memoist ## BSD flavors, including OS X Users on BSD platforms get the extra `Uname.model` method. ## HP-UX Notes HP-UX users get the extra `Uname.id_number` method. This is actually a String, not a Fixnum, because that's how it's defined in the utsname struct. ## MS Windows Notes The C version for Windows has been completely scrapped in favor of an OLE plus WMI approach. It is pure Ruby. Please see the MSDN documentation for the `Win32_OperatingSystem` class for a complete list of what each of the UnameStruct members mean. ## The Platform Class This was added both as a nicer way to check simple information about your system, and as a replacement for the old 'Platform' gem which is no longer maintained. ## Future Plans I may dump the "Uname" portion of this library, and rename the project to just sys-platform. ## Documentation For more details, see the 'uname.rdoc' file under the 'doc' directory. djberg96-sys-uname-60e7a35/Rakefile000066400000000000000000000017001515630643300170520ustar00rootroot00000000000000require 'rake' require 'rake/clean' require 'rbconfig' require 'rspec/core/rake_task' require 'rubocop/rake_task' CLEAN.include("**/*.rbc", "**/*.rbx", "**/*.gem", "**/*.lock") desc "Run the example program" task :example do if File::ALT_SEPARATOR sh 'ruby -Ilib/windows examples/uname_test.rb' else sh 'ruby -Ilib/unix examples/uname_test.rb' end end namespace :gem do desc "Create the sys-uname gem" task :create => [:clean] do require 'rubygems/package' spec = Gem::Specification.load('sys-uname.gemspec') spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem') Gem::Package.build(spec) end desc "Install the sys-uname gem" task :install => [:create] do file = Dir["*.gem"].first sh "gem install #{file}" end end RuboCop::RakeTask.new desc "Run the test suite" RSpec::Core::RakeTask.new(:spec) do |t| t.verbose = true t.rspec_opts = '-f documentation -w' end task :default => :spec djberg96-sys-uname-60e7a35/certs/000077500000000000000000000000001515630643300165275ustar00rootroot00000000000000djberg96-sys-uname-60e7a35/certs/djberg96_pub.pem000066400000000000000000000030761515630643300215220ustar00rootroot00000000000000-----BEGIN CERTIFICATE----- MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MREwDwYDVQQDDAhkamJl cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t MB4XDTE4MDMxODE1MjIwN1oXDTI4MDMxNTE1MjIwN1owPzERMA8GA1UEAwwIZGpi ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv bTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALgfaroVM6CI06cxr0/h A+j+pc8fgpRgBVmHFaFunq28GPC3IvW7Nvc3Y8SnAW7pP1EQIbhlwRIaQzJ93/yj u95KpkP7tA9erypnV7dpzBkzNlX14ACaFD/6pHoXoe2ltBxk3CCyyzx70mTqJpph 75IB03ni9a8yqn8pmse+s83bFJOAqddSj009sGPcQO+QOWiNxqYv1n5EHcvj2ebO 6hN7YTmhx7aSia4qL/quc4DlIaGMWoAhvML7u1fmo53CYxkKskfN8MOecq2vfEmL iLu+SsVVEAufMDDFMXMJlvDsviolUSGMSNRTujkyCcJoXKYYxZSNtIiyd9etI0X3 ctu0uhrFyrMZXCedutvXNjUolD5r9KGBFSWH1R9u2I3n3SAyFF2yzv/7idQHLJJq 74BMnx0FIq6fCpu5slAipvxZ3ZkZpEXZFr3cIBtO1gFvQWW7E/Y3ijliWJS1GQFq 058qERadHGu1yu1dojmFRo6W2KZvY9al2yIlbkpDrD5MYQIDAQABo3cwdTAJBgNV HRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUFZsMapgzJimzsbaBG2Tm8j5e AzgwHQYDVR0RBBYwFIESZGpiZXJnOTZAZ21haWwuY29tMB0GA1UdEgQWMBSBEmRq YmVyZzk2QGdtYWlsLmNvbTANBgkqhkiG9w0BAQsFAAOCAYEAW2tnYixXQtKxgGXq /3iSWG2bLwvxS4go3srO+aRXZHrFUMlJ5W0mCxl03aazxxKTsVVpZD8QZxvK91OQ h9zr9JBYqCLcCVbr8SkmYCi/laxIZxsNE5YI8cC8vvlLI7AMgSfPSnn/Epq1GjGY 6L1iRcEDtanGCIvjqlCXO9+BmsnCfEVehqZkQHeYczA03tpOWb6pon2wzvMKSsKH ks0ApVdstSLz1kzzAqem/uHdG9FyXdbTAwH1G4ZPv69sQAFAOCgAqYmdnzedsQtE 1LQfaQrx0twO+CZJPcRLEESjq8ScQxWRRkfuh2VeR7cEU7L7KqT10mtUwrvw7APf DYoeCY9KyjIBjQXfbj2ke5u1hZj94Fsq9FfbEQg8ygCgwThnmkTrrKEiMSs3alYR ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh -----END CERTIFICATE----- djberg96-sys-uname-60e7a35/doc/000077500000000000000000000000001515630643300161545ustar00rootroot00000000000000djberg96-sys-uname-60e7a35/doc/uname.rdoc000066400000000000000000000054501515630643300201360ustar00rootroot00000000000000== Description A cross platform Ruby interface for getting operating system information. The name comes from the Unix 'uname' command, but this library works on Windows as well. == Synopsis require 'sys/uname' include Sys # Unix puts Uname.nodename => my_host puts Uname.version => #1 Fri Oct 24 22:43:28 MDT 2003 puts Uname.sysname => Linux puts Uname.machine => i686 puts Uname.release => 2.4.22-21mdk p Uname.uname => Show all UnameStruct members # Windows u = Uname.uname puts u.caption => 'Microsoft Windows XP Home Edition puts u.csd_version => 'Service Pack 2' == Constants VERSION The current version number of the sys-uname library. This is a String. == Class Methods Uname.sysname Returns the operating system name, e.g. "Darwin". Uname.nodename Returns the nodename. This is usually, but not necessarily, the same as the system's hostname. You cannot currently set the nodename (root or otherwise). This may be added in a future release. Uname.machine Returns the machine hardware type, e.g. "i686" Uname.version Returns the operating system version. e.g. "5.8". In the case of MS Windows, it returns the version plus patch information, separated by a hyphen, e.g. "2915-Service Pack 2". Uname.release Returns the operating system release, e.g. "2.2.16-3" Uname.uname Returns a struct of type UnameStruct that contains sysname, nodename, machine, version, and release. On HP-UX, it will also include id_number. MS Windows - there are many more, and different, fields in the struct. Please see the MSDN documenation on the Win32_OperatingSystem WMI class for a complete explanation of what each of these members mean. == BSD Platforms Only (including OS X) Uname.model Returns the model type, e.g. "PowerBook5,1" == HP-UX Only Uname.id Returns the id number, e.g. 234233587. This is a String, not a Fixnum. == Notes Not all of the information that you might be used to seeing with a 'uname -a' is available. This may be added in future releases, but since different implementations provide different information (via different header files) it will be a bit of a pain. Windows users - please see the MSDN documentation for the Win32_OperatingSystem class for a complete list of what each of the UnameStruct members mean. == Known Bugs None that I'm aware of. Please log any bugs on the project page at https://github.com/djberg96/sys-uname == License Apache-2.0 == Copyright (C) 2002-2026 Daniel J. Berger All Rights Reserved == Warranty This package is provided "as is" and without any express or implied warranties, including, without limitation, the implied warranties of merchantability and fitness for a particular purpose. == Author Daniel Berger == See Also uname(1) for unix, or WMI for MS Windows. djberg96-sys-uname-60e7a35/examples/000077500000000000000000000000001515630643300172255ustar00rootroot00000000000000djberg96-sys-uname-60e7a35/examples/uname_test.rb000066400000000000000000000016421515630643300217210ustar00rootroot00000000000000######################################################################## # uname_test.rb # # Generic test script for general futzing. Modify as you see fit. This # should generally be run via the 'rake example' task. ######################################################################## require 'sys/uname' require 'rbconfig' include Sys puts "VERSION: " + Uname::VERSION puts 'Nodename: ' + Uname.nodename puts 'Sysname: ' + Uname.sysname puts 'Version: ' + Uname.version puts 'Release: ' + Uname.release puts 'Machine: ' + Uname.machine # May be "unknown" on Win32 if RbConfig::CONFIG['host_os'] =~ /powerpc|darwin|bsd|dragonfly|mach/i print "\nBSD/OS X specific tests\n" puts "=======================" puts 'Model: ' + Uname.model end if RbConfig::CONFIG['host_os'] =~ /hpux/i print "\nHP-UX specific tests\n" puts "========================" puts "ID: " + Uname.id end print "\nTest finished successfully\n" djberg96-sys-uname-60e7a35/lib/000077500000000000000000000000001515630643300161555ustar00rootroot00000000000000djberg96-sys-uname-60e7a35/lib/sys-uname.rb000066400000000000000000000000741515630643300204240ustar00rootroot00000000000000# frozen_string_literal: true require_relative 'sys/uname' djberg96-sys-uname-60e7a35/lib/sys/000077500000000000000000000000001515630643300167735ustar00rootroot00000000000000djberg96-sys-uname-60e7a35/lib/sys/platform.rb000066400000000000000000000027131515630643300211470ustar00rootroot00000000000000# frozen_string_literal: true # The Sys module is a namespace only. module Sys # The Platform class provides singleton methods to tell you what OS you're on. class Platform # The CPU architecture ARCH = File::ALT_SEPARATOR ? Uname.architecture.to_sym : Uname.machine.to_sym # Returns a basic OS family, either :windows or :unix OS = File::ALT_SEPARATOR ? :windows : :unix # Returns the OS type, :macosx, :linux, :mingw32, etc IMPL = case Uname.sysname when /darwin|mac/i :macosx when /mingw|windows/i require 'rbconfig' RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase.to_sym when /linux/i :linux when /bsd|dragonfly/i :bsd end # Returns whether or not you're on a Windows OS def self.windows? Uname.sysname =~ /microsoft/i ? true : false end # Returns whether or not you're on a Unixy (non-Windows) OS def self.unix? Uname.sysname =~ /microsoft/i ? false : true end # Returns whether or not you're on a mac, i.e. OSX def self.mac? Uname.sysname =~ /darwin|mac/i ? true : false end # Returns whether or not you're on Linux def self.linux? Uname.sysname =~ /linux/i ? true : false end # Returns whether or not you're on any BSD platform def self.bsd? Uname.sysname =~ /bsd/i ? true : false end end end djberg96-sys-uname-60e7a35/lib/sys/uname.rb000066400000000000000000000005361515630643300204310ustar00rootroot00000000000000# frozen_string_literal: true module Sys class Uname # The version of the sys-uname gem. VERSION = '1.5.1' end class Platform # The version of the sys-uname gem. VERSION = Uname::VERSION end end if File::ALT_SEPARATOR require_relative 'windows/uname' else require_relative 'unix/uname' end require_relative 'platform' djberg96-sys-uname-60e7a35/lib/sys/unix/000077500000000000000000000000001515630643300177565ustar00rootroot00000000000000djberg96-sys-uname-60e7a35/lib/sys/unix/uname.rb000066400000000000000000000155661515630643300214250ustar00rootroot00000000000000# frozen_string_literal: true require 'ffi' require 'rbconfig' require 'memoist' # The Sys module serves as a namespace only. module Sys # The Uname class encapsulates information about the system. class Uname extend FFI::Library ffi_lib FFI::Library::LIBC # Error raised if the uname() function fails. class Error < StandardError; end # :stopdoc # Buffer size for uname struct char arrays case RbConfig::CONFIG['host_os'] when /linux/i BUFSIZE = 65 when /bsd|dragonfly/i BUFSIZE = 32 else BUFSIZE = 256 end attach_function :uname_c, :uname, [:pointer], :int private_class_method :uname_c begin attach_function :sysctl, %i[pointer uint pointer pointer pointer size_t], :int private_class_method :sysctl CTL_HW = 6 # Generic hardware/cpu HW_MODEL = 2 # Specific machine model rescue FFI::NotFoundError # Ignore. Not suppored. end begin attach_function :sysinfo, %i[int pointer long], :long private_class_method :sysinfo SI_SYSNAME = 1 # OS name SI_HOSTNAME = 2 # Node name SI_RELEASE = 3 # Operating system release SI_VERSION = 4 # Version field of utsname SI_MACHINE = 5 # Machine type SI_ARCHITECTURE = 6 # Instruction set architecture SI_HW_SERIAL = 7 # Hardware serial number SI_HW_PROVIDER = 8 # Hardware manufacturer SI_SRPC_DOMAIN = 9 # Secure RPC domain SI_PLATFORM = 513 # Platform identifier SI_ISALIST = 514 # Supported isalist SI_DHCP_CACHE = 515 # Kernel cached DHCPACK rescue FFI::NotFoundError # Ignore. Not suppored. end # FFI class passed to the underlying C uname function. class UnameFFIStruct < FFI::Struct members = [ :sysname, [:char, BUFSIZE], :nodename, [:char, BUFSIZE], :release, [:char, BUFSIZE], :version, [:char, BUFSIZE], :machine, [:char, BUFSIZE] ] members.push(:domainname, [:char, BUFSIZE]) if RbConfig::CONFIG['host_os'] =~ /linux/i members.push(:__id_number, [:char, BUFSIZE]) if RbConfig::CONFIG['host_os'] =~ /hpux/i layout(*members) end fields = %w[ sysname nodename release version machine ] fields.push('domainname') if RbConfig::CONFIG['host_os'] =~ /linux/i fields.push('id_number') if RbConfig::CONFIG['host_os'] =~ /hpux/i fields.push('model') if RbConfig::CONFIG['host_os'] =~ /darwin|bsd|dragonfly/i private_constant :UnameFFIStruct # :startdoc: UnameStruct = Struct.new('UnameStruct', *fields) # Returns a struct that contains the sysname, nodename, machine, version # and release of your system. # # On OS X and BSD platforms it will also include the model. # # On HP-UX, it will also include the id_number. # # Example: # # require 'sys/uname' # # p Sys::Uname.uname # def self.uname utsname = UnameFFIStruct.new raise Error, 'uname() function call failed' if uname_c(utsname) < 0 struct = UnameStruct.new struct[:sysname] = utsname[:sysname].to_s struct[:nodename] = utsname[:nodename].to_s struct[:release] = utsname[:release].to_s struct[:version] = utsname[:version].to_s struct[:machine] = utsname[:machine].to_s struct[:model] = get_model() if RbConfig::CONFIG['host_os'] =~ /darwin|bsd|dragonfly/i struct[:id_number] = utsname[:__id_number].to_s if RbConfig::CONFIG['host_os'] =~ /hpux/i struct[:domainname] = utsname[:domainname].to_s if RbConfig::CONFIG['host_os'] =~ /linux/i # Let's add a members method that works for testing and compatibility if struct.members.nil? struct.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def members @table.keys.map(&:to_s) end RUBY end struct.freeze end # Returns the name of this implementation of the operating system. # # Example: # # Uname.sysname # => 'Darwin' # def self.sysname uname.sysname end # Returns the name of this node within the communications network to # which this node is attached, if any. This is often, but not # necessarily, the same as the host name. # # Example: # # Uname.nodename # => 'your_host.foo.com' # def self.nodename uname.nodename end # Returns the current release level of your operating system. # # Example: # # Uname.release # => '2.2.16-3' # def self.release uname.release end # Returns the current version level of your operating system. # # Example: # # Uname.version # => '5.9' # def self.version uname.version end # Returns the machine hardware type. # # Example: # # Uname.machine # => 'i686' # def self.machine uname.machine end if defined? :sysctl # Returns the model type. # # Example: # # Uname.model # => 'MacBookPro5,3' # def self.model uname.model end end if defined? :sysinfo # The basic instruction set architecture of the current # system, e.g. sparc, i386, etc. # def self.architecture uname.architecture end # The specific model of the hardware platform, e.g Sun-Blade-1500, etc. # def self.platform uname.platform end # The string consisting of the ASCII hexidecimal encoding of the name # of the interface configured by boot(1M) followed by the DHCPACK reply # from the server. # def self.dhcp_cache uname.dhcp_cache end # The variant instruction set architectures executable on the # current system. # def self.isa_list uname.isa_list end # The ASCII representation of the hardware-specific serial number # of the physical machine on which the function is executed. # def self.hw_serial uname.hw_serial.to_i end # The name of the of the hardware provider. # def self.hw_provider uname.hw_provider end # The Secure Remote Procedure Call domain name. # def self.srpc_domain uname.srpc_domain end end class << self extend Memoist memoize :sysname memoize :nodename memoize :release memoize :version memoize :machine end private # Returns the model for systems that define sysctl(). # def self.get_model buf = 0.chr * BUFSIZE mib = FFI::MemoryPointer.new(:int, 2).write_array_of_int([CTL_HW, HW_MODEL]) size = FFI::MemoryPointer.new(:long, 1).write_int(buf.size) sysctl(mib, 2, buf, size, nil, 0) buf.strip end private_class_method :get_model end end djberg96-sys-uname-60e7a35/lib/sys/windows/000077500000000000000000000000001515630643300204655ustar00rootroot00000000000000djberg96-sys-uname-60e7a35/lib/sys/windows/uname.rb000066400000000000000000000314721515630643300221260ustar00rootroot00000000000000# frozen_string_literal: true require 'socket' require 'time' require 'win32ole' require 'memoist' # The Sys module provides a namespace only. module Sys # The Uname class encapsulates uname (platform) information. class Uname # This is the error raised if any of the Sys::Uname methods should fail. class Error < StandardError; end fields = %w[ boot_device build_number build_type caption code_set country_code creation_class_name cscreation_class_name csd_version cs_name current_time_zone debug description distributed encryption_level foreground_application_boost free_physical_memory free_space_in_paging_files free_virtual_memory install_date last_bootup_time local_date_time locale manufacturer max_number_of_processes max_process_memory_size name number_of_licensed_users number_of_processes number_of_users organization os_language os_product_suite os_type other_type_description plus_product_id plus_version_number primary product_type quantum_length quantum_type registered_user serial_number service_pack_major_version service_pack_minor_version size_stored_in_paging_files status suite_mask system_device system_directory system_drive total_swap_space_size total_virtual_memory_size total_visible_memory_size version windows_directory ] # The UnameStruct is used to store platform information for some methods. UnameStruct = Struct.new('UnameStruct', *fields) # Returns the version plus patch information of the operating system, # separated by a hyphen, e.g. "2915-Service Pack 2". #-- # The instance name is unpredictable, so we have to resort to using # the 'InstancesOf' method to get the data we need, rather than # including it as part of the connection. # def self.version(host = Socket.gethostname) cs = "winmgmts://#{host}/root/cimv2" begin wmi = WIN32OLE.connect(cs) rescue WIN32OLERuntimeError => err raise Error, err else ole = wmi.InstancesOf('Win32_OperatingSystem').ItemIndex(0) str = "#{ole.Version} #{ole.BuildNumber}-" "#{str}#{ole.ServicePackMajorVersion}" end end # Returns the operating system name, e.g. "Microsoft Windows XP Home" # def self.sysname(host = Socket.gethostname) cs = 'winmgmts:{impersonationLevel=impersonate,(security)}' cs += "//#{host}/root/cimv2" begin wmi = WIN32OLE.connect(cs) rescue WIN32OLERuntimeError => err raise Error, err else wmi.InstancesOf('Win32_OperatingSystem').ItemIndex(0).Caption.strip end end # Returns the nodename. This is usually, but not necessarily, the # same as the system's hostname. # def self.nodename(host = Socket.gethostname) cs = 'winmgmts:{impersonationLevel=impersonate,(security)}' cs += "//#{host}/root/cimv2" begin wmi = WIN32OLE.connect(cs) rescue WIN32OLERuntimeError => err raise Error, err else wmi.InstancesOf('Win32_OperatingSystem').ItemIndex(0).CSName end end # Returns the CPU architecture, e.g. "x86" # def self.architecture(cpu_num = 0, host = Socket.gethostname) cs = 'winmgmts:{impersonationLevel=impersonate,(security)}' cs += "//#{host}/root/cimv2:Win32_Processor='cpu#{cpu_num}'" begin wmi = WIN32OLE.connect(cs) rescue WIN32OLERuntimeError => err raise Error, err else case wmi.Architecture when 0 'x86' when 1 'mips' when 2 'alpha' when 3 'powerpc' when 6 'ia64' when 9 'x86_64' else 'unknown' end end end # Returns the machine hardware type. e.g. "i686". #-- # This may or may not return the expected value because some CPU types # were unknown to the OS when the OS was originally released. It # appears that MS doesn't necessarily patch this, either. # def self.machine(cpu_num = 0, host = Socket.gethostname) cs = 'winmgmts:{impersonationLevel=impersonate,(security)}' cs += "//#{host}/root/cimv2:Win32_Processor='cpu#{cpu_num}'" begin wmi = WIN32OLE.connect(cs) rescue WIN32OLERuntimeError => err raise Error, err else # Convert a family number into the equivalent string case wmi.Family when 1 'Other' when 3 '8086' when 4 '80286' when 5 '80386' when 6 '80486' when 7 '8087' when 8 '80287' when 9 '80387' when 10 '80487' when 11 'Pentium brand' when 12 'Pentium Pro' when 13 'Pentium II' when 14 'Pentium processor with MMX technology' when 15 'Celeron' when 16 'Pentium II Xeon' when 17 'Pentium III' when 18 'M1 Family' when 19 'M2 Family' when 24 'K5 Family' when 25 'K6 Family' when 26 'K6-2' when 27 'K6-3' when 28 'AMD Athlon Processor Family' when 29 'AMD Duron Processor' when 30 'AMD2900 Family' when 31 'K6-2+' when 32 'Power PC Family' when 33 'Power PC 601' when 34 'Power PC 603' when 35 'Power PC 603+' when 36 'Power PC 604' when 37 'Power PC 620' when 38 'Power PC X704' when 39 'Power PC 750' when 48 'Alpha Family' when 49 'Alpha 21064' when 50 'Alpha 21066' when 51 'Alpha 21164' when 52 'Alpha 21164PC' when 53 'Alpha 21164a' when 54 'Alpha 21264' when 55 'Alpha 21364' when 64 'MIPS Family' when 65 'MIPS R4000' when 66 'MIPS R4200' when 67 'MIPS R4400' when 68 'MIPS R4600' when 69 'MIPS R10000' when 80 'SPARC Family' when 81 'SuperSPARC' when 82 'microSPARC II' when 83 'microSPARC IIep' when 84 'UltraSPARC' when 85 'UltraSPARC II' when 86 'UltraSPARC IIi' when 87 'UltraSPARC III' when 88 'UltraSPARC IIIi' when 96 '68040' when 97 '68xxx Family' when 98 '68000' when 99 '68010' when 100 '68020' when 101 '68030' when 112 'Hobbit Family' when 120 'Crusoe TM5000 Family' when 121 'Crusoe TM3000 Family' when 122 'Efficeon TM8000 Family' when 128 'Weitek' when 130 'Itanium Processor' when 131 'AMD Athlon 64 Processor Family' when 132 'AMD Opteron Processor Family' when 144 'PA-RISC Family' when 145 'PA-RISC 8500' when 146 'PA-RISC 8000' when 147 'PA-RISC 7300LC' when 148 'PA-RISC 7200' when 149 'PA-RISC 7100LC' when 150 'PA-RISC 7100' when 160 'V30 Family' when 176 'Pentium III Xeon' when 177 'Pentium III Processor with Intel SpeedStep Technology' when 178 'Pentium 4' when 179 'Intel Xeon' when 180 'AS400 Family' when 181 'Intel Xeon processor MP' when 182 'AMD AthlonXP Family' when 183 'AMD AthlonMP Family' when 184 'Intel Itanium 2' when 185 'AMD Opteron Family' when 190 'K7' when 198 'Intel Core i7-2760QM' when 200 'IBM390 Family' when 201 'G4' when 202 'G5' when 203 'G6' when 204 'z/Architecture Base' when 250 'i860' when 251 'i960' when 260 'SH-3' when 261 'SH-4' when 280 'ARM' when 281 'StrongARM' when 300 '6x86' when 301 'MediaGX' when 302 'MII' when 320 'WinChip' when 350 'DSP' when 500 'Video Processor' else 'Unknown' end end end # Returns the release number, e.g. 5.1.2600. # def self.release(host = Socket.gethostname) cs = "winmgmts://#{host}/root/cimv2" begin wmi = WIN32OLE.connect(cs) rescue WIN32OLERuntimeError => err raise Error, err else wmi.InstancesOf('Win32_OperatingSystem').ItemIndex(0).Version end end # Returns a struct of type UnameStruct that contains sysname, nodename, # machine, version, and release, as well as a plethora of other fields. # Please see the MSDN documentation for what each of these fields mean. # def self.uname(host = Socket.gethostname) cs = "winmgmts://#{host}/root/cimv2" begin wmi = WIN32OLE.connect(cs) rescue WIN32OLERuntimeError => err raise Error, err else os = wmi.InstancesOf('Win32_OperatingSystem').ItemIndex(0) UnameStruct.new( os.BootDevice, os.BuildNumber, os.BuildType, os.Caption, os.CodeSet, os.CountryCode, os.CreationClassName, os.CSCreationClassName, os.CSDVersion, os.CSName, os.CurrentTimeZone, os.Debug, os.Description, os.Distributed, os.EncryptionLevel, os.ForegroundApplicationBoost, convert(os.FreePhysicalMemory), convert(os.FreeSpaceInPagingFiles), convert(os.FreeVirtualMemory), parse_ms_date(os.InstallDate), parse_ms_date(os.LastBootUpTime), parse_ms_date(os.LocalDateTime), os.Locale, os.Manufacturer, os.MaxNumberOfProcesses, convert(os.MaxProcessMemorySize), os.Name, os.NumberOfLicensedUsers, os.NumberOfProcesses, os.NumberOfUsers, os.Organization, os.OSLanguage, os.OSProductSuite, os.OSType, os.OtherTypeDescription, os.PlusProductID, os.PlusVersionNumber, os.Primary, os.ProductType, os.respond_to?(:QuantumLength) ? os.QuantumLength : nil, os.respond_to?(:QuantumType) ? os.QuantumType : nil, os.RegisteredUser, os.SerialNumber, os.ServicePackMajorVersion, os.ServicePackMinorVersion, convert(os.SizeStoredInPagingFiles), os.Status, os.SuiteMask, os.SystemDevice, os.SystemDirectory, os.SystemDrive, convert(os.TotalSwapSpaceSize), convert(os.TotalVirtualMemorySize), convert(os.TotalVisibleMemorySize), os.Version, os.WindowsDirectory ) end end class << self extend Memoist memoize :sysname memoize :nodename memoize :release memoize :version memoize :machine end # Converts a string in the format '20040703074625.015625-360' into a # Ruby Time object. # def self.parse_ms_date(str) return if str.nil? Time.parse(str.split('.')[0]) end private_class_method :parse_ms_date # There is a bug in win32ole where uint64 types are returned as a # String rather than a Fixnum/Bignum. This deals with that for now. # def self.convert(str) return nil if str.nil? # Don't turn nil into 0 str.to_i end private_class_method :convert end end djberg96-sys-uname-60e7a35/spec/000077500000000000000000000000001515630643300163415ustar00rootroot00000000000000djberg96-sys-uname-60e7a35/spec/spec_helper.rb000066400000000000000000000006751515630643300211670ustar00rootroot00000000000000# frozen_string_literal: true require 'rspec' require 'sys/uname' RSpec.configure do |config| config.filter_run_excluding(:bsd) unless RbConfig::CONFIG['host_os'] =~ /powerpc|darwin|macos|bsd|dragonfly/i config.filter_run_excluding(:hpux) unless RbConfig::CONFIG['host_os'] =~ /hpux/i config.filter_run_excluding(:linux) unless RbConfig::CONFIG['host_os'] =~ /linux/i config.filter_run_excluding(:windows) unless Gem.win_platform? end djberg96-sys-uname-60e7a35/spec/sys_platform_spec.rb000066400000000000000000000040631515630643300224250ustar00rootroot00000000000000# frozen_string_literal: true ############################################################################## # sys_platform_spec.rb # # Test suite for the Sys::Platform class. ############################################################################## require 'spec_helper' RSpec.describe Sys::Platform do example 'the VERSION constant is set to the expected value' do expect(Sys::Platform::VERSION).to eql('1.5.1') expect(Sys::Platform::VERSION).to be_frozen end example 'the ARCH constant is defined' do expect(Sys::Platform::ARCH).to be_a(Symbol) end example 'the OS constant is defined' do expect(Sys::Platform::OS).to be_a(Symbol) end example 'the IMPL constant is defined' do expect(Sys::Platform::IMPL).to be_a(Symbol) end example 'the IMPL returns an expected value on windows', :windows do expect(%i[mingw mswin]).to include(Sys::Platform::IMPL) end example 'the mac? method is defined and returns a boolean' do expect(described_class).to respond_to(:mac?) expect(described_class.mac?).to eql(true).or eql(false) end example 'the windows? method is defined and returns a boolean' do expect(described_class).to respond_to(:windows?) expect(described_class.windows?).to eql(true).or eql(false) end example 'the windows? method returns the expected value' do expect(described_class.windows?).to eql(Gem.win_platform?) end example 'the unix? method is defined and returns a boolean' do expect(described_class).to respond_to(:unix?) expect(described_class.unix?).to eql(true).or eql(false) end example 'the unix? method returns the expected value' do expect(described_class.unix?).not_to eql(Gem.win_platform?) end example 'the linux? method is defined and returns a boolean' do expect(described_class).to respond_to(:linux?) expect(described_class.linux?).to eql(true).or eql(false) end example 'the bsd? method is defined and returns a boolean' do expect(described_class).to respond_to(:bsd?) expect(described_class.bsd?).to eql(true).or eql(false) end end djberg96-sys-uname-60e7a35/spec/sys_uname_spec.rb000066400000000000000000000425071515630643300217130ustar00rootroot00000000000000# frozen_string_literal: true ############################################################################## # sys_uname_spec.rb # # Test suite for the sys-uname library. Run 'rake test' to execute tests. ############################################################################## require 'spec_helper' RSpec.describe Sys::Uname do let(:members){ %i[sysname nodename machine version release] } let(:windows_members) do %i[ boot_device build_number build_type caption code_set country_code creation_class_name cscreation_class_name csd_version cs_name current_time_zone debug description distributed encryption_level foreground_application_boost free_physical_memory free_space_in_paging_files free_virtual_memory install_date last_bootup_time local_date_time locale manufacturer max_number_of_processes max_process_memory_size name number_of_licensed_users number_of_processes number_of_users organization os_language os_product_suite os_type other_type_description plus_product_id plus_version_number primary product_type quantum_length quantum_type registered_user serial_number service_pack_major_version service_pack_minor_version size_stored_in_paging_files status suite_mask system_device system_directory system_drive total_swap_space_size total_virtual_memory_size total_visible_memory_size version windows_directory ] end context 'universal singleton methods' do example 'version constant is set to expected value' do expect(Sys::Uname::VERSION).to eql('1.5.1') expect(Sys::Uname::VERSION).to be_frozen end example 'uname basic functionality' do expect{ described_class.uname }.not_to raise_error expect(described_class.uname).to be_a(Struct) end example 'machine singleton method works as expected' do expect(described_class).to respond_to(:machine) expect{ described_class.machine }.not_to raise_error expect(described_class.machine).to be_a(String) expect(described_class.machine.size).to be > 0 end example 'version singleton method works as expected' do expect(described_class).to respond_to(:version) expect{ described_class.version }.not_to raise_error expect(described_class.version).to be_a(String) expect(described_class.version.size).to be > 0 end example 'nodename singleton method works as expected' do expect(described_class).to respond_to(:nodename) expect{ described_class.nodename }.not_to raise_error expect(described_class.nodename).to be_a(String) end example 'release singleton method works as expected' do expect(described_class).to respond_to(:release) expect{ described_class.release }.not_to raise_error expect(described_class.release).to be_a(String) expect(described_class.release.size).to be > 0 end example 'sysname singleton method works as expected' do expect(described_class).to respond_to(:sysname) expect{ described_class.sysname }.not_to raise_error expect(described_class.sysname).to be_a(String) expect(described_class.sysname.size).to be > 0 end end context 'singleton methods for BSD and Darwin only', :bsd do example 'model singleton method works as expected on BSD and Darwin' do expect(described_class).to respond_to(:model) expect{ described_class.model }.not_to raise_error expect(described_class.model).to be_a(String) end end context 'singleton methods for HP-UX only', :hpux do example 'id_number singleton method works as expected on HP-UX' do expect(described_class).to respond_to(:id_number) expect{ described_class.id_number }.not_to raise_error expect(described_class.id_number).to be_a(String) end end context 'uname struct' do example 'uname struct contains expected members on linux', :linux do members.push(:domainname) expect(described_class.uname.members.sort).to eql(members.sort) end example 'uname struct contains expected members on bsd or osx', :bsd do members.push(:model) expect(described_class.uname.members.sort).to eql(members.sort) end example 'uname struct contains expected members on hpux', :hpux do members.push(:id) expect(described_class.uname.members.sort).to eql(members.sort) end example 'uname struct contains expected members on windows', :windows do expect(described_class.uname.members.sort).to eql(windows_members.sort) end end context 'ffi' do let(:our_methods){ described_class.methods(false).map(&:to_s) } example 'ffi and internal functions are not public' do expect(our_methods).not_to include('get_model') expect(our_methods).not_to include('get_si') expect(our_methods).not_to include('uname_c') expect(our_methods).not_to include('sysctl') expect(our_methods).not_to include('sysinfo') end end context 'instance methods for MS Windows', :if => File::ALT_SEPARATOR do example 'boot_device' do expect{ described_class.uname.boot_device }.not_to raise_error expect(described_class.uname.boot_device).to be_a(String) end example 'build_number' do expect{ described_class.uname.build_number }.not_to raise_error expect(described_class.uname.build_number).to be_a(String) end example 'build_type' do expect{ described_class.uname.build_type }.not_to raise_error expect(described_class.uname.build_type).to be_a(String) end example 'caption' do expect{ described_class.uname.caption }.not_to raise_error expect(described_class.uname.caption).to be_a(String) end example 'code_set' do expect{ described_class.uname.code_set }.not_to raise_error expect(described_class.uname.code_set).to be_a(String) end example 'country_code' do expect{ described_class.uname.country_code }.not_to raise_error expect(described_class.uname.country_code).to be_a(String) end example 'creation_class_name' do expect{ described_class.uname.creation_class_name }.not_to raise_error expect(described_class.uname.creation_class_name).to be_a(String) end example 'cscreation_class_name' do expect{ described_class.uname.cscreation_class_name }.not_to raise_error expect(described_class.uname.cscreation_class_name).to be_a(String) end example 'csd_version' do expect{ described_class.uname.csd_version }.not_to raise_error expect(described_class.uname.csd_version).to be_a(String).or be_nil end example 'cs_name' do expect{ described_class.uname.cs_name }.not_to raise_error expect(described_class.uname.cs_name).to be_a(String) end example 'current_time_zone' do expect{ described_class.uname.current_time_zone }.not_to raise_error expect(described_class.uname.current_time_zone).to be_a(Integer) end example 'debug' do expect{ described_class.uname.debug }.not_to raise_error expect(described_class.uname.debug).to be(true).or be(false) end example 'description' do expect{ described_class.uname.description }.not_to raise_error expect(described_class.uname.description).to be_a(String) end example 'distributed' do expect{ described_class.uname.distributed }.not_to raise_error expect(described_class.uname.distributed).to be(true).or be(false) end example 'encryption_level' do expect{ described_class.uname.encryption_level }.not_to raise_error expect(described_class.uname.encryption_level).to be_a(Integer) end example 'foreground_application_boost' do expect{ described_class.uname.foreground_application_boost }.not_to raise_error expect(described_class.uname.foreground_application_boost).to be_a(Integer) end example 'free_physical_memory' do expect{ described_class.uname.free_physical_memory }.not_to raise_error expect(described_class.uname.free_physical_memory).to be_a(Integer) end example 'free_space_in_paging_files' do expect{ described_class.uname.free_space_in_paging_files }.not_to raise_error expect(described_class.uname.free_space_in_paging_files).to be_a(Integer) end example 'free_virtual_memory' do expect{ described_class.uname.free_virtual_memory }.not_to raise_error expect(described_class.uname.free_virtual_memory).to be_a(Integer) end example 'install_date' do expect{ described_class.uname.install_date }.not_to raise_error expect(described_class.uname.install_date).to be_a(Time) end example 'last_bootup_time' do expect{ described_class.uname.last_bootup_time }.not_to raise_error expect(described_class.uname.last_bootup_time).to be_a(Time) end example 'local_date_time' do expect{ described_class.uname.local_date_time }.not_to raise_error expect(described_class.uname.local_date_time).to be_a(Time) end example 'locale' do expect{ described_class.uname.locale }.not_to raise_error expect(described_class.uname.locale).to be_a(String) end example 'manufacturer' do expect{ described_class.uname.manufacturer }.not_to raise_error expect(described_class.uname.manufacturer).to be_a(String) end example 'max_number_of_processes' do expect{ described_class.uname.max_number_of_processes }.not_to raise_error expect(described_class.uname.max_number_of_processes).to be_a(Integer) end example 'max_process_memory_size' do expect{ described_class.uname.max_process_memory_size }.not_to raise_error expect(described_class.uname.max_process_memory_size).to be_a(Integer) end example 'name' do expect{ described_class.uname.name }.not_to raise_error expect(described_class.uname.name).to be_a(String) end example 'number_of_licensed_users' do expect{ described_class.uname.number_of_licensed_users }.not_to raise_error expect(described_class.uname.number_of_licensed_users).to be_a(Integer).or be_nil end example 'number_of_processes' do expect{ described_class.uname.number_of_processes }.not_to raise_error expect(described_class.uname.number_of_processes).to be_a(Integer) end example 'number_of_users' do expect{ described_class.uname.number_of_users }.not_to raise_error expect(described_class.uname.number_of_users).to be_a(Integer) end example 'organization' do expect{ described_class.uname.organization }.not_to raise_error expect(described_class.uname.organization).to be_a(String).or be_nil end example 'os_language' do expect{ described_class.uname.os_language }.not_to raise_error expect(described_class.uname.os_language).to be_a(Integer) end example 'os_product_suite' do expect{ described_class.uname.os_product_suite }.not_to raise_error expect(described_class.uname.os_product_suite).to be_a(Integer) end example 'os_type' do expect{ described_class.uname.os_type }.not_to raise_error expect(described_class.uname.os_type).to be_a(Integer) end example 'other_type_description' do expect{ described_class.uname.other_type_description }.not_to raise_error expect(described_class.uname.other_type_description).to be_a(String).or be_nil end example 'plus_product_id' do expect{ described_class.uname.plus_product_id }.not_to raise_error expect(described_class.uname.plus_product_id).to be_a(Integer).or be_nil end example 'plus_version_number' do expect{ described_class.uname.plus_version_number }.not_to raise_error expect(described_class.uname.plus_version_number).to be_a(Integer).or be_nil end example 'primary' do expect{ described_class.uname.primary }.not_to raise_error expect(described_class.uname.primary).to eql(true).or eql(false) end example 'product_type' do expect{ described_class.uname.product_type }.not_to raise_error expect(described_class.uname.product_type).to be_a(Integer) end example 'quantum_length' do expect{ described_class.uname.quantum_length }.not_to raise_error expect(described_class.uname.quantum_length).to be_a(Integer).or be_nil end example 'quantum_type' do expect{ described_class.uname.quantum_type }.not_to raise_error expect(described_class.uname.quantum_type).to be_a(Integer).or be_nil end example 'registered_user', :unless => ENV['CI'] do expect{ described_class.uname.registered_user }.not_to raise_error expect(described_class.uname.registered_user).to be_a(String) end example 'serial_number' do expect{ described_class.uname.serial_number }.not_to raise_error expect(described_class.uname.serial_number).to be_a(String) end example 'service_pack_major_version' do expect{ described_class.uname.service_pack_major_version }.not_to raise_error expect(described_class.uname.service_pack_major_version).to be_a(Integer) end example 'service_pack_minor_version' do expect{ described_class.uname.service_pack_minor_version }.not_to raise_error expect(described_class.uname.service_pack_minor_version).to be_a(Integer) end example 'status' do expect{ described_class.uname.status }.not_to raise_error expect(described_class.uname.status).to be_a(String) end example 'suite_mask' do expect{ described_class.uname.suite_mask }.not_to raise_error expect(described_class.uname.suite_mask).to be_a(Integer) end example 'system_device' do expect{ described_class.uname.system_device }.not_to raise_error expect(described_class.uname.system_device).to be_a(String) end example 'system_directory' do expect{ described_class.uname.system_directory }.not_to raise_error expect(described_class.uname.system_directory).to be_a(String) end example 'system_drive' do expect{ described_class.uname.system_drive }.not_to raise_error expect(described_class.uname.system_drive).to be_a(String) expect(described_class.uname.system_drive).to eql('C:') end example 'total_swap_space_size' do expect{ described_class.uname.total_swap_space_size }.not_to raise_error expect(described_class.uname.total_swap_space_size).to be_a(Integer).or be_nil end example 'total_virtual_memory_size' do expect{ described_class.uname.total_virtual_memory_size }.not_to raise_error expect(described_class.uname.total_virtual_memory_size).to be_a(Integer) end example 'total_visible_memory_size' do expect{ described_class.uname.total_visible_memory_size }.not_to raise_error expect(described_class.uname.total_visible_memory_size).to be_a(Integer) end example 'version' do expect{ described_class.uname.version }.not_to raise_error expect(described_class.uname.version).to be_a(String) end example 'windows_directory' do expect{ described_class.uname.windows_directory }.not_to raise_error expect(described_class.uname.windows_directory).to be_a(String) end end context 'memoization', :unix do before(:each) do # Clear any existing memoization cache before each test described_class.flush_cache if described_class.respond_to?(:flush_cache) end example 'sysname method is memoized' do first_call = described_class.sysname second_call = described_class.sysname expect(first_call).to equal(second_call) expect(first_call.object_id).to eq(second_call.object_id) end example 'nodename method is memoized' do first_call = described_class.nodename second_call = described_class.nodename expect(first_call).to equal(second_call) expect(first_call.object_id).to eq(second_call.object_id) end example 'release method is memoized' do first_call = described_class.release second_call = described_class.release expect(first_call).to equal(second_call) expect(first_call.object_id).to eq(second_call.object_id) end example 'version method is memoized' do first_call = described_class.version second_call = described_class.version expect(first_call).to equal(second_call) expect(first_call.object_id).to eq(second_call.object_id) end example 'machine method is memoized' do first_call = described_class.machine second_call = described_class.machine expect(first_call).to equal(second_call) expect(first_call.object_id).to eq(second_call.object_id) end example 'memoized methods maintain independence' do # Test that different methods return different values but each is consistently memoized sysname1 = described_class.sysname nodename1 = described_class.nodename # Different methods should return different values expect(sysname1).not_to eq(nodename1) # But repeated calls should return the same object sysname2 = described_class.sysname nodename2 = described_class.nodename expect(sysname1).to equal(sysname2) expect(nodename1).to equal(nodename2) end example 'uname method is not memoized' do # The main uname method should not be memoized, as it returns a new struct each time first_call = described_class.uname second_call = described_class.uname # Should return equivalent structs but not the same object expect(first_call.object_id).not_to eq(second_call.object_id) end end end djberg96-sys-uname-60e7a35/sys-uname.gemspec000066400000000000000000000042041515630643300206750ustar00rootroot00000000000000require 'rubygems' Gem::Specification.new do |spec| spec.name = 'sys-uname' spec.version = '1.5.1' spec.author = 'Daniel J. Berger' spec.email = 'djberg96@gmail.com' spec.homepage = 'http://github.com/djberg96/sys-uname' spec.summary = 'An interface for returning uname (platform) information' spec.license = 'Apache-2.0' spec.files = Dir['**/*'].reject{ |f| f.include?('git') } spec.test_files = Dir['spec/*_spec.rb'] spec.cert_chain = ['certs/djberg96_pub.pem'] spec.extra_rdoc_files = Dir['doc/*.rdoc'] spec.add_dependency('ffi', '~> 1.1') spec.add_dependency('memoist3', '~> 1.0.0') # Yes, this means on every release, we'll have to release two versions # of the gem because it has different dependencies. Hope there's a Windows VM handy! if Gem.win_platform? spec.platform = Gem::Platform.new(['universal', 'mingw32']) spec.add_dependency('win32ole') end spec.add_development_dependency('rspec', '~> 3.9') spec.add_development_dependency('rake') spec.add_development_dependency('rubocop') spec.add_development_dependency('rubocop-rspec') spec.metadata = { 'homepage_uri' => 'https://github.com/djberg96/sys-uname', 'bug_tracker_uri' => 'https://github.com/djberg96/sys-uname/issues', 'changelog_uri' => 'https://github.com/djberg96/sys-uname/blob/main/CHANGES.md', 'documentation_uri' => 'https://github.com/djberg96/sys-uname/wiki', 'source_code_uri' => 'https://github.com/djberg96/sys-uname', 'wiki_uri' => 'https://github.com/djberg96/sys-uname/wiki', 'rubygems_mfa_required' => 'true', 'github_repo' => 'https://github.com/djberg96/sys-uname', 'funding_uri' => 'https://github.com/sponsors/djberg96' } spec.description = <<-EOF The sys-uname library provides an interface for gathering information about your current platform. The library is named after the Unix 'uname' command but also works on MS Windows. Available information includes OS name, OS version, system name and so on. Additional information is available for certain platforms. EOF end