LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-16-2013, 09:45 AM   #1
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
ruby IF question


Good morning,

Im working on a chef plugin, that i did not write, and I realize that it needs an IF statement.

Pseduo:
If user root, then home is /root/
else
home is /home/$user

Im not a programmer at all so im not sure how much code to include, but this seems like the important section. Any takers for fixing this snippet for me?

Code:
  user  = params[:name]
  group = params[:group] || user
  home  = params[:home]  || "/home/#{user}"
  keys  = data_bag params[:keys]
 
Old 07-16-2013, 11:12 AM   #2
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
Quote:
Originally Posted by szboardstretcher View Post
Code:
home  = params[:home]  || "/home/#{user}"
That looks fine, assuming that params won't have a :home key (i.e. params[:home] will be nil) if you don't want to use it. What's wrong with it? I.e. what behavior do you expect from it, and what are you getting instead?

Although note that if you're only dealing with the current user, you should normally just use ENV['HOME'] as their home directory, as that will (i) be easier for you and (ii) cover weird/unusual configurations, and (iii) be nil/the empty string (not sure which) if the user has no home directory configured.
 
1 members found this post helpful.
Old 07-16-2013, 11:23 AM   #3
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Original Poster
Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
excellent. thank you for the input.

https://github.com/skalar-cookbooks/authorized_keys

I got the plugin from this place. So i dont understand what its actually doing - except that its automatically assuming roots home folder is /home/root.

I've since found the chef documentation that explains how to distribute ssh keys without plugins here:

https://opscode.app.box.com/shared/b0lmhnhn09

If anyone finds this thread looking for ssh key distribution in chef, this is the guide you will need.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ruby-question - a newbie-question sayhello_to_the_world Programming 1 06-23-2013 08:44 AM
Any issues installing Ruby Gems and Ruby on Rails in Slackware? Lufbery Slackware 8 02-09-2011 07:22 PM
Ruby SDL/ Ruby OpenGL tutorials/reference? LinuxNoob75 Programming 0 12-30-2007 12:47 PM
PHP v Ruby/Ruby on Rails Neko_D Linux - General 4 02-08-2007 11:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration