Load gems programatically?

Hi.
I want to write a script to alter a value in a plist. I know how to do
it but for the script to run i have to install a plist gem like this:
“sudo gem install Plist”.
and then I get prompted for the password…no problem.

I would like to have the script install the gem for me so It can be run
on machines that have a freshly installed OS.
If I put this line in the script " system(“sudo gem install Plist”)
I get asked for the password.

How do I use ruby to enter the password? (the password is always the
same in this case)

On Sun, Jan 22, 2012 at 3:55 PM, John S. [email protected]
wrote:

How do I use ruby to enter the password? (the password is always the
same in this case)

Hmmm, I am thinking of ways to get arount this (I mean: not putting the
password in the script).

  • standard solutions like puppet and Chef have certainly resolved
    this issue

  • Is there any chance that you do not need to install those gems
    with sudo rights, but could suffice with a local install in a user
    directory. E.g. this page

http://docs.rubygems.org/read/chapter/3

shows how to install gems locally:

3.2 Installing RubyGems in a User Directory

  • If that fails, you might also figure out a bash script that does
    what you need to do (it might call a ruby program) and have that
    entire bash script running with real or effective user with root
    permissions.

  • and if you really want to do it as you suggest, you could
    use the -S option of sudo … This is NOT RECOMMENDED !

peterv@ASUS:~$ echo 'x...x' | sudo -S tail -1 /var/log/auth.log Jan 22 16:26:19 ASUS sudo: peterv : TTY=pts/2 ; PWD=/home/peterv ; USER=root ; COMMAND=/usr/bin/tail -1 /var/log/auth.log peterv@ASUS:~$ kill -9 $$

Running off, going to wash my hands,

Peter

There is no security risk. These macs are used for testing software and
we all just use the same user and password, so it doesn’t matter if
people see the password as everyone knows what it is. I want the end
user of the
script to not have to type “sudo gem install Plist” before running the
script.