简体   繁体   English

使用厨师食谱更新.bashrc

[英]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. 我正在编写使用chef-solo安装jsk的练习方法,我需要更新.bashrc文件来设置JAVA_HOMEPATH变量。 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. 我不明白command %{bash -i -c“source / etc / bash / bashrc && bashrc update”}是什么意思。 thanks 谢谢

First off, /etc/skel/ is the directory that's copied when a new user is created. 首先, /etc/skel/是创建新用户时复制的目录。 Changing the bashrc there will not affect your already existing users, so you maybe you want to change a different file? 更改bashrc不会影响您现有的用户,所以您可能想要更改其他文件?

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 . 其次,注释掉的命令启动一个新的bash shell,并在那个shell中找到/etc/bash/bashrc (重新加载它),然后执行bashrc update I have no idea what that does, it's probably a shell script on your machine? 我不知道那是什么,它可能是你机器上的shell脚本?
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. 第三,您调用content两次,这意味着只有第二行将在该文件中。

What you probably want to do is: 你可能想做的是:

Create a file files/default/bashrc and copy your entire bashrc (including the Java lines) into there. 创建一个文件files/default/bashrc并将整个bashrc(包括Java行)复制到那里。
Replace your code above with: 将上面的代码替换为:

file "/home/whateveruseryouwant/.bashrc" do
  owner "whateveruseryouwant"
  group "whateveruseryouwant"
  source "bashrc"
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM