libraries/helpers.rb
# If a user is logged in, /dev/console is always owned by them. Returns the
# username.
If a user is logged in, /dev/console is always owned by them. Returns the
username.
If a user is logged in / dev / console is always owned by them . Returns the username .
def uid_user
  if node['platform'] == 'mac_os_x'
    user_uid = File.stat('/dev/console').uid
    require 'etc'
    Etc.getpwuid(user_uid).name
  else 
    id_output = Mixlib::ShellOut.new('id -un')
    id_output.run_command
    unless id_output.error? 
      id_output.stdout.strip
    else
      ''
    end
  end
end
def uid_user if node [ 'platform' ] == 'mac_os_x' user_uid = File . stat ( '/dev/console' ) . uid require 'etc' Etc . getpwuid ( user_uid ) . name else id_output = Mixlib :: ShellOut . new ( 'id -un' ) id_output . run_command unless id_output . error? id_output . stdout . strip else '' end end end
If a user is logged in, /dev/console is always owned by them.
If a user is logged in / dev / console is always owned by them .
# Required to allow testing in Travis CI (Linux). Otherwise not used # Will only return stdout if no error