Module: Megam::Install::ClassMethods

Defined in:
lib/megam/install.rb

Instance Method Summary collapse

Instance Method Details

#copy(options, birr_opts) ⇒ Object

now run the stuff in parsed block. eg.pull out the directory and copy it.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/megam/install.rb', line 72

def copy (options, birr_opts)
  cmd = Megam::WorkArea.new(options)

  Birr.text.info(Birr.text.color("DUMP :", :green, :bold) + "dumping directory " + "#{cmd.directory}")

  if cmd.directory_avail?
    from_dir =  Megam::Install.workarea_loader[(File.join(options[:method_name],cmd.directory))]
    to_dir = Megam::TransferArea.convert_to_transferarea_dir(cmd.directory)

    goahead_copy = Birr.text.agree("Do you wish to copy files from #{from_dir}\n to #{to_dir} [y/n]?")

    if Dir.exists?(from_dir) && goahead_copy
      #formulate the shell cp command, and returns it. now feed it to shelly and execute it.
      cp_opts = { :from_dir => from_dir,
        :to_dir => to_dir,
        :sudo => birr_opts.sudo?,
        :recursive => true,
        :copy_on_new => true}
      birr_opts.command(Megam::CmdVerb.cp(cp_opts))
      options[:message] = ''
      shelly(options,birr_opts)
    else
      unless goahead_copy
        then
        Birr.text.warn "Skip : OK."
      else
        Birr.text.fatal "Skip : You need to specify an existing #{from_dir}\n in the :directory option to dump"

      end
    end
  end
end

#dump(options = {}, &block) ⇒ Object

default parms del_if_exists is false message prints a dump directory string



29
30
31
32
33
34
35
# File 'lib/megam/install.rb', line 29

def dump(options = {},&block)
  if block_given?
    birr_opts = BirrOptions.new(&block)
    options[:method_name] = __method__.to_s
    copy(options,birr_opts)
  end
end

#install(options = {}, &block) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/megam/install.rb', line 48

def install(options = {},&block)
  if block_given?
    birr_opts = BirrOptions.new(&block)
    cmd = Megam::WorkArea.new(options)
    options[:method_name] = __method__.to_s
    shelly(options,birr_opts)
  end
end

#script(options = {}, &block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/megam/install.rb', line 37

def script(options = {},&block)
  if block_given?
    birr_opts = BirrOptions.new(&block)
    cmd = Megam::WorkArea.new(options)
    options[:method_name] = "package"
    key =  Megam::Install.workarea_loader[(File.join(options[:method_name],cmd.directory))]
    birr_opts.command(cmd.find_package_script(options[:method_name]+'.'+cmd.directory, birr_opts.commands).fetch(key))
    shelly(options,birr_opts)
  end
end

#shelly(options = {}, birr_opts) ⇒ Object

now run the stuff in parsed block. eg.pull out the command and run it.



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/megam/install.rb', line 107

def shelly (options ={},birr_opts)
  msg = ''
  msg            = options[:message] if options[:message]
  Birr.text.info(Birr.text.color("INSTALL :", :green, :bold) + msg.to_s) unless !msg.strip
  command ||= birr_opts.commands
  unless !BirrOptions.method_defined?(:command)
    command.each do |scmd|
      Birr.text.info(Birr.text.color("SHELL   :", :cyan, :bold) + scmd.to_s)
      find = Mixlib::ShellOut.new(scmd.strip)
      find.run_command
      Birr.text.info find.stdout
      find.error!
    end
  end
end

#tarball(options = {}, &block) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/megam/install.rb', line 57

def tarball(options = {},&block)
  if block_given?
    birr_opts = BirrOptions.new(&block)
    cmd = Megam::WorkArea.new(options)
    options[:method_name] = __method__.to_s
    tar_dir =  Megam::Install.workarea_loader[(File.join(options[:method_name],cmd.directory.gsub(".", File::SEPARATOR)))]

    tmp_opts = {:tar_file => File.join(tar_dir,birr_opts.tarball_file), :to_dir =>  Megam::TransferArea.convert_to_transferarea_dir(cmd.directory) }
    birr_opts.command(Megam::CmdVerb.untar(tmp_opts))
    shelly(options, birr_opts)
  end
end