Class: Roebe::SetupChrootedEnvironment

Inherits:
Base show all
Defined in:
lib/roebe/classes/setup_chrooted_environment.rb

Overview

Roebe::SetupChrootedEnvironment

Constant Summary collapse

ARRAY_COMPILE_THESE_PROGRAMS =
#

ARRAY_COMPILE_THESE_PROGRAMS

The order should be kept because we will also compile in precisely that manner - first to come here in this Array will also be the first that is to be compiled.

There is an empty line in this array - this is deliberate. Programs past that point are mostly convenience addons, not completely mandatory.

#
%w(
  binutils
  coreutils
  bash
  diffutils
  yaml
  ruby
  gmp
  mpc
  sed
  grep
  xterm
  nano
  make
  libtool
  gcc

  tcl
  expect
  dejagnu
  ffmpeg
  libva
)
ARRAY_CREATE_THESE_DIRECTORIES =
#

ARRAY_CREATE_THESE_DIRECTORIES

The leading / can be and should be omitted.

#
%w(
  etc/ lib/ usr/ bin/ dev/ gems/
  dev/ proc/ sys/
  AUTOGENERATED/
  usr/share/ usr/bin usr/lib usr/share/terminfo/
  Depot/ Depot/j Depot/jj Depot/jjj Depot/jjjj
  Depot/Temp/
  System/
  System/Index/bin
  System/Index/lib
)
TARGET_DIRECTORY =
#

TARGET_DIRECTORY

#
'/Depot/Chroot/'
RUBY_GEM_DIRECTORY =
#

RUBY_GEM_DIRECTORY

#
"#{HOME_DIRECTORY_OF_USER_X}SRC/ruby/gems/"

Constants inherited from Base

Base::COLOURS, Base::HOME_DIRECTORY_OF_USER_X, Base::N, Base::NAMESPACE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#actions, #append_this_onto_that_file, #append_what_into, #be_silent, #be_verbose?, #beautiful_url, #burlywood, #call_next, #chdir, #cheerful_guy, #cliner, #complex_esystem, #convert_global_env, #copy_directory, #cornflowerblue, #create_directory, #crimson, #current_month?, #current_time?, #current_year?, #cyan, #darkcyan, #darkgreen, #darkkhaki, #darkslateblue, #deeppink, #delete_symlink, #do_not_use_the_base_colours, #do_use_the_base_colours, #e, #ecomment, #editor_to_use?, #efancy, #eimp, #emphasis, #ensure_main_encoding, #ensure_utf_encoding, #eparse, #erev, #esteelblue, #etomato, #ewarn, #exit_program, #firebrick, #get_current_day, #get_current_month, #get_files_and_directories, #get_files_from, #get_german_name_for_this_weekday, #gold, #green, #grey, #hh_mm_ss, #hh_mm_ss_day_month_year, #home_dir?, #home_directory_of_user_x?, #infer_the_namespace, #internal_hash?, #is_a_directory?, #is_a_file?, #is_a_jpg_file?, #is_an_image_file?, #is_archive?, #is_audio_file?, #is_in_studium_dir?, #is_multimedia_file?, #is_on_roebe?, #is_on_windows?, #is_studium_available?, #is_symlink?, #is_this_a_ruby_file?, #is_video_file?, #iso_encoding?, #le, #left_colour, #lightblue, #lightgreen, #lightseagreen, #lightsteelblue, #lime, #limegreen, #localhost_to_data, #log_directory?, #main_encoding?, #mediumorchid, #mediumpurple, #mediumseagreen, #mediumslateblue, #mediumspringgreen, #mediumturquoise, #mkdir_p, #mv, #n_days_in_this_month, #n_pages_in_this_pdf_file?, #namespace?, #no_file_exists_at, #ogrey, #olive, #olivedrab, #open_in_browser, #opne, #opnesystem, #opnn, #orange, #orchid, #orev, #palegoldenrod, #palevioletred, #pink, #powderblue, #programs_dir?, #project_base_dir?, #random_html_colour, #rds, #read_file_in_iso_encoding, #read_file_via_the_default_encoding, #read_lines_via_iso_encoding, #readlines_with_main_encoding, #red, #register_sigint, #remove, #remove_file, #rename_kde_konsole_tab, #replace_localhost_with_data, #report_pwd, #require_rescue, #reset_the_internal_hash, #return_all_directories_from_this_directory, #return_all_files_from_this_directory, #return_current_directory, #return_dd_mm_yyyy, #return_file_or_directory_of, #return_files_from_pwd, #return_last_part_of_the_current_directory, #return_utc, #rev, #right_arrow?, #right_colour, #roebe_log_directory?, #rosybrown, #royalblue, #ruby_base_directory?, #run_in_background, #run_rcfiles_then_run_ata_via_qdbus, #sandybrown, #sdir, #seagreen, #set_be_verbose, #set_xorg_buffer, #sfancy, #sfile, #show_help, #silent_redirection?, #simp, #simple_esystem, #skyblue, #slateblue, #slategray, #springgreen, #steelblue, #string_italic, #swarn, #symlink, #teal, #temp_dir?, #to_camelcase, #to_counted_hash, #tomato, #touch, #try_to_require_the_beautiful_url_gem, #try_to_require_the_html_template, #try_to_require_the_open_gem, #try_to_require_the_program_information_gem, #try_to_require_the_xorg_buffer, #use_colours?, #verbose_truth, #weekday?, #word_wrap, #write_what_into, #yellow

Methods included from Base::CommandlineArguments

#append_onto_the_commandline_arguments, #clear_commandline_arguments, #commandline_arguments?, #commandline_arguments_as_string?, #commandline_arguments_without_leading_hyphens?, #first_argument?, #first_argument_without_leading_hyphens?, #has_an_argument_been_passed?, #remove_hyphened_arguments_from_the_commandline_arguments, #return_commandline_arguments_with_leading_hyphens, #second_argument?, #set_commandline_arguments

Constructor Details

#initialize(i = nil, run_already = true) ⇒ SetupChrootedEnvironment

#

initialize

#


99
100
101
102
103
104
105
106
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 99

def initialize(
    i           = nil,
    run_already = true
  )
  reset
  set_input(i)
  run if run_already
end

Class Method Details

.[](i = '') ⇒ Object

#

[]

#


247
248
249
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 247

def self.[](i = '')
  new(i)
end

Instance Method Details

#build_my_custom_gemsObject

#

build_my_custom_gems

#


371
372
373
374
375
376
377
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 371

def build_my_custom_gems
  target = main_dir?+'MyGems'
  mkdir(target)
  target_dir = Roebe.build_all_my_local_gems
  files = Dir[target_dir+'*.gem']
  files.each {|file| copy_file(file, target) }
end

#compile(compile_this_program) ⇒ Object

#

compile

#


151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 151

def compile(compile_this_program)
  use_this_prefix = main_prefix?
  show_header(compile_this_program)
  case compile_this_program
  when 'binutils'
    use_this_prefix << ' 

--with-sysroot='+main_target?+'
--with-lib-path='+main_target?+'lib
--disable-nls

'.tr(N,' ')
  when 'ruby'
    ensure_non_static_cflags
    copy_all_gems # Yes, we can copy the gems prior to compiling ruby.
    build_my_custom_gems
    use_this_prefix = main_prefix?+'/Programs/Ruby/2.3.1' # Use another ruby-prefix.
  end
  _ = RBT::Installer.new(compile_this_program, :dont_run_yet)
  _.menu(use_this_prefix)
  _.run
end

#compile_the_required_programsObject

#

compile_the_required_programs

Batch-compile several programs here - all of which were defined in an Array constant on the top of this file.

#


328
329
330
331
332
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 328

def compile_the_required_programs
  ARRAY_COMPILE_THESE_PROGRAMS.each {|compile_this_program|
    compile(compile_this_program)
  }
end

#copy_all_gemsObject

#

copy_all_gems

#


209
210
211
212
213
214
215
216
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 209

def copy_all_gems
  _ = main_target?+'gems/'
  mkdir(_)
  files = Dir[RUBY_GEM_DIRECTORY+'*.gem']
  files.each {|entry|
    copy_file(entry, _) if File.file? entry
  }
end

#copy_file(from, to) ⇒ Object

#

copy_file

#


196
197
198
199
200
201
202
203
204
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 196

def copy_file(from, to)
  if from.is_a? Array
    from.each {|inner_from|
      copy_file(inner_from, to)
    }
  else
    FileUtils.cp(from, to) unless File.directory? from
  end
end
#
#


254
255
256
257
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 254

def copy_libc_related_files_and_other_mandatory_files
  files = Dir['/lib/*']
  copy_file(files, main_dir?+'lib/')
end

#create_bashrc_fileObject

#

create_bashrc_file

#


337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 337

def create_bashrc_file
  what = "
set +h
umask 022
LC_ALL=POSIX

export LD_LIBRARY_PATH=/System/Index/lib

PATH=/System/Index/bin:/bin:/usr/bin

export LC_ALL PATH

. /AUTOGENERATED/aliases_rc
. /AUTOGENERATED/cd_aliases_rc

"
  into = target_dir?+'root/.bashrc'
  mkdir(File.dirname(into)) # Must ensure that the directory exists.
  .write_what_into(what, into)
end
#
#


290
291
292
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 290

def create_bin_sh_symlink
  _ = 'ln -s '+main_dir?+'bin/sh '+main_dir?+'bin/bash'
end

#create_dev_nullObject

#

create_dev_null

#


309
310
311
312
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 309

def create_dev_null
  _ = 'mknod -m 666 '+main_dir?+'/dev/null c 1 3'
  esystem _
end

#create_directory_skeletonObject

#

create_directory_skeleton

#


262
263
264
265
266
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 262

def create_directory_skeleton
  ARRAY_CREATE_THESE_DIRECTORIES.each {|entry|
    mkdir(main_target?+entry)
  }
end

#create_mount_pointsObject

#

create_mount_points (mount tag)

#


297
298
299
300
301
302
303
304
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 297

def create_mount_points
  _ = 'mount -o bind /dev '+main_dir?+'dev'
  esystem _
  _ = 'mount -o bind /proc '+main_dir?+'proc'
  esystem _
  _ = 'mount -t sysfs sysfs '+main_dir?+'sys'
  esystem _
end

#ensure_non_static_cflagsObject

#

ensure_non_static_cflags

#


177
178
179
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 177

def ensure_non_static_cflags
  ENV['CFLAGS'] = '-O2 -fPIC -fno-strict-overflow -Wno-error'
end

#ensure_that_the_target_directory_existsObject

#

ensure_that_the_target_directory_exists

#


137
138
139
140
141
142
143
144
145
146
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 137

def ensure_that_the_target_directory_exists
  _ = main_dir?
  if File.directory? _
    remove_directory(_) # Remove it as of 01.09.2016 - may be changed at a later time again.
  end
  unless File.directory? _
    opn; e 'Creating the directory '+sdir(_)+' next.'
    create_directory(_)
  end
end

#input?Boolean

#

input?

#

Returns:

  • (Boolean)


130
131
132
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 130

def input?
  @input
end

#main_prefix?Boolean

#

main_prefix?

#

Returns:

  • (Boolean)


221
222
223
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 221

def main_prefix?
  'prefix='+main_dir?
end
#

menu

#


271
272
273
274
275
276
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 271

def menu(i = input?)
  case i
  when '--help'
    opn; e 'No option exists for now.'
  end
end

#perform_chroot_operation(be_verbose = true) ⇒ Object

#

perform_chroot_operation

#


236
237
238
239
240
241
242
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 236

def perform_chroot_operation(be_verbose = true)
  _ = main_dir?
  if be_verbose
    opn; e 'Now entering the chroot-directory at `'+sdir(_)+'`.'
  end
  esystem "chroot #{_}"
end

#populate_autogenerated_directoryObject

#

populate_autogenerated_directory

#


317
318
319
320
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 317

def populate_autogenerated_directory
  files = Dir['/AUTOGENERATED/*']
  files.each {|file| copy_file(file, main_dir?+'AUTOGENERATED/') }
end

#remove_directory(i) ⇒ Object

#

remove_directory

#


361
362
363
364
365
366
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 361

def remove_directory(i)
  i.squeeze!('/')
  unless i == '/' # We can never, not even accidentally, remove '/'.
    FileUtils.rm_rf(i)
  end
end

#rename_konsole_tab(i = 'Setting up a chrooted environment ...') ⇒ Object

#

rename_konsole_tab

#


281
282
283
284
285
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 281

def rename_konsole_tab(
    i = 'Setting up a chrooted environment ...'
  )
  Roebe.rename_konsole(i)
end

#resetObject

#

reset (reset tag)

#


111
112
113
114
115
116
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 111

def reset
  super()
  infer_the_namespace
  # === @target_directory
  @target_directory = TARGET_DIRECTORY # Use the default here.
end

#runObject

#

run (run tag)

#


382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 382

def run
  rename_konsole_tab
  check_against_menu
  ensure_that_the_target_directory_exists
  create_directory_skeleton
  create_mount_points if false # Not in use for now.
  create_dev_null     if false # Not in use for now.
  create_bashrc_file
  create_bin_sh_symlink
  populate_autogenerated_directory
  compile_the_required_programs
  copy_libc_related_files_and_other_mandatory_files
  perform_chroot_operation
  rename_konsole_tab('_')
end

#set_input(i = '') ⇒ Object

#

set_input

#


121
122
123
124
125
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 121

def set_input(i = '')
  i = i.first if i.is_a? Array
  i = i.to_s.dup
  @input = i
end

#show_header(i) ⇒ Object

#

show_header (header tag)

#


184
185
186
187
188
189
190
191
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 184

def show_header(i)
  i = i.to_s.sub(/compile_/,'')
  e
  e sfancy('#')
  e sfancy('# === '+i)
  e sfancy('#')
  e
end

#target_dir?Boolean Also known as: main_target?, main_dir?

#

target_dir?

#

Returns:

  • (Boolean)


228
229
230
# File 'lib/roebe/classes/setup_chrooted_environment.rb', line 228

def target_dir?
  @target_directory
end