class RBT::Linux::LFS

Constants

DEFAULT_USER
#

DEFAULT_USER

#
F
#

F

#
LFS_DIR
#

LFS_DIR

#
LOCATION_OF_PARTITION
#

LOCATION_OF_PARTITION

This is presently hardcoded. We may move to a non-hardcoded approach at a later time.

#
MOUNT_DIR
#

MOUNT_DIR

This will become /Mount/lfs/.

#
SOURCES_DIR
#

SOURCES_DIR

#
T
#

T

#
TOOLS_DIR
#

TOOLS_DIR

#

Public Class Methods

esystem(i) click to toggle source
#

RBT::LFS.esystem

#
# File lib/rbt/linux/lfs/lfs/lfs.rb, line 241
def self.esystem(i)
  ::RBT.esystem(i)
end
mkdir(i) click to toggle source
#

RBT::LFS.mkdir

#
# File lib/rbt/linux/lfs/lfs/lfs.rb, line 248
def self.mkdir(i)
  ::RBT.mkdir(i)
end
new( run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/linux/lfs/lfs/lfs.rb, line 39
def initialize(
    run_already = true
  )
  reset
  run if run_already
end
populate_dev_device() click to toggle source
#

RBT::LFS.populate_dev_device

This method can be used to populate the linux /dev entries, as specified in the LFS project.

See the following link for an in-depth explanation:

http://www.linuxfromscratch.org/lfs/view/6.1/chapter06/devices.html
#
# File lib/rbt/linux/lfs/lfs/lfs.rb, line 263
def self.populate_dev_device
  esystem 'mknod -m 600 /dev/console c 5 1'
  esystem 'mknod -m 666 /dev/null c 1 3'
  esystem 'mount -n -t tmpfs none /dev'
  esystem 'mknod -m 622 /dev/console c 5 1'
  esystem 'mknod -m 666 /dev/null c 1 3'
  esystem 'mknod -m 666 /dev/zero c 1 5'
  esystem 'mknod -m 666 /dev/ptmx c 5 2'
  esystem 'mknod -m 666 /dev/tty c 5 0'
  esystem 'mknod -m 444 /dev/random c 1 8'
  esystem 'mknod -m 444 /dev/urandom c 1 9'
  esystem 'chown 0:tty /dev/{console,ptmx,tty}'
  esystem 'ln -s /proc/self/fd /dev/fd'
  esystem 'ln -s /proc/self/fd/0 /dev/stdin'
  esystem 'ln -s /proc/self/fd/1 /dev/stdout'
  esystem 'ln -s /proc/self/fd/2 /dev/stderr'
  esystem 'ln -s /proc/kcore /dev/core'
  mkdir '/dev/pts'
  mkdir '/dev/shm'
  esystem 'mount -t devpts -o gid=4,mode=620 none /dev/pts'
  esystem 'mount -t tmpfs none /dev/shm'
end

Public Instance Methods

add_user(i = DEFAULT_USER) click to toggle source
#

add_user

This method will add a new user, in this context the lfs-user.

This is equivalent to this step:

http://www.linuxfromscratch.org/lfs/view/development/chapter04/addinguser.html
#
# File lib/rbt/linux/lfs/lfs/lfs.rb, line 231
def add_user(i = DEFAULT_USER)
  @user = i.to_s
  e 'Next adding a new '+slateblue('user')+' via groupadd/useradd:'
  s 'groupadd '+i.to_s
  s 'useradd -s /bin/bash -g '+i.to_s+' -m -k /dev/null '+i.to_s
end
compile( name, optional_version = nil ) click to toggle source
#

compile

This will compile. If name contains a number, we split it up.

#
# File lib/rbt/linux/lfs/lfs/lfs.rb, line 175
def compile(
    name, optional_version = nil
  )
  if name =~ /-\d+/
    name = name.split '-'
    optional_version = name[1]
    name = name[0]
  end # from here on everything is fine again.
  installer = RBT::Action::Installer.new(name)
  installer.set_version optional_version if optional_version
  installer.run
end
consider_creating_mount_directory(i = MOUNT_DIR) click to toggle source
#

consider_creating_mount_directory

Consider creating the directory /Mount/lfs/.

#
# File lib/rbt/linux/lfs/lfs/lfs.rb, line 103
def consider_creating_mount_directory(i = MOUNT_DIR)
  unless File.directory? i
    e "Anyway, let's get started and first "+
       sfancy('create a new directory.')
    e i
    mkdir i
    change_permission i
  else
    e 'Directory '+sdir(i)+' already exists, thus'
    e 'we will not create it.'
  end
end
create_all_directories() click to toggle source
#

create_all_directories

#
# File lib/rbt/linux/lfs/lfs/lfs.rb, line 200
def create_all_directories
  e 'Next creating the '+sdir('source/')+' and '+sdir('tools/')+' directory.'
  create_source_directory
  create_temp_directory
  create_tools_directory # mkdir -v $MOLLI/tools
end
create_bash_profile() click to toggle source
#

create_bash_profile

#
# File lib/rbt/linux/lfs/lfs/lfs.rb, line 135
def create_bash_profile # creates ~/.bash_profile
  # what = "exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash"
  # to = '~/.bash_profile'
  # append_what_to what, File.expand_path(to)
end
create_source_directory() click to toggle source
#

create_source_directory

#
# File lib/rbt/linux/lfs/lfs/lfs.rb, line 210
def create_source_directory
  create_directory @mounted_sources_directory,'',true
end
create_temp_directory() click to toggle source
#

create_temp_directory

#
# File lib/rbt/linux/lfs/lfs/lfs.rb, line 217
def create_temp_directory
  create_directory @mounted_temp_directory,'',true
end
create_tools_directory() click to toggle source
#

create_tools_directory

#
# File lib/rbt/linux/lfs/lfs/lfs.rb, line 74
def create_tools_directory
  create_directory TOOLS_DIR,'',true
end
enter_lfs_partition(this_directory = MOUNT_DIR) click to toggle source
#

enter_lfs_partition

#
# File lib/rbt/linux/lfs/lfs/lfs.rb, line 94
def enter_lfs_partition(this_directory = MOUNT_DIR)
  change_directory this_directory
end
install_linux_kernel_headers() click to toggle source
#

install_linux_kernel_headers

This is used to install the Linux kernel headers.

URL resource can be found at:

https://www.linuxfromscratch.org/lfs/view/development/chapter05/linux-headers.html
#
# File lib/rbt/linux/lfs/lfs/lfs.rb, line 126
def install_linux_kernel_headers
  esystem 'make mrproper'
  esystem 'make INSTALL_HDR_PATH=dest headers_install'
  esystem 'cp -rv dest/include/* /tools/include'
end
mount_lfs_partition() click to toggle source
#

mount_lfs_partition

#
# File lib/rbt/linux/lfs/lfs/lfs.rb, line 165
def mount_lfs_partition # mount tag.
  s 'export LFS='+MOUNT_DIR
  s 'mount -v '+LOCATION_OF_PARTITION+' '+MOUNT_DIR
end
prepare_user_then_login(i = @user) click to toggle source
#

prepare_user_then_login

#
# File lib/rbt/linux/lfs/lfs/lfs.rb, line 144
def prepare_user_then_login(i = @user)
  s 'chown -v '+i+' '+TOOLS_DIR
  s 'chown -v '+i+' '+MOUNT_DIR+'sources'
  s 'chown -v '+i+' '+MOUNT_DIR+'temp'
  s 'su - '+i
end
reset() click to toggle source
#

reset

#
Calls superclass method RBT::LeanPrototype#reset
# File lib/rbt/linux/lfs/lfs/reset.rb, line 16
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @sources_dir
  # ======================================================================= #
  @sources_dir = source_directory?
  # ======================================================================= #
  # === @mounted_sources_directory
  # ======================================================================= #
  @mounted_sources_directory = "#{MOUNT_DIR}sources/"
  # ======================================================================= #
  # === @mounted_temp_directory
  # ======================================================================= #
  @mounted_temp_directory    = MOUNT_DIR+'temp/'
end
run() click to toggle source
#

run

#
# File lib/rbt/linux/lfs/lfs/run.rb, line 16
  def run
    show_welcome_message              # (1)
    consider_creating_mount_directory # (2)
    # mount_lfs_partition             # (3) optional step
    enter_lfs_partition               # (4)
    create_all_directories            # (5)
    symlink_tools_to_root             # (6)
    set_sticky_bit                    # (7)
    add_user(:lfs)                    # (8) also sets @user.
    prepare_user_then_login
    create_file
    create_bash_profile # creates ~/.bash_profile
e steelblue('DEBUG - all fine up to this point?')
e steelblue('If yes we can continue.')
exit
    compile 'Binutils-2.27' # This should be synced to the most recent Binutils version.
    compile 'GCC-6.3.0'
    install_linux_kernel_headers
    compile 'Glibc-2.14.1'
  end
s(i) click to toggle source
#

s

Easier wrapper towards system. (system tag)

#
# File lib/rbt/linux/lfs/lfs/lfs.rb, line 193
def s(i)
  esystem(i)
end
set_sticky_bit(i = @sources_dir) click to toggle source
#

set_sticky_bit

#
# File lib/rbt/linux/lfs/lfs/lfs.rb, line 154
def set_sticky_bit(i = @sources_dir) # Sets the sticky bit.
  begin
    File.chmod(01666, i)
  rescue Exception => error
    pp error
  end
end
show_welcome_message() click to toggle source
#

show_welcome_message

#
# File lib/rbt/linux/lfs/lfs/lfs.rb, line 81
def show_welcome_message
  e 'Welcome to '+slateblue('Linux from Scratch')+'!'
  e 'This project will make use of the '+
    sfancy('RBT (Ruby Build Tools)')+'project'
  e 'to try and compile a smooth LFS for you from scratch.'
  e
  e 'For this, we will need to know a few things.'
  e
end