git.rake revision f6fd701c750b47c6c58a23b784d5b890317340a2
816bf6f8088b162b681101d93fd450127a0e586fJulian Kornbergernamespace :git do
816bf6f8088b162b681101d93fd450127a0e586fJulian Kornberger def reconfigure_cp_keys(source_file)
816bf6f8088b162b681101d93fd450127a0e586fJulian Kornberger data_root = Ontohub::Application.config.data_root
816bf6f8088b162b681101d93fd450127a0e586fJulian Kornberger git_home = Ontohub::Application.config.git_home
816bf6f8088b162b681101d93fd450127a0e586fJulian Kornberger
816bf6f8088b162b681101d93fd450127a0e586fJulian Kornberger reconfigured_source = File.read(source_file).
816bf6f8088b162b681101d93fd450127a0e586fJulian Kornberger sub(/^#define DATA_ROOT .*$/, "#define DATA_ROOT \"#{data_root}\"").
816bf6f8088b162b681101d93fd450127a0e586fJulian Kornberger sub(/^#define GIT_HOME .*$/, "#define GIT_HOME \"#{git_home}\"")
816bf6f8088b162b681101d93fd450127a0e586fJulian Kornberger
816bf6f8088b162b681101d93fd450127a0e586fJulian Kornberger reconfigured_source_file = Tempfile.new(%w(cp_keys .c))
816bf6f8088b162b681101d93fd450127a0e586fJulian Kornberger reconfigured_source_file.write(reconfigured_source)
816bf6f8088b162b681101d93fd450127a0e586fJulian Kornberger reconfigured_source_file.close
816bf6f8088b162b681101d93fd450127a0e586fJulian Kornberger puts "Copying #{source_file} to tempfile #{reconfigured_source_file.path}"
816bf6f8088b162b681101d93fd450127a0e586fJulian Kornberger puts "Reconfiguring DATA_ROOT in this tempfile to #{data_root}"
816bf6f8088b162b681101d93fd450127a0e586fJulian Kornberger puts "Reconfiguring GIT_HOME in this tempfile to #{git_home}"
816bf6f8088b162b681101d93fd450127a0e586fJulian Kornberger
reconfigured_source_file
end
def compile_gcc(source_path, target_path)
command = ['gcc', source_path, '-o', target_path]
puts "Compiling #{target_path.split('/').last} with"
puts command.map { |c| c.match(/\s/) ? "'#{c}'" : c }.join(' ')
system(*command)
end
def remove_symbols(target_path)
command = ['strip', target_path]
puts 'Removing symbols with'
puts command.map { |c| c.match(/\s/) ? "'#{c}'" : c }.join(' ')
system(*command)
end
def set_permissions(mode, path, owner_group)
command_chmod = ['chmod', mode, path]
puts 'Changing owner with'
puts command_chmod.map { |c| c.match(/\s/) ? "'#{c}'" : c }.join(' ')
system(*command_chmod)
puts "You need to manually set the owner/group of '#{path}' to #{owner_group}"
end
desc 'Compile cp_keys binary'
task :compile_cp_keys => :environment do
source_file = Rails.root.join('script', 'cp_keys.c')
target_path = Rails.root.join('bin', 'cp_keys').to_s
reconfigured_source_tempfile = reconfigure_cp_keys(source_file)
compile_gcc(reconfigured_source_tempfile.path, target_path)
remove_symbols(target_path)
set_permissions('4500', target_path,
'the git user and the webserver-running group.')
reconfigured_source_tempfile.unlink
end
desc 'Create authorized_keys file and set its permissions'
task :prepare_authorized_keys => :environment do
SSH_DIR = Ontohub::Application.config.data_root.join('.ssh')
AUTHORIZED_KEYS = SSH_DIR.join('authorized_keys')
SSH_DIR.mkpath
if !File.exists?(AUTHORIZED_KEYS)
puts "Creating the file #{AUTHORIZED_KEYS}."
FileUtils.touch(AUTHORIZED_KEYS)
set_permissions('0640', AUTHORIZED_KEYS.to_s,
'the webserver-running user.')
end
end
end