aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Formula/luciddb.rb
blob: 47aab716cf0879fc15adbf68000f4fc6a010c2cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
require 'formula'

class Luciddb < Formula
  homepage 'http://www.luciddb.org/'
  url 'http://sourceforge.net/projects/luciddb/files/luciddb/luciddb-0.9.4/luciddb-bin-macos32-0.9.4.tar.bz2'
  sha1 'b0a7b9dbe997a1754d48856c866ffedf4d276eae'

  def shim_script target
    <<-EOS.undent
      #!/bin/bash
      export JAVA_HOME=`/usr/libexec/java_home`
      exec "#{libexec}/bin/#{target}" "$@"
    EOS
  end

  def install
    java_home = `/usr/libexec/java_home`.chomp!
    libexec.install Dir['*']
    cd libexec/'install' do
      # install.sh just sets Java classpaths and writes them to bin/classpath.gen.
      # This is why we run it /after/ copying all the files to #{libexec}.
      ENV['JAVA_HOME'] = java_home
      system "./install.sh"
    end
    Dir["#{libexec}/bin/*"].each do |b|
      next if b =~ /classpath.gen/ or b =~ /defineFarragoRuntime/
      n = Pathname.new(b).basename
      (bin+n).write shim_script(n)
    end
    plist_path.write luciddb_startup_plist(java_home)
    plist_path.chmod 0644
  end

  def luciddb_startup_plist(java_home); <<-EOPLIST.undent
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
      <key>KeepAlive</key>
      <true/>
      <key>Label</key>
      <string>#{plist_name}</string>
      <key>UserName</key>
      <string>#{`whoami`.chomp}</string>
      <key>EnvironmentVariables</key>
      <dict>
        <key>JAVA_HOME</key>
        <string>#{java_home}</string>
      </dict>
      <key>ProgramArguments</key>
      <array>
        <string>#{libexec}/bin/lucidDbServer</string>
      </array>
      <key>RunAtLoad</key>
      <true/>
      <key>WorkingDirectory</key>
      <string>#{libexec}</string>
      <key>StandardOutPath</key>
      <string>/dev/null</string>
    </dict>
    </plist>
    EOPLIST
  end

  def caveats; <<-EOS.undent
    If this is your first install:
      mkdir -p ~/Library/LaunchAgents
      cp #{plist_path} ~/Library/LaunchAgents/
      launchctl load -w ~/Library/LaunchAgents/#{plist_path.basename}

    If this is an upgrade and you already have the #{plist_path.basename} loaded:
      launchctl unload -w ~/Library/LaunchAgents/#{plist_path.basename}
      cp #{plist_path} ~/Library/LaunchAgents/
      launchctl load -w ~/Library/LaunchAgents/#{plist_path.basename}

    Or start the server manually by typing:
      lucidDbServer
   EOS
 end
end