aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Formula/sickbeard.rb
blob: d6a5a773bdee4f1ae1b4ec78efe149685cee1aca (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
81
require 'formula'

class Sickbeard < Formula
  url 'https://github.com/midgetspy/Sick-Beard/tarball/build-488'
  homepage 'http://www.sickbeard.com/'
  md5 '3bdcabe963e2622513f3cca2757fa2f0'

  head 'git://github.com/midgetspy/Sick-Beard.git'

  depends_on 'Cheetah' => :python

  def install
    prefix.install Dir['*']
    bin.mkpath
    (bin+"sickbeard").write(startup_script)
    (prefix+"com.sickbeard.sickbeard.plist").write(startup_plist)
  end

  def startup_plist; <<-EOS.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>Label</key>
      <string>com.sickbeard.sickbeard</string>
      <key>ProgramArguments</key>
      <array>
           <string>#{bin}/sickbeard</string>
           <string>-q</string>
           <string>--nolaunch</string>
           <string>-p</string>
           <string>8081</string>
      </array>
      <key>RunAtLoad</key>
      <true/>
      <key>UserName</key>
      <string>#{`whoami`.chomp}</string>
    </dict>
    </plist>
    EOS
  end

  def startup_script; <<-EOS.undent
    #!/usr/bin/env ruby

    me = begin
      File.expand_path(
        File.join(
          File.dirname(__FILE__),
          File.readlink(__FILE__)
        )
      )
    rescue
      __FILE__
    end

    path = File.join(File.dirname(me), '..', 'SickBeard.py')
    args = ["--pidfile=#{var}/run/sickbeard.pid", "--datadir=#{etc}/sickbeard"]

    exec("python", path, *(args + ARGV))
    EOS
  end

  def caveats; <<-EOS.undent
    SickBeard will start up and launch http://localhost:8081/ when you run:

        sickbeard

    To launch automatically on startup, copy and paste the following into a terminal:

        mkdir -p ~/Library/LaunchAgents
        (launchctl unload -w ~/Library/LaunchAgents/com.sickbeard.sickbeard.plist 2>/dev/null || true)
        ln -sf #{prefix}/com.sickbeard.sickbeard.plist ~/Library/LaunchAgents/com.sickbeard.sickbeard.plist
        launchctl load -w ~/Library/LaunchAgents/com.sickbeard.sickbeard.plist

    You may want to edit:
      #{prefix}/com.sickbeard.sickbeard.plist
    to change the port (default: 8081) or user (default: #{`whoami`.chomp}).
    EOS
  end
end