Skip to content
This repository has been archived by the owner on Jul 2, 2019. It is now read-only.

Commit

Permalink
make project setup support bash
Browse files Browse the repository at this point in the history
  • Loading branch information
danivovich committed Apr 12, 2012
1 parent 88c02c1 commit 7c8a264
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
2 changes: 2 additions & 0 deletions chef-repo/cookbooks/packages/recipes/default.rb
Expand Up @@ -24,6 +24,8 @@
package 'pdftk' package 'pdftk'
package 'xpdf' package 'xpdf'
package 'libgif4' package 'libgif4'
package 'redis-server'
package 'memcached'


package 'libssl0.9.8' # for prince to be happy package 'libssl0.9.8' # for prince to be happy
remote_file '/tmp/prince_8.0-1ubuntu10.04_amd64.deb' do remote_file '/tmp/prince_8.0-1ubuntu10.04_amd64.deb' do
Expand Down
57 changes: 48 additions & 9 deletions chef-repo/cookbooks/projects/recipes/default.rb
Expand Up @@ -3,11 +3,12 @@


projects.each_with_index do |project, index| projects.each_with_index do |project, index|
attributes = data_bag_item('projects', project) attributes = data_bag_item('projects', project)
shell = attributes['shell'] || 'zsh'


home = "/home/#{project}" home = "/home/#{project}"
user(project) do user(project) do
home home home home
shell '/bin/zsh' shell "/bin/#{shell}"
supports :manage_home => true supports :manage_home => true
end end


Expand Down Expand Up @@ -42,14 +43,25 @@
action :install action :install
end end


if shell == 'bash'
execute "clear .bashrc for #{project}" do
user project
group project
cwd home
environment ({'HOME' => home})
command %{rm .bashrc}
action :run
end
end

if attributes['dotfiles'] && attributes['dotfiles']['repo'] && attributes['dotfiles']['init'] if attributes['dotfiles'] && attributes['dotfiles']['repo'] && attributes['dotfiles']['init']
execute "install dotfiles for #{project}" do execute "install dotfiles for #{project}" do
user project user project
group project group project
cwd home cwd home
environment ({'HOME' => home}) environment ({'HOME' => home})
command "git clone #{attributes['dotfiles']['repo']} .dotfiles && cd .dotfiles && ./#{attributes['dotfiles']['init']}" command "git clone #{attributes['dotfiles']['repo']} #{attributes['dotfiles']['install_loc']} && cd #{attributes['dotfiles']['install_loc']} && ./#{attributes['dotfiles']['init']}"
creates "#{home}/.dotfiles" creates "#{home}/#{attributes['dotfiles']['install_loc']}"
action :run action :run
end end
else else
Expand All @@ -66,14 +78,33 @@
action :run action :run
end end


if shell == 'bash'
execute "load rvm into .bashrc for #{project}" do
user project
group project
cwd home
environment ({'HOME' => home})
command %{echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bashrc}
not_if %{grep RVM .bashrc}
action :run
end

template "#{home}/.bash_profile" do
owner project
group project
source "bash_profile.erb"
mode '0644'
end
end

if attributes['ruby_version'] if attributes['ruby_version']
execute "install ruby #{attributes['ruby_version']} for #{project}" do execute "install ruby #{attributes['ruby_version']} for #{project}" do
user project user project
group project group project
cwd home cwd home
environment ({'HOME' => home}) environment ({'HOME' => home})
command "zsh -c 'rvm install #{attributes['ruby_version']}'" command "#{shell} -c 'rvm install #{attributes['ruby_version']}'"
not_if %{zsh -c "rvm list | grep '#{attributes['ruby_version']}'"} not_if %{#{shell} -c "rvm list | grep '#{attributes['ruby_version']}'"}
action :run action :run
end end
end end
Expand All @@ -84,10 +115,8 @@
group project group project
cwd home cwd home
environment ({'HOME' => home}) environment ({'HOME' => home})
command "rvm install #{ruby_version}" command "#{shell} -c 'rvm install #{ruby_version}'"
not_if "rvm list | grep '#{ruby_version}'" not_if %{#{shell} -c "rvm list | grep '#{ruby_version}'"}
command "zsh -c 'rvm install #{ruby_version}'"
not_if %{zsh -c "rvm list | grep '#{ruby_version}'"}
action :run action :run
end end
end end
Expand All @@ -109,6 +138,16 @@
end end


template "#{home}/.zshrc.local" do template "#{home}/.zshrc.local" do
owner project
group project
source "zshrc_local.erb"
mode '0644'
variables :display => "#{99 - index}"
end

template "#{home}/.bashrc.local" do
owner project
group project
source "zshrc_local.erb" source "zshrc_local.erb"
mode '0644' mode '0644'
variables :display => "#{99 - index}" variables :display => "#{99 - index}"
Expand Down
@@ -0,0 +1,3 @@
if [ -f "$HOME/.bashrc" ]; then
source $HOME/.bashrc
fi

0 comments on commit 7c8a264

Please sign in to comment.