puppet-standalone-mashup/shared/lib/puppet/provider/git/clone.rb
2012-08-14 21:35:41 -04:00

56 lines
1.0 KiB
Ruby

Puppet::Type.type(:git).provide(:clone) do
desc "Clone/pull a git repo"
def create
p ENV
system key_check_command
if $?.exitstatus != 0
system keyscan_command
end
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)
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
command.tap { |o| p o }
end
def path
File.join(@resource[:cwd], @resource[:name])
end
end