Skip to content

Instantly share code, notes, and snippets.

Created Feb 21, 2012
Embed
What would you like to do?
cpanm recipes
define :local_lib_for_user, :user => nil do
filename = "/etc/profile.d/perl-lib-#{params[:user]}.sh"
cpan_module 'local::lib' do
user params[:user]
end
script "perl-lib-#{params[:user]}" do
interpreter "bash"
creates filename
code <<-EOF
echo 'if [ `whoami` = "#{params[:user]}" ]; then' > #{filename}
env HOME=/home/#{params[:user]} perl -Mlocal::lib >> #{filename}
echo 'fi' >> #{filename}
chown -R #{params[:user]} /home/#{params[:user]}
EOF
end
file filename do
owner 'root'
mode 0755
end
end
define :cpan_module, :force => nil, :user => 'root', :env => {} do
execute "install-#{params[:name]}" do
if params[:user] != 'root'
params[:opts] = '-l ~/perl5'
params[:env]['HOME'] = "/home/#{params[:user]}"
not_if "sh -l -c \"perl -m#{params[:name]} -e ''\"", :user => params[:user], :environment => params[:env]
else
not_if "perl -m#{params[:name]} -e ''"
end
if params[:force]
command "cpanm #{params[:opts]} -f #{params[:name]}"
else
command "cpanm #{params[:opts]} #{params[:name]}"
end
environment params[:env]
user params[:user]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment