class RBT::GenerateShellscript
Constants
- DEFAULT_PROGRAM
#¶ ↑
DEFAULT_PROGRAM
¶ ↑#¶ ↑
- NAMESPACE
#¶ ↑
NAMESPACE
¶ ↑#¶ ↑
- 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/utility_scripts/generate_shellscript.rb, line 55 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
dataset?()
click to toggle source
empty_main_string()
click to toggle source
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/utility_scripts/generate_shellscript.rb, line 149 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=/Users/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 unless dataset?.make_options?.empty? _ ' '+dataset?.make_options?.join(', ').strip+N 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 _ 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 opnn; e '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
program?()
click to toggle source
program_name?()
click to toggle source
program_version?()
click to toggle source
report_task()
click to toggle source
reset()
click to toggle source
run()
click to toggle source
saved_into(file)
click to toggle source
saving_into(file)
click to toggle source
set_also_run_at_once(i = true)
click to toggle source
set_append_source_file(i)
click to toggle source
set_data(i = program?)
click to toggle source
#¶ ↑
set_data
¶ ↑
Since at least June 2014 we store @data as symbols.
#¶ ↑
# File lib/rbt/utility_scripts/generate_shellscript.rb, line 448 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 = RBT::Cookbooks::Cookbook.new { :bypass_menu_check } @cookbook_dataset.find @program elsif i.is_a? String @cookbook_dataset = RBT::Cookbooks::Cookbook.new(i) { :bypass_menu_check } elsif i.is_a? RBT::Cookbooks::Cookbook @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_program(i = DEFAULT_PROGRAM)
click to toggle source
set_save_into_file(i = true)
click to toggle source
short_name?()
click to toggle source
string?()
click to toggle source