Created
April 30, 2013 15:13
-
-
Save alexsparrow/5489369 to your computer and use it in GitHub Desktop.
Homebrew formula exhibiting hanging system call
This file contains hidden or 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 'formula' | |
require 'find' | |
require 'version' | |
class MyFormula < Formula | |
BASEDIR=File.dirname(Pathname.new(__FILE__).realpath) | |
def self.init | |
homepage 'www.foo.com' | |
keg_only "We don't need all the stuff on the PATH" | |
depends_on 'foo/brew/postgis-15' | |
depends_on 'foo/brew/jdbc-postgres' | |
depends_on 'foo/brew/qs-tool' | |
option 'dont-touch-db', 'Leave the database alone. Should only be used if you have already setup the DB.' | |
end | |
def init_postgres | |
postgres_dir = var/'postgres' | |
stop_postgres | |
if Dir[postgres_dir].empty? | |
mkdir postgres_dir | |
chmod 0755, postgres_dir | |
else | |
ohai "Postgres data directory appears to exist. Skipping initialization." | |
return | |
end | |
begin | |
system "initdb #{postgres_dir}" | |
rescue BuildError | |
opoo 'Failed to initialise DB' | |
end | |
end | |
def start_postgres | |
postgres_dir = var/'postgres' | |
begin | |
system "pg_ctl -w -D #{postgres_dir} -l #{postgres_dir/'server.log'} status" | |
rescue BuildError | |
ohai "Postgres server not running" | |
end | |
begin | |
system "pg_ctl -w -D #{postgres_dir} -l #{postgres_dir/'server.log'} start" | |
rescue BuildError | |
ofail 'Failed to start the Postgres server.' | |
end | |
end | |
def stop_postgres | |
postgres_dir = var/'postgres' | |
begin | |
system "pg_ctl -w -D #{postgres_dir} -m fast stop" | |
rescue BuildError | |
ohai "Failed to stop the Postgres server, maybe it wasn't running." | |
end | |
sleep(5.0) | |
end | |
def create_db(dbname) | |
begin | |
system "dropdb -h localhost #{dbname}" | |
rescue BuildError | |
ohai 'Slight problem with postgres. Probably OK tho...' | |
end | |
system "createdb -h localhost #{dbname}" | |
end | |
def patch_sql | |
inreplace 'sql/postgis.sql' do |s| | |
s.gsub! /LANGUAGE '(.*)'/, 'LANGUAGE \1' | |
end | |
end | |
def run_sql(dbname, fname) | |
cd 'sql/dev' | |
system "psql #{dbname} -h localhost -f #{fname}" | |
cd '../..' | |
end | |
def install | |
MyFormula.const_set("NAME", "prod#{version.to_s.delete('.')}") | |
ENV['NAME'] = NAME | |
ohai "$NAME = #{ENV['NAME']}" | |
# Hook up a suitable JRE | |
unless ENV.has_key? 'JAVA_HOME' | |
java_home = `/usr/libexec/java_home`.strip | |
ohai "Guessing $JAVA_HOME = #{java_home}" | |
ENV['JAVA_HOME'] = java_home | |
end | |
system "ln -fhs #{ENV['JAVA_HOME']} #{prefix}/jre" | |
patch_sql | |
# .prefs files | |
fix_prefs | |
# Clean non-Mac files. | |
Find.find('.') do |f| | |
['\.bat$', '\.dll$', '\.exe$', '\.so$', '\.sl$', '\.a$'].each do |pattern| | |
rm f if f.match pattern | |
end | |
end | |
# Start Postgres and create DB | |
unless build.include? 'dont-touch-db' | |
init_postgres | |
start_postgres | |
create_db NAME | |
run_sql(NAME, 'run_all_dev_postgres.sql') | |
end | |
generate_keys | |
# Install files | |
prefix.install Dir['*'] | |
end | |
def fix_prefs | |
end | |
# Default keys for this release have already expired, regenerate newer ones. | |
def generate_keys | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment