postgres_real_path = "@PATH_TEMPLATE@"
PLIST_BUDDY = "/usr/libexec/PlistBuddy"
config_file_index = ARGV.index("--apple-configuration")
if !config_file_index.nil?
config_path = ARGV[config_file_index + 1]
if config_path.nil?
puts "Error: missing required argument for --apple-configuration"
exit(1)
end
ARGV.delete_at(config_file_index+1)
ARGV.delete_at(config_file_index)
if !FileTest.exists?(config_path)
puts "Error: missing configuration file at #{config_path}"
exit(1)
end
config_lines = `#{PLIST_BUDDY} -c 'Print :ProgramArguments' #{config_path}`
config_lines.each do |line|
if (line =~ /^Array \{/) || (line =~ /^\}/)
next
end
line.chomp!
line = line.sub(/^\s+/, '')
ARGV.push(line)
end
end
dataPathArgIndicatorIndex = ARGV.index("-D")
if !dataPathArgIndicatorIndex.nil?
dataPathArg = ARGV[dataPathArgIndicatorIndex + 1]
system("/bin/wait4path", dataPathArg) unless dataPathArg.nil?
end
nargv = ["#{postgres_real_path}", ARGV].flatten
exec(*nargv)
exit(0)