Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

updating .bashrc using chef recipes

i am writing practice recipe for installing jsk using chef-solo, i need to update .bashrc file to set JAVA_HOME and PATH variables. i don't know how to do it. can anyone tell me how to do it. some of my code is..

file "/home/user/.bashrc" do
    owner   "root"
    #something goes here.... i don't know what. but i write
    #%{bash -i -c "source /etc/bash/bashrc && bashrc update"}

    content "JAVA_HOME=/usr/java/jdk1.1.0.05"
    content "PATH=$PATH:JAVA_HOME/bin"

  end

i do not understand what does command%{bash -i -c "source /etc/bash/bashrc && bashrc update"}mean. thanks

like image 431
itsme Avatar asked Oct 06 '22 21:10

itsme


1 Answers

First off, /etc/skel/ is the directory that's copied when a new user is created. Changing the bashrc there will not affect your already existing users, so you maybe you want to change a different file?

Second, the commented out command starts a new bash shell, and in that shell sources /etc/bash/bashrc (to reload it), and then does bashrc update. I have no idea what that does, it's probably a shell script on your machine?
And why do you want to call that? It doesn't even reference the file you change.

Thirdly, you call content twice, which means only the second line will be in that file.

What you probably want to do is:

Create a file files/default/bashrc and copy your entire bashrc (including the Java lines) into there.
Replace your code above with:

file "/home/whateveruseryouwant/.bashrc" do
  owner "whateveruseryouwant"
  group "whateveruseryouwant"
  source "bashrc"
end
like image 69
Nils Landt Avatar answered Oct 13 '22 12:10

Nils Landt