class RBT::GenerateShellscript

Constants

DEFAULT_PROGRAM
#

DEFAULT_PROGRAM

#
PATH_TO_THE_FILE_EXTRACT_ARCHIVE
#

PATH_TO_THE_FILE_EXTRACT_ARCHIVE

#

Public Class Methods

new( sdata = nil, save_into_file = true, display_result = true, append_source_file = true ) { || ... } click to toggle source
#

initialize

The first argument, ‘sdata`, should be the whole dataset of the program we wish to create a shell script for. But you can also pass in a program name instead.

The second argument, sdata, passes in the datastructure associated with that very program. It can be omitted however, in which case we will load the data on our own.

Only the first argument is mandatory - the other arguments are not mandatory.

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 52
def initialize(
    sdata              = nil,
    save_into_file     = true,
    display_result     = true,
    append_source_file = true
  )
  reset
  # ======================================================================= #
  # Assign to our variables next.
  # ======================================================================= #
  set_data(sdata) # Also calls set_program().
  set_save_into_file(save_into_file)
  set_append_source_file(append_source_file)
  set_display_result(display_result)
  if block_given?
    _ = yield
    if _.is_a? Hash
      if _.has_key? :also_run_at_once
        set_also_run_at_once _.delete(:also_run_at_once)
      end
    end
  end
  run
end

Public Instance Methods

_(i) click to toggle source
#

_

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 415
def _(i)
  @_ << i
end
_?()
Alias for: string?
dataset()
Alias for: string?
dataset?() click to toggle source
#

dataset?

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 445
def dataset?
  @cookbook_dataset
end
empty_main_string() click to toggle source
#

empty_main_string

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 388
def empty_main_string # Simply empty @_.
  @_ = ''.dup
end
generate_main_string( also_run_at_once = @also_run_at_once ) click to toggle source
#

generate_main_string

This method will generate the shell-string that will be saved and then used.

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 161
def generate_main_string(
    also_run_at_once = @also_run_at_once
  )
  url = url1? # This stores the main URL. Could also use .last_url?
  empty_main_string # Here we empty the variable @_.
  program_version = program_version?
  # ======================================================================= #
  # Next determine where to store the .sh file at hand. It may be a good
  # idea to store it into a subdirectory.
  # ======================================================================= #
  use_this_subdirectory = "#{rbt_log_dir?}shell_scripts/"
  mkdir(use_this_subdirectory)
  location_where_to_store_the_shell_file = use_this_subdirectory+
                                           @program.to_s+'-'+
                                           program_version+'.sh'
  # ======================================================================= #
  # Append roeberia.sh onto that shell file:
  # ======================================================================= #
  if @append_source_file
    _ 'if [ ! -f "$file" ]'+N
    _ 'then'+N
    _ '  source $LINUX/SHELL/SCRIPTS/roeberia.sh'+N
    _ "fi#{N}#{N}"
  end
  # ======================================================================= #
  # Add a nice little header to our shell script..
  # ======================================================================= #
  _ header_for_shell_script
  _ '# === '+@program+N
  _ '#'+N
  _ '# This will attempt to download and install the program '+N
  _ '# called `'+@program+'`.'+N
  _ '#'+N
  _ '# The location of the shell script will be at '+N
  _ '#'+N
  _ '#   '+location_where_to_store_the_shell_file+N
  _ '#'+N
  _ '# This program has the following description:'+N
  description = dataset?.desc?
  description.split(N).each {|line|
    _ '# '+line+N
  } if description.is_a? Array
  _ header_for_shell_script
  function_name = 'compile_'+@program
  _ 'function '+function_name.to_s+'() {'+N
  program_name = program_name?
  _ "  application_name='"+program_name.to_s+"'"+N
  # ======================================================================= #
  # Next, we must set the proper type. By default this is .tar.bz2 but it
  # could also be .tar.xz
  # ======================================================================= #
  _ '  type="'+dataset?.archive_type?.to_s+'"'+N
  # ======================================================================= #
  # Nun das base dir das ein default haben muss:
  # ======================================================================= #
  base_dir = ''.dup
  unless dataset?.base_dir?.empty?
    base_dir << dataset?.base_dir?
  end
  # ======================================================================= #
  # Let's get the source location. For this we must have the proper type.
  # It will equal to something like:
  #
  #   file=/home/x/src/bison/${application_name}${type}
  #
  # ======================================================================= #
  source_location = base_dir+'${application_name}${type}'
  # ======================================================================= #
  # this string is either doit or a full configure
  # Write one URL:
  # ======================================================================= #
  _ '  source '+PATH_TO_THE_FILE_EXTRACT_ARCHIVE+N+N
  # ======================================================================= #
  # Feedback where the remote URL may be found.
  # ======================================================================= #
  _ '  echo "The remote URL can be found at:'+N+N
  _ '    '+url?.to_s+'"'+N+N
  _ N
  _ '  sleep 0.1'+N
  _ N
  # ======================================================================= #
  # Now test whether the file exists at the specified location or not.
  # ======================================================================= #
  _ '  file='+source_location+N+N
  _ '  echo "The file should be at the location:"'+N+N
  _ '  echo "  $file"'+N+N+N
  _ '  if [ -f $file ]'+N
  _ '  then'+N
  _ '    echo "$file exists! Thus we can continue."'+N
  _ '  else'+N
  _ '    echo "$file does not exist."'+N
  _ '    echo "We will thus download it now."'+N
  src_dir = source_directory?
  _ '    cd '+src_dir+N
  target_dir = src_dir+'${'+program_name+'^^*}' # This is the UPCASED version.
  _ '    mkdir '+target_dir+N
  _ '    cd '+target_dir+N
  # ======================================================================= #
  # Add Wget tag.
  # ======================================================================= #
  _ '    wget '+url.to_s+N
  _ '  fi'+N+N
  # ======================================================================= #
  # Next, proceed to extract the Package.
  # ======================================================================= #
  _ '  echo "We will now extract the package into '+temp_dir?+':"'+N+N
  _ '  sleep 0.3'+N
  _ '  extract_archive '+source_location+N
  _ '  echo "Now entering the directory \`'+temp_dir?+'$application_name\`".'+N
  _ '  cd '+temp_dir?+'$application_name '+N
  _ '  pwd'+N
  if dataset?.make_options?
    unless dataset?.make_options?.empty?
      _ '  '+dataset?.make_options?.join(', ').strip+N
    end
  end
  if dataset?.prefix? == true
    _ '  doit'+N
  else # Else false, thus its non-traditional.
    this_configure_line = '  ./configure --prefix=/'+programs_dir?
    if @data
      short_name = short_name?.to_s.capitalize
      this_configure_line << short_name.to_s
      this_configure_line << '/'
      this_configure_line << program_version?
      this_configure_line << ' '+dataset?.configure_options?+N
      this_configure_line << '  make'+N
      this_configure_line << '  make install'+N
    end
    _ '  echo "Running these commands next: `'+
      rds(this_configure_line).strip+'`"'+N
    _ N
    _ rds(this_configure_line)
  end
  _ N
  # ======================================================================= #
  # Report URL again to make sure we know about it.
  # ======================================================================= #
  if ! url.to_s.empty?
    _ '  echo -e "\nIn case you missed it, here is the URL to \`'+
      program_name.to_s+'\`"'+N
    _ '  echo -e "again: "'+N+N
    _ '  echo "  '+url.to_s+'"'+N+N
  end
  # ======================================================================= #
  # Decide whether we should keep the source Package, or whether we should
  # remove it.
  # ======================================================================= #
  _ '  echo "Let us see whether we shall keep the source package"'+N
  _ '  echo "extracted for the program '+program?+' or not, next:"'+N+N
  keep_extracted = dataset?.keep_extracted?
  case keep_extracted.to_s
  when 'true','t'
    _ '  keep_extracted="true"'+N
  else
    _ '  keep_extracted="false"'+N
  end
  _ '  if [ "$keep_extracted" = "true" ]'+N
  _ '  then'+N
  _ '    echo "  Yes, we keep the archive extracted."'+N
  _ '  else'+N
  _ '    echo "Not keeping the archive. Removing it now:"'+N
  _ '    echo rm -rf '+temp_dir?+'$application_name'+N
  _ '    rm -rf '+temp_dir?+'$application_name'+N
  _ '  fi'+N
  # Finish the function here:
  _ '}'+N
  _ header_for_shell_script
  _ '# Next we wil add some aliases to the function:'+N
  _ header_for_shell_script
  _ "alias 'c"+@program+"'=\"compile_"+@program+"\""+N
  _ "alias 'c_"+@program+"'=\"compile_"+@program+"\""+N # also add a c_
  _ N # last but not least add a newline.
  # ======================================================================= #
  # === also_run_at_once
  #
  # Determine whether those scripts run already, or not. Usually we wish
  # to have this, but sometimes, like in batch-generation mode, we do
  # not want to have this.
  # ======================================================================= #
  if also_run_at_once
    _ '# '+('='* 76)+' #'+N
    _ '# We also compile at once.'+N
    _ '# '+('='* 76)+' #'+N
    _ function_name+N
  end
  # ======================================================================= #
  # Finally, save the shell script into a file here.
  # ======================================================================= #
  if @save_into_file
    saving_into(location_where_to_store_the_shell_file)
    if File.exist?(location_where_to_store_the_shell_file)
      remove_file(location_where_to_store_the_shell_file)
    end
    save_file(@_, location_where_to_store_the_shell_file)
  end
  if @display_result
    opne 'Also displaying its content next, for convenience.'
    cliner
    e N+@_ # Newline to properly align the output.
  end
  saved_into(location_where_to_store_the_shell_file) # Added Feb 2012.
  return @_ # Always return the @_ but also keep it stored.
end
header_for_shell_script() click to toggle source
#

header_for_shell_script

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 151
def header_for_shell_script
  '# '+('=' * 75)+' #'+N
end
program?() click to toggle source
#

program?

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 438
def program?
  @program
end
program_name?() click to toggle source
#

program_name?

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 144
def program_name?
  dataset?.program_name?.to_s
end
program_version?() click to toggle source
#

program_version?

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 130
def program_version?
  dataset?.program_version?.to_s
end
report_task() click to toggle source
#

report_task

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 430
def report_task
  opne 'Generating a shell script now for the '+
       'program `'+sfancy(@program)+'`.'
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::LeanPrototype#reset
# File lib/rbt/generate_files/generate_shellscript.rb, line 80
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @program
  # ======================================================================= #
  @program = nil
  # ======================================================================= #
  # === @data
  # ======================================================================= #
  @data = nil
  # ======================================================================= #
  # === @save_into_file
  # ======================================================================= #
  @save_into_file = nil
  # ======================================================================= #
  # === @display_result
  # ======================================================================= #
  @display_result = nil
  # ======================================================================= #
  # === @also_run_at_once
  # ======================================================================= #
  @also_run_at_once = true
  empty_main_string
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 485
def run
  report_task
  generate_main_string
end
saved_into(file) click to toggle source
#

saved_into

This method will inform the user where the file has been saved.

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 454
def saved_into(file)
  cliner {
    opne "The file was saved into: #{sfile(file)}"
  }
end
saving_into(file) click to toggle source
#

saving_into

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 406
def saving_into(file)
  cliner {
    opne "Saving into #{sfile(file)}"
  }
end
set_also_run_at_once(i = true) click to toggle source
#

set_also_run_at_once

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 109
def set_also_run_at_once(i = true)
  @also_run_at_once = i
end
set_append_source_file(i) click to toggle source
#

set_append_source_file

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 116
def set_append_source_file(i)
  @append_source_file = i
end
set_data(i = program?) click to toggle source
#

set_data

Since at least June 2014 we store @data as symbols.

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 465
def set_data(i = program?)
  if i.nil? # If this is nil, then we are trying to call this in a standalone fashion
    # In this case we will make use of @cookbook_dataset.
    @cookbook_dataset = action(:SanitizeCookbook) { :do_not_run_yet }
    @cookbook_dataset.find @program
  elsif i.is_a? String
    @cookbook_dataset = action(:SanitizeCookbook, i)
  elsif i.is_a? RBT::Action::Cookbooks::SanitizeCookbook
    @cookbook_dataset = i
  else # Then we exit here.
    e swarn('Error!'); pp i; exit
  end
  new_name = @cookbook_dataset.short_name?
  set_program(new_name) # We require here that @data is correct.
  @data = @cookbook_dataset
end
set_display_result(i) click to toggle source
#

set_display_result

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 377
def set_display_result(i)
  case i
  when :display_result
    i = true
  end
  @display_result = i
end
set_program(i = DEFAULT_PROGRAM) click to toggle source
#

set_program

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 369
def set_program(i = DEFAULT_PROGRAM) # set @program here.
  i = i.to_s.downcase
  @program = i
end
set_save_into_file(i = true) click to toggle source
#

set_save_into_file

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 395
def set_save_into_file(i = true) # can be true or false.
  case i
  when :save_into_file
    i = true
  end
  @save_into_file = i
end
short_name?() click to toggle source
#

short_name?

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 137
def short_name?
  dataset?.short_name?.to_s
end
string?() click to toggle source
#

string?

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 422
def string? # accessor method towards @_ which is the main string.
  @_
end
Also aliased as: _?, dataset
url1?() click to toggle source
#

url1?

#
# File lib/rbt/generate_files/generate_shellscript.rb, line 123
def url1?
  dataset?.url1?
end
Also aliased as: url?
url?()
Alias for: url1?