Created
May 30, 2013 14:43
-
-
Save cyberswat/5678391 to your computer and use it in GitHub Desktop.
A sample LWRP per #drupal-colorado conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fileutils' | |
require 'tempfile' | |
action :ensure do | |
t_file = Tempfile.new('/root/.profile_temp') | |
::File.open(new_resource.profile, 'r') do |f| | |
f.each_line do |line| | |
if line.match(/PATH=/) | |
if ::File.readlines(new_resource.profile).grep(/:#{new_resource.path.gsub('/','\/')}/).length > 0 | |
t_file.puts line | |
else | |
new_line = line.split("\n")[0] | |
t_file.puts "#{new_line}:#{new_resource.path}\n" | |
end | |
else | |
t_file.puts line | |
end | |
end | |
end | |
FileUtils.mv(t_file.path, new_resource.profile) | |
FileUtils.chmod(0600, new_resource.profile) | |
end | |
action :purge do | |
t_file = Tempfile.new('/root/.profile_temp') | |
::File.open(new_resource.profile, 'r') do |f| | |
f.each_line do |line| | |
if line.match(/PATH=/) | |
t_file.puts line.sub(":#{new_resource.path}",'') | |
else | |
t_file.puts line | |
end | |
end | |
end | |
FileUtils.mv(t_file.path, new_resource.profile) | |
FileUtils.chmod(0600, new_resource.profile) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment