puppet-standalone-mashup/shared/lib/puppet/provider/git/clone.rb

54 lines
1013 B
Ruby
Raw Normal View History

2012-04-30 16:02:19 +00:00
Puppet::Type.type(:git).provide(:clone) do
desc "Clone/pull a git repo"
def create
2012-08-15 01:35:41 +00:00
system key_check_command
if $?.exitstatus != 0
system keyscan_command
end
2012-04-30 16:02:19 +00:00
if File.directory?(path)
Dir.chdir(path) { system git_command("pull origin master") }
else
Dir.chdir(@resource[:cwd]) { system git_command("clone #{@resource[:repo]}") }
end
end
def destroy
FileUtils.rm_rf(path) if File.directory?(path)
end
def exists?
false
end
private
def git_command(what)
2012-08-15 01:35:41 +00:00
path_wrap("git #{what}")
end
def keyscan_command
path_wrap("ssh-keyscan -t dsa,rsa #{@resource[:host]} >> ~/.ssh/known_hosts")
end
def key_check_command
path_wrap("ssh-keygen -F #{@resource[:host]}")
end
def path_wrap(command)
command = %{PATH=#{@resource[:path]} #{command}}
if @resource[:user]
command = %{su -c "#{command}" #{@resource[:user]}}
end
2012-04-30 16:02:19 +00:00
2012-08-16 15:37:08 +00:00
command
2012-04-30 16:02:19 +00:00
end
def path
File.join(@resource[:cwd], @resource[:name])
end
end