Giter VIP home page Giter VIP logo

etc's Introduction

Etc

The Etc module provides access to information typically stored in files in the /etc directory on Unix systems.

The information accessible consists of the information found in the /etc/passwd and /etc/group files, plus information about he system's temporary directory (/tmp) and configuration directory (/etc).

The Etc module provides a more reliable way to access information about the logged in user than environment variables such as +$USER+.

Installation

Add this line to your application's Gemfile:

gem 'etc'

And then execute:

$ bundle

Or install it yourself as:

$ gem install etc

Usage

require 'etc'

login = Etc.getlogin
info = Etc.getpwnam(login)
username = info.gecos.split(/,/).first
puts "Hello #{username}, I see your login name is #{login}"

Note that the methods provided by this module are not always secure. It should be used for informational purposes, and not for security.

All operations defined in this module are class methods, so that you can include the Etc module into your class.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/etc.

License

The gem is available as open source under the terms of the 2-Clause BSD License.

etc's People

Contributors

akr avatar dependabot[bot] avatar drbrain avatar eban avatar eregon avatar haileys avatar hsbt avatar ioquatix avatar jeremyevans avatar k0kubun avatar knu avatar ko1 avatar mame avatar marcandre avatar nobu avatar nurse avatar olleolleolle avatar peterzhu2118 avatar shirosaki avatar shugo avatar shyouhei avatar tanakakc avatar unak avatar znz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

etc's Issues

Cannot install with `gem install etc`, missing `constdefs.h`

It seems that when installing with gem the file constdefs.h does not get generated, thus building the native extension fails.

fedora 26
gem  --version: 2.6.13
ruby --version: ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]

both running as root or as normal user fail.


To reproduce (more or less)

as root:
dnf install ruby rubygems
gem install etc 

warning: already initialized constant Etc::SC_*

When upgrading etc from 1.0.1 to 1.1.0 in ruby 2.6.5 (linux) it started to throw a lot of warnings like this:

 .../ruby/2.6.5/lib/ruby/2.6.0/x86_64-linux/etc.so: warning: already initialized constant Etc::SC_AIO_LISTIO_MAX
  .../2.6.5/lib/ruby/2.6.0/x86_64-linux/etc.so: warning: already initialized constant Etc::SC_AIO_MAX
  .../ruby/2.6.5/lib/ruby/2.6.0/x86_64-linux/etc.so: warning: already initialized constant Etc::SC_AIO_PRIO_DELTA_MAX
  .../ruby/2.6.5/lib/ruby/2.6.0/x86_64-linux/etc.so: warning: already initialized constant Etc::SC_ARG_MAX
  .../ruby/2.6.5/lib/ruby/2.6.0/x86_64-linux/etc.so: warning: already initialized constant Etc::SC_ATEXIT_MAX
 .../ruby/2.6.5/lib/ruby/2.6.0/x86_64-linux/etc.so: warning: already initialized constant Etc::SC_BC_BASE_MAX
and so on...

Windows CI?

@nobu

Thanks for the quick fix. Of course, ruby-loco ran between the two commits.

Not sure whether there's an interest in Windows CI.

Not sure about how many versions to test, as Windows CI needs to load build tools, and hence, takes quite a bit longer.

Sorry about empty issue, mouse/keyboard error

JRuby support

JRuby has its own Java implementation of this library, which uses our internal FFI library jnr-ffi to bind the appropriate functions. We will need to incorporate this version into the gem, so we can use it and users can include it in Gemfile.

Update to version 1.2.0 results in undefined symbol: rb_deprecate_constant error

On Ruby 2.7.2, if I update etc from version 1.1.0 to 1.2.0, all gem commands stop working:

$ gem outdated
cucumber-cucumber-expressions (10.3.0 < 11.0.0)
cucumber-gherkin (15.0.2 < 16.0.0)
cucumber-html-formatter (9.0.0 < 11.0.2)
date (3.0.1 < 3.1.1)
etc (1.1.0 < 1.2.0)
faraday (1.1.0 < 1.2.0)
fiddle (1.0.5 < 1.0.6)
mini_portile2 (2.4.0 < 2.5.0)
psych (3.2.1 < 3.3.0)
$ gem update etc
Updating installed gems
Updating etc
Building native extensions. This could take a while...
Successfully installed etc-1.2.0
Parsing documentation for etc-1.2.0
Done installing documentation for etc after 0 seconds
Parsing documentation for etc-1.2.0
Done installing documentation for etc after 0 seconds
Gems updated: etc
$ gem outdated
/home/matijs/.rbenv/versions/2.7.2/bin/ruby: symbol lookup error:
  /home/matijs/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/etc-1.2.0/lib/etc.so:
  undefined symbol: rb_deprecate_constant
$ ruby --version
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]

`gem install etc` failing

C:\WINDOWS\system32>gem install etc
Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions. This could take a while...
ERROR:  Error installing etc:
        ERROR: Failed to build gem native extension.

    current directory: C:/Program Files/Ruby31-x64/lib/ruby/gems/3.1.0/gems/etc-1.3.0/ext/etc
C:/Program\ Files/Ruby31-x64/bin/ruby.exe -I C:/Program\ Files/Ruby31-x64/lib/ruby/3.1.0 -r ./siteconf20220325-248-e3vzt4.rb extconf.rb
checking for sys/utsname.h... no
checking for getpwnam() in -lsun... no
checking for uname((struct utsname *)NULL)... no
checking for getlogin()... yes
checking for getpwent()... no
checking for getgrent()... no
checking for sysconf()... no
checking for confstr()... no
checking for fpathconf()... no
checking for struct passwd.pw_gecos in pwd.h... no
checking for struct passwd.pw_change in pwd.h... no
checking for struct passwd.pw_quota in pwd.h... no
checking for struct passwd.pw_age in pwd.h... no
checking for struct passwd.pw_class in pwd.h... no
checking for struct passwd.pw_comment in pwd.h... no
checking for struct passwd.pw_expire in pwd.h... no
checking for struct passwd.pw_passwd in pwd.h... no
checking for struct group.gr_passwd in grp.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/Program Files/Ruby31-x64/bin/$(RUBY_BASE_NAME)
        --with-sys-dir
        --without-sys-dir
        --with-sys-include
        --without-sys-include=${sys-dir}/include
        --with-sys-lib
        --without-sys-lib=${sys-dir}/lib
        --with-sun-dir
        --without-sun-dir
        --with-sun-include
        --without-sun-include=${sun-dir}/include
        --with-sun-lib
        --without-sun-lib=${sun-dir}/lib
        --with-sunlib
        --without-sunlib
extconf.rb:47:in ``': No such file or directory - C:/Program Files/Ruby31-x64/bin/ruby.exe C:/Program Files/Ruby31-x64/lib/ruby/gems/3.1.0/gems/etc-1.3.0/ext/etc/mkconstants.rb -o C:/Program Files/Ruby31-x64/lib/ruby/gems/3.1.0/gems/etc-1.3.0/ext/etc/constdefs.h (Errno::ENOENT)
        from extconf.rb:47:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  C:/Program Files/Ruby31-x64/lib/ruby/gems/3.1.0/extensions/x64-mingw-ucrt/3.1.0/etc-1.3.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in C:/Program Files/Ruby31-x64/lib/ruby/gems/3.1.0/gems/etc-1.3.0 for inspection.
Results logged to C:/Program Files/Ruby31-x64/lib/ruby/gems/3.1.0/extensions/x64-mingw-ucrt/3.1.0/etc-1.3.0/gem_make.out

And here is the mkmf.log.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.