Class: Shepherd

Inherits:
SphinxModule show all
Defined in:
lib/modules/shepherd.rb

Instance Method Summary collapse

Methods inherited from SphinxModule

#load_configuration, #save_configuration, #setup, #uninstall, #update

Constructor Details

#initializeShepherd

Returns a new instance of Shepherd.



2
3
4
5
6
7
# File 'lib/modules/shepherd.rb', line 2

def initialize
  @config = {
      :version => SphinxTv::VERSION
  }
  load_configuration
end

Instance Method Details

#check(quiet = false) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/modules/shepherd.rb', line 9

def check(quiet = false)
  result = true

  unless File.exists? "/usr/local/share/xmltv"
    result = false
    puts "XMLTV is not installed.".red unless quiet
  end

  unless File.exists? File.join(Etc.getpwuid.dir, ".shepherd")
    result = false
    puts "Shepherd is not installed.".red unless quiet
  end

  puts "Shepherd is OK.".green if result
  result
end

#configureObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/modules/shepherd.rb', line 26

def configure
  shepherd = File.join(Etc.getpwuid.dir, ".shepherd", "shepherd")
  shepherd_download = SphinxTv::download_path("shepherd")
  exit = false
  until exit do
    choose do |menu|
      menu.header = "\nShepherd Configuration".cyan
      menu.prompt = "Select an option: "
      if File.exists? shepherd
        menu.choice("Configure Shepherd") { system("perl #{shepherd} --configure") }
      elsif File.exists? shepherd_download
        menu.choice("Install and Configure Shepherd") { system("perl #{shepherd_download} --configure") }
      end
      menu.choice("Done") {
        exit = true
      }
    end
  end
end

#downloadObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/modules/shepherd.rb', line 46

def download
  doc = Nokogiri::HTML(open('http://sourceforge.net/projects/xmltv/files/xmltv/0.5.63/'))

  url = "http://www.whuffy.com/shepherd/shepherd"
  puts "Downloading Shepherd".cyan
  puts url
  result = Download.url(url, SphinxTv::download_path("shepherd"))

  doc.css('tr.file  a').each do |link|
    if /\.tar\.bz2\/download$/.match(link[:href])
      filename = nil
      filename = "xmltv.tar.bz2" if /xmltv/.match(link[:href])
      if filename
        puts "Downloading #{filename}".cyan
        puts link[:href]
        Download::url(link[:href], SphinxTv::download_path(filename))
      end
    end
  end
end

#installObject



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/modules/shepherd.rb', line 67

def install
  unless check(true)
    download
    install_perl_prerequisites
    install_xmltv unless File.exists? "/usr/local/share/xmltv"

    unless File.exists? "/Library/Perl/5.12/Shepherd"
      puts "Creating symlink for Shepherd/MythTV perl library...".cyan
      home_dir = Etc.getpwuid.dir
      %x[sudo #{SphinxTv::SUDO_PROMPT} ln -s #{home_dir}/.shepherd/references/Shepherd /Library/Perl/5.12]
    end
  end
end

#install_perl_prerequisitesObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/modules/shepherd.rb', line 81

def install_perl_prerequisites

  Cpan::create_config_file

  shepherd_mandatory_perl_modules = "YAML XML::Twig Algorithm::Diff Compress::Zlib Cwd Data::Dumper Date::Manip Getopt::Long \
       List::Compare LWP::UserAgent POSIX Digest::SHA1"

  shepherd_optional_perl_modules = "DateTime::Format::Strptime File::Basename File::Path HTML::Entities \
       HTML::TokeParser HTML::TreeBuilder IO::File Storable Time::HiRes XML::DOM \
       XML::DOM::NodeList XML::Simple Storable HTTP::Cookies File::Basename \
       LWP::ConnCache Digest::MD5 Archive::Zip IO::String \
       DateTime::Format::Strptime \
       HTTP::Cache::Transparent Crypt::SSLeay DBD::mysql "

  perl_modules = shepherd_mandatory_perl_modules.split(" ") + shepherd_optional_perl_modules.split(" ")
  puts "Installing required perl modules...".cyan
  Cpan::install(perl_modules)
end

#install_xmltvObject



100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/modules/shepherd.rb', line 100

def install_xmltv
  puts "Extracting XMLTV...".cyan
  %x[tar -jxf #{SphinxTv::download_path("xmltv.tar.bz2")} -C #{SphinxTv::cache_path}]
  puts "Compiling XMLTV...".cyan
  commands = Array.new.tap do |c|
    c << "cd #{SphinxTv::cache_path}/xmltv*"
    c << "perl Makefile.PL"
    c << "make"
    c << "make test"
    c << "sudo #{SphinxTv::SUDO_PROMPT} make install"
  end
  puts %x[#{commands.join(";")}]
end