getch 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb6075f7c63fb0a9b3d9cae63e24aae84cb3c90947985aa54ba48bc0dd284dcc
4
- data.tar.gz: 26ad192fed5685f42e62d400706d6127c3d28a0fc5ce67296da6ef758955de25
3
+ metadata.gz: 4d697434a5e8a44edb8027582ece052145c440247524597afe5ad28118115154
4
+ data.tar.gz: 42eb9e224e6581752f28d6997a9e10feb0e65c432e0dd80bc87236d7e597d828
5
5
  SHA512:
6
- metadata.gz: fe321ca0175f95f07c68026269830932609ba2fe5a1757efb7228bc26a069c4f5c322b21c534d05077c98a4dddfb0ed33bb2aa2fb30b1bc2df234e25b47acb56
7
- data.tar.gz: 5b3540c9a1f07162bfbb3e4772f78c0b74b9525ec74fed7ce71c507da5f58befc85e6f8198abc595b49fa767abc77349f56b0ab9790d56730c45771365268fb0
6
+ metadata.gz: 2e17128164b81b58d59f296e360197a2b9fbb33fd2b1cbd58128b1b04885eef4480d067c5588d40802c889e5a80861b63c37454b685bdb6263e9806b2e99b208
7
+ data.tar.gz: f8eee6f6b37fb036a05003d109672615cc7439dcc5277f2d4604d58e66b2407fa648bdccb850269545f2aef5441777a0d936842326cecb7410b05dfb6dbcee64
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,7 +1,12 @@
1
- * Repair GRUB/fstab for BIOS system, add config and all
2
- * New option --encrypt (LVM/EXT4/LUKS for now)
3
- * Adding LVM
4
- * Create a swap volume equal to the memory installed
1
+ * Adding LVM via the option fs, `--fs lvm`.
2
+ * Systemd-boot use the value of PARTUUID without initramfs.
3
+ * Include lib logger.
4
+
5
+ ## 0.0.7, release 2020-09-22
6
+ * Correct fstab.
7
+ * Repair GRUB/fstab for BIOS system, add secure cmdline.
8
+ * Create a swap volume equal to the memory installed.
9
+ * Add vim and sudo
5
10
 
6
11
  ## 0.0.6, release 2020-09-19
7
12
  * Add support for QEMU guest with KVM and Virtio driver
data/README.md CHANGED
@@ -23,7 +23,7 @@ With `gem` installed:
23
23
 
24
24
  When you boot from an `iso`, you can install `ruby`, `getch` and correct your `PATH=` directly with the `bin/setup.sh`:
25
25
 
26
- # curl https://raw.githubusercontent.com/szorfein/getch/master/bin/setup.sh | sh
26
+ # sh <(curl -L https://raw.githubusercontent.com/szorfein/getch/master/bin/setup.sh)
27
27
  # source ~/.zshrc # or ~/.bashrc
28
28
 
29
29
  ## Usage
@@ -37,6 +37,10 @@ For a french user:
37
37
 
38
38
  After an install by Getch, take a look on the [wiki](https://github.com/szorfein/getch/wiki).
39
39
 
40
+ Install Gentoo on LVM:
41
+
42
+ # getch --format lvm --disk sda
43
+
40
44
  ## Issues
41
45
  If need more support for your hardware (network, sound card, ...), you can submit a [new issue](https://github.com/szorfein/getch/issues/new) and post the output of the following command:
42
46
  + lspci
@@ -26,7 +26,7 @@ search_ruby() {
26
26
  else
27
27
  echo "Install ruby"
28
28
  if hash pacman 2>/dev/null ; then
29
- pacman -Syy libyaml ruby ruby-irb ruby-reline rubygems
29
+ pacman -Syy --noconfirm libyaml ruby ruby-irb ruby-reline rubygems
30
30
  elif hash emerge 2>/dev/null ; then
31
31
  emerge -av dev-lang/ruby
32
32
  elif hash apt-get 2>/dev/null ; then
@@ -4,6 +4,7 @@ require_relative 'getch/gentoo'
4
4
  require_relative 'getch/filesystem'
5
5
  require_relative 'getch/command'
6
6
  require_relative 'getch/helpers'
7
+ require_relative 'getch/log'
7
8
 
8
9
  module Getch
9
10
 
@@ -30,7 +31,8 @@ module Getch
30
31
 
31
32
  MOUNTPOINT = "/mnt/gentoo".freeze
32
33
  OPTIONS_FS = {
33
- 'ext4' => DEFAULT_OPTIONS[:encrypt] ? Getch::FileSystem::Ext4::Encrypt : Getch::FileSystem::Ext4
34
+ 'ext4' => DEFAULT_OPTIONS[:encrypt] ? Getch::FileSystem::Ext4::Encrypt : Getch::FileSystem::Ext4,
35
+ 'lvm' => DEFAULT_OPTIONS[:encrypt] ? Getch::FileSystem::Lvm::Encrypt : Getch::FileSystem::Lvm
34
36
  }.freeze
35
37
 
36
38
  def self.resume_options(opts)
@@ -54,10 +56,12 @@ module Getch
54
56
 
55
57
  def self.format(disk, fs, user)
56
58
  return if STATES[:format] and STATES[:partition]
59
+ log = Log.new
57
60
  puts
58
61
  print "Partition and format disk #{disk}, this will erase all data, continue? (n,y) "
59
62
  case gets.chomp
60
63
  when /^y|^Y/
64
+ log.info("Partition start")
61
65
  OPTIONS_FS[fs]::Partition.new
62
66
  OPTIONS_FS[fs]::Format.new
63
67
  else
@@ -4,14 +4,22 @@ module Getch
4
4
  class Command
5
5
  def initialize(cmd)
6
6
  @cmd = cmd
7
- @block_size = 512
7
+ @block_size = 1024
8
+ @log = Getch::Log.new
8
9
  end
9
10
 
10
11
  def run!
11
- puts "Running command: " + @cmd.gsub(/\"/, '')
12
+ @log.info "Running command: " + @cmd.gsub(/\"/, '')
12
13
 
13
- Open3.popen3(@cmd) do |stdin, stdout, stderr|
14
+ Open3.popen3(@cmd) do |stdin, stdout, stderr, wait_thr|
14
15
  stdin.close_write
16
+ code = wait_thr.value
17
+
18
+ # only stderr
19
+ begin
20
+ @log.error stderr.readline until stderr.eof.nil?
21
+ rescue EOFError
22
+ end
15
23
 
16
24
  begin
17
25
  files = [stdout, stderr]
@@ -24,25 +32,20 @@ module Getch
24
32
  # writable = ready[1]
25
33
  # exceptions = ready[2]
26
34
 
27
- readable.each do |f|
28
- fileno = f.fileno
29
-
30
- begin
31
- data = f.read_nonblock(@block_size)
32
-
33
- # Do something with the data...
34
- puts "#{data}" if DEFAULT_OPTIONS[:verbose]
35
- rescue EOFError
36
- puts "fileno: #{fileno} EOF"
37
- end
38
- end
35
+ display_lines(readable)
39
36
  end
40
37
  end
41
38
  rescue IOError => e
42
39
  puts "IOError: #{e}"
43
40
  end
41
+
42
+ unless code.success?
43
+ @log.fatal "Running #{@cmd}"
44
+ exit 1
45
+ end
46
+
47
+ @log.debug "Done - #{@cmd} - #{code}"
44
48
  end
45
- puts "Done"
46
49
  end
47
50
 
48
51
  private
@@ -51,5 +54,103 @@ module Getch
51
54
  def all_eof(files)
52
55
  files.find { |f| !f.eof }.nil?
53
56
  end
57
+
58
+ def display_lines(block)
59
+ block.each do |f|
60
+ begin
61
+ data = f.read_nonblock(@block_size)
62
+ puts data if DEFAULT_OPTIONS[:verbose]
63
+ rescue EOFError
64
+ puts ""
65
+ rescue => e
66
+ puts "Fatal - #{e}"
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ # Use system, the only ruby method to display stdout with colors !
73
+ class Emerge
74
+ def initialize(cmd)
75
+ @gentoo = MOUNTPOINT
76
+ @cmd = cmd
77
+ @log = Getch::Log.new
78
+ end
79
+
80
+ def run!
81
+ @log.info "Running emerge: #{@cmd}"
82
+ system("chroot", @gentoo, "/bin/bash", "-c", "source /etc/profile && #{@cmd}")
83
+ read_exit
84
+ end
85
+
86
+ def pkg!
87
+ @log.info "Running emerge pkg: #{@cmd}"
88
+ system("chroot", @gentoo, "/bin/bash", "-c", "source /etc/profile && emerge --changed-use #{@cmd}")
89
+ read_exit
90
+ end
91
+
92
+ private
93
+
94
+ def read_exit
95
+ if $?.exitstatus > 0
96
+ @log.fatal "Running #{@cmd}"
97
+ else
98
+ @log.info "Done #{@cmd}"
99
+ end
100
+ end
101
+ end
102
+
103
+ class Make
104
+ def initialize(cmd)
105
+ @gentoo = MOUNTPOINT
106
+ @cmd = cmd
107
+ @log = Getch::Log.new
108
+ end
109
+
110
+ def run!
111
+ @log.info "Running Make: #{@cmd}"
112
+ cmd = "chroot #{@gentoo} /bin/bash -c \"source /etc/profile \
113
+ && env-update \
114
+ && cd /usr/src/linux \
115
+ && #{@cmd}\""
116
+ Open3.popen2e(cmd) do |stdin, stdout_err, wait_thr|
117
+ while line = stdout_err.gets
118
+ puts line
119
+ end
120
+
121
+ exit_status = wait_thr.value
122
+ unless exit_status.success?
123
+ @log.fatal "Running #{cmd}"
124
+ exit 1
125
+ end
126
+ end
127
+ end
128
+ end
129
+
130
+ class Garden
131
+ def initialize(cmd)
132
+ @gentoo = MOUNTPOINT
133
+ @cmd = cmd
134
+ @log = Getch::Log.new
135
+ end
136
+
137
+ def run!
138
+ @log.info "Running Garden: #{@cmd}"
139
+ cmd = "chroot #{@gentoo} /bin/bash -c \"source /etc/profile \
140
+ && env-update \
141
+ && cd /root/garden-master \
142
+ && ./kernel.sh #{@cmd} -k /usr/src/linux\""
143
+ Open3.popen2e(cmd) do |stdin, stdout_err, wait_thr|
144
+ while line = stdout_err.gets
145
+ puts line
146
+ end
147
+
148
+ exit_status = wait_thr.value
149
+ unless exit_status.success?
150
+ @log.fatal "Running #{cmd}"
151
+ exit 1
152
+ end
153
+ end
154
+ end
54
155
  end
55
156
  end
@@ -4,3 +4,4 @@ module Getch
4
4
  end
5
5
 
6
6
  require_relative 'filesystem/ext4'
7
+ require_relative 'filesystem/lvm'
@@ -22,7 +22,7 @@ module Getch
22
22
  datas_gentoo = [
23
23
  'title Gentoo Linux',
24
24
  'linux /vmlinuz',
25
- "options root=UUID=#{uuid_root} init=#{@init} rw"
25
+ "options root=PARTUUID=#{@partuuid_root} init=#{@init} rw"
26
26
  ]
27
27
  File.write("#{dir}/gentoo.conf", datas_gentoo.join("\n"))
28
28
  end
@@ -37,6 +37,7 @@ module Getch
37
37
  private
38
38
 
39
39
  def gen_uuid
40
+ @partuuid_root = `lsblk -o "PARTUUID" #{@dev_root} | tail -1`.chomp() if @dev_root
40
41
  @uuid_swap = `lsblk -o "UUID" #{@dev_swap} | tail -1`.chomp() if @dev_swap
41
42
  @uuid_root = `lsblk -o "UUID" #{@dev_root} | tail -1`.chomp() if @dev_root
42
43
  @uuid_boot = `lsblk -o "UUID" #{@dev_boot} | tail -1`.chomp() if @dev_boot
@@ -22,7 +22,7 @@ module Getch
22
22
 
23
23
  def install_deps
24
24
  exec("euse -p sys-apps/systemd -E cryptsetup")
25
- Helpers::emerge('genkernel cryptsetup lvm2')
25
+ Getch::Emerge.new('genkernel cryptsetup lvm2').pkg!
26
26
  exec("genkernel --install --luks --keymap #{DEFAULT_OPTIONS[:keyboard]} --lvm --kernel-config=/usr/src/linux/.config initramfs")
27
27
  exec("systemctl enable lvm2-monitor")
28
28
  end
@@ -12,12 +12,18 @@ module Getch
12
12
  def format
13
13
  return if STATES[:format]
14
14
  puts "Format #{@disk} with #{@fs}"
15
- system("mkfs.fat -F32 #{@dev_boot_efi}") if Helpers::efi?
16
- system("mkswap -f #{@dev_swap}")
17
- system("mkfs.#{@fs} #{@dev_root}")
18
- system("mkfs.#{@fs} #{@dev_home}") if @dev_home
15
+ exec("mkfs.fat -F32 #{@dev_boot_efi}") if Helpers::efi?
16
+ exec("mkswap -f #{@dev_swap}")
17
+ exec("mkfs.#{@fs} -F #{@dev_root}")
18
+ exec("mkfs.#{@fs} -F #{@dev_home}") if @dev_home
19
19
  @state.format
20
20
  end
21
+
22
+ private
23
+
24
+ def exec(cmd)
25
+ Getch::Command.new(cmd).run!
26
+ end
21
27
  end
22
28
  end
23
29
  end
@@ -0,0 +1,13 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Lvm
4
+ end
5
+ end
6
+ end
7
+
8
+ require_relative 'lvm/device'
9
+ require_relative 'lvm/partition'
10
+ require_relative 'lvm/format'
11
+ require_relative 'lvm/mount'
12
+ require_relative 'lvm/config'
13
+ require_relative 'lvm/deps'
@@ -0,0 +1,62 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Lvm
4
+ class Config < Getch::FileSystem::Lvm::Device
5
+ def initialize
6
+ super
7
+ gen_uuid
8
+ @root_dir = MOUNTPOINT
9
+ @init = '/usr/lib/systemd/systemd'
10
+ end
11
+
12
+ def fstab
13
+ file = "#{@root_dir}/etc/fstab"
14
+ datas = data_fstab
15
+ File.write(file, datas.join("\n"))
16
+ end
17
+
18
+ def systemd_boot
19
+ return if ! Helpers::efi?
20
+ esp = '/boot/efi'
21
+ dir = "#{@root_dir}/#{esp}/loader/entries/"
22
+ datas_gentoo = [
23
+ 'title Gentoo Linux',
24
+ 'linux /vmlinuz',
25
+ 'initrd /initramfs',
26
+ "options resume=UUID=#{@uuid_swap} root=UUID=#{@uuid_root} init=#{@init} dolvm rw"
27
+ ]
28
+ File.write("#{dir}/gentoo.conf", datas_gentoo.join("\n"))
29
+ end
30
+
31
+ def grub
32
+ return if Helpers::efi?
33
+ file = "#{@root_dir}/etc/default/grub"
34
+ cmdline = [
35
+ "GRUB_CMDLINE_LINUX=\"resume=UUID=#{@uuid_swap} root=UUID=#{@uuid_root} init=#{@init} dolvm rw\""
36
+ ]
37
+ File.write("#{file}", cmdline.join("\n"), mode: 'a')
38
+ end
39
+
40
+ private
41
+
42
+ def gen_uuid
43
+ @uuid_swap = `lsblk -o "UUID" #{@lv_swap} | tail -1`.chomp() if @lv_swap
44
+ @uuid_root = `lsblk -o "UUID" #{@lv_root} | tail -1`.chomp() if @lv_root
45
+ @uuid_dev_root = `lsblk -o "UUID" #{@dev_root} | tail -1`.chomp() if @dev_root
46
+ @uuid_boot = `lsblk -o "UUID" #{@dev_boot} | tail -1`.chomp() if @dev_boot
47
+ @uuid_boot_efi = `lsblk -o "UUID" #{@dev_boot_efi} | tail -1`.chomp() if @dev_boot_efi
48
+ @uuid_home = `lsblk -o "UUID" #{@lv_home} | tail -1`.chomp() if @lv_home
49
+ end
50
+
51
+ def data_fstab
52
+ boot_efi = @dev_boot_efi ? "UUID=#{@uuid_boot_efi} /boot/efi vfat noauto,noatime 1 2" : ''
53
+ swap = @lv_swap ? "UUID=#{@uuid_swap} none swap discard 0 0" : ''
54
+ root = @lv_root ? "UUID=#{@uuid_root} / ext4 defaults 0 1" : ''
55
+ home = @lv_home ? "UUID=#{@uuid_home} /home/#{@user} ext4 defaults 0 2" : ''
56
+
57
+ [ boot_efi, swap, root, home ]
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,57 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Lvm
4
+ class Deps
5
+ def initialize
6
+ if Helpers::efi?
7
+ install_efi
8
+ else
9
+ install_bios
10
+ end
11
+ install_deps
12
+ end
13
+
14
+ def make
15
+ options_make
16
+ Getch::Make.new("genkernel --kernel-config=/usr/src/linux/.config all").run!
17
+ end
18
+
19
+ private
20
+ def options_make
21
+ grub = Helpers::efi? ? 'BOOTLOADER="no"' : 'BOOTLOADER="grub2"'
22
+ datas = [
23
+ '',
24
+ grub,
25
+ 'INSTALL="yes"',
26
+ 'MENUCONFIG="no"',
27
+ 'CLEAN="yes"',
28
+ 'SAVE_CONFIG="yes"',
29
+ 'MOUNTBOOT="yes"',
30
+ 'MRPROPER="no"',
31
+ 'LVM="yes"',
32
+ ]
33
+ file = "#{MOUNTPOINT}/etc/genkernel.conf"
34
+ File.write(file, datas.join("\n"), mode: 'a')
35
+ end
36
+
37
+ def install_efi
38
+ end
39
+
40
+ def install_bios
41
+ exec("euse -p sys-boot/grub -E device-mapper")
42
+ end
43
+
44
+ def install_deps
45
+ exec("euse -E lvm")
46
+ Getch::Emerge.new('genkernel lvm2').pkg!
47
+ Getch::Garden.new('-a lvm').run!
48
+ exec("systemctl enable lvm2-monitor")
49
+ end
50
+
51
+ def exec(cmd)
52
+ Helpers::run_chroot(cmd, MOUNTPOINT)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,19 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Lvm
4
+ class Device
5
+ def initialize
6
+ @disk = DEFAULT_OPTIONS[:disk]
7
+ @user = DEFAULT_OPTIONS[:username]
8
+ @dev_boot_efi = Helpers::efi? ? "/dev/#{@disk}1" : nil
9
+ @dev_boot = Helpers::efi? ? nil : "/dev/#{@disk}2"
10
+ @dev_root = Helpers::efi? ? "/dev/#{@disk}2" : "/dev/#{@disk}3"
11
+ @vg = 'vg0'
12
+ @lv_root = "/dev/mapper/#{@vg}-root"
13
+ @lv_swap = "/dev/mapper/#{@vg}-swap"
14
+ @lv_home = @user ? "/dev/mapper/#{@vg}-home" : nil
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Lvm
4
+ class Format < Getch::FileSystem::Lvm::Device
5
+ def initialize
6
+ super
7
+ @fs = 'ext4'
8
+ @state = Getch::States.new()
9
+ format
10
+ end
11
+
12
+ def format
13
+ return if STATES[:format]
14
+ puts "Format #{@disk} with #{@fs}"
15
+ system("mkfs.fat -F32 #{@dev_boot_efi}") if @dev_boot_efi
16
+ system("mkfs.#{@fs} -F #{@dev_boot}") if @dev_boot
17
+ system("mkswap -f #{@lv_swap}")
18
+ system("mkfs.#{@fs} -F #{@lv_root}")
19
+ system("mkfs.#{@fs} -F #{@lv_home}") if @lv_home
20
+ @state.format
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,62 @@
1
+ require 'fileutils'
2
+
3
+ module Getch
4
+ module FileSystem
5
+ module Lvm
6
+ class Mount < Getch::FileSystem::Lvm::Device
7
+ def initialize
8
+ super
9
+ @root_dir = MOUNTPOINT
10
+ @boot_dir = "#{@root_dir}/boot"
11
+ @boot_efi_dir = "#{@root_dir}/boot/efi"
12
+ @home_dir = @user ? "#{@root_dir}/home/#{@user}" : nil
13
+ @state = Getch::States.new()
14
+ end
15
+
16
+ def run
17
+ return if STATES[:mount]
18
+ mount_swap
19
+ mount_root
20
+ mount_boot
21
+ mount_home
22
+ mount_boot_efi
23
+ @state.mount
24
+ end
25
+
26
+ private
27
+
28
+ def mount_swap
29
+ return if ! @lv_swap
30
+ system("swapon #{@lv_swap}")
31
+ end
32
+
33
+ def mount_root
34
+ return if ! @lv_root
35
+ Dir.mkdir(@root_dir, 0700) if ! Dir.exist?(@root_dir)
36
+ system("mount #{@lv_root} #{@root_dir}")
37
+ end
38
+
39
+ def mount_boot_efi
40
+ return if ! @dev_boot_efi
41
+ FileUtils.mkdir_p @boot_efi_dir, mode: 0700 if ! Dir.exist?(@boot_efi_dir)
42
+ system("mount #{@dev_boot_efi} #{@boot_efi_dir}")
43
+ end
44
+
45
+ def mount_boot
46
+ return if ! @dev_boot
47
+ FileUtils.mkdir_p @boot_dir, mode: 0700 if ! Dir.exist?(@boot_dir)
48
+ system("mount #{@dev_boot} #{@boot_dir}")
49
+ end
50
+
51
+ def mount_home
52
+ return if ! @lv_home
53
+ if @user != nil then
54
+ FileUtils.mkdir_p @home_dir, mode: 0700 if ! Dir.exist?(@home_dir)
55
+ system("mount #{@lv_home} #{@home_dir}")
56
+ end
57
+ @state.mount
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,81 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Lvm
4
+ class Partition < Getch::FileSystem::Lvm::Device
5
+ def initialize
6
+ super
7
+ @state = Getch::States.new()
8
+ run_partition
9
+ end
10
+
11
+ def run_partition
12
+ return if STATES[:partition ]
13
+ clear_struct
14
+ cleaning
15
+ partition
16
+ lvm
17
+ @state.partition
18
+ end
19
+
20
+ private
21
+
22
+ def clear_struct
23
+ oldvg = `vgdisplay | grep #{@vg}`.chomp
24
+ exec("vgremove -f #{@vg}") if oldvg != '' # remove older volume group
25
+ exec("pvremove -f #{@dev_root}") if oldvg != '' and File.exist? @dev_root # remove older volume group
26
+
27
+ exec("sgdisk -Z /dev/#{@disk}")
28
+ exec("wipefs -a /dev/#{@disk}")
29
+ end
30
+
31
+ def cleaning
32
+ puts
33
+ print "Cleaning data on #{@disk}, can be long, avoid this on Flash Memory (SSD,USB,...) ? (n,y) "
34
+ case gets.chomp
35
+ when /^y|^Y/
36
+ bloc=`blockdev --getbsz /dev/#{@disk}`.chomp
37
+ exec("dd if=/dev/urandom of=/dev/#{@disk} bs=#{bloc} status=progress")
38
+ else
39
+ return
40
+ end
41
+ end
42
+
43
+ def partition
44
+ if Helpers::efi?
45
+ exec("sgdisk -n1:1M:+260M -t1:EF00 /dev/#{@disk}")
46
+ exec("sgdisk -n2:0:+0 -t2:8e00 /dev/#{@disk}")
47
+ else
48
+ exec("sgdisk -n1:1MiB:+1MiB -t1:EF02 /dev/#{@disk}")
49
+ exec("sgdisk -n2:0:+128MiB -t2:8300 /dev/#{@disk}")
50
+ exec("sgdisk -n3:0:+0 -t3:8e00 /dev/#{@disk}")
51
+ end
52
+ end
53
+
54
+ def lvm
55
+ mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
56
+ exec("pvcreate -f #{@dev_root}")
57
+ exec("vgcreate -f #{@vg} #{@dev_root}")
58
+ # Wipe old signature: https://github.com/chef-cookbooks/lvm/issues/45
59
+ exec("lvcreate -y -Wy -Zy -L 15G -n root #{@vg}")
60
+ exec("lvcreate -y -Wy -Zy -L #{mem} -n swap #{@vg}")
61
+ exec("lvcreate -y -Wy -Zy -l 100%FREE -n home #{@vg}") if @user
62
+ exec("vgchange --available y")
63
+ end
64
+
65
+ # Follow https://wiki.archlinux.org/index.php/Partitioning
66
+ # Partition_efi
67
+ # /boot/efi - EFI system partition - 260MB
68
+ # / - Root
69
+
70
+ # Partition_bios
71
+ # None - Bios Boot Partition - 1MiB
72
+ # /boot - Boot - 8300
73
+ # / - Root
74
+
75
+ def exec(cmd)
76
+ Getch::Command.new(cmd).run!
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -39,8 +39,8 @@ module Getch
39
39
  def chroot
40
40
  chroot = Getch::Gentoo::Chroot.new()
41
41
  chroot.update
42
- chroot.world
43
42
  chroot.systemd
43
+ chroot.world
44
44
  return if STATES[:gentoo_kernel]
45
45
  chroot.kernel
46
46
  chroot.kernel_deps
@@ -11,7 +11,6 @@ module Getch
11
11
 
12
12
  def start
13
13
  @config.fstab
14
- OPTIONS_FS[DEFAULT_OPTIONS[:fs]]::Deps.new()
15
14
  bootloader
16
15
  password
17
16
  umount
@@ -41,18 +40,22 @@ module Getch
41
40
  File.write("#{MOUNTPOINT}/#{esp}/loader/loader.conf", datas_loader.join("\n"))
42
41
 
43
42
  FileUtils.cp("#{MOUNTPOINT}/usr/src/linux/arch/x86/boot/bzImage", "#{MOUNTPOINT}/#{esp}/vmlinuz", preserve: true)
43
+
44
+ initramfs = Dir.glob("#{MOUNTPOINT}/boot/initramfs-*.img")
45
+ FileUtils.cp("#{initramfs[0]}", "#{MOUNTPOINT}/#{esp}/initramfs", preserve: true) if initramfs != []
46
+
44
47
  exec_chroot("bootctl --path #{esp} update")
45
48
  end
46
49
 
47
50
  def bootctl_dep
48
51
  puts 'Installing systemd-boot...'
49
52
  exec_chroot("euse -p sys-apps/systemd -E gnuefi")
50
- Helpers::emerge("sys-apps/systemd efivar", MOUNTPOINT)
53
+ Getch::Emerge.new("sys-apps/systemd efivar").pkg!
51
54
  end
52
55
 
53
56
  def grub
54
57
  puts 'Installing GRUB...'
55
- Helpers::emerge("sys-boot/grub:2", MOUNTPOINT)
58
+ Getch::Emerge.new("sys-boot/grub:2").pkg!
56
59
  @config.grub
57
60
  exec_chroot("grub-install /dev/#{@disk}")
58
61
  exec_chroot('grub-mkconfig -o /boot/grub/grub.cfg')
@@ -10,15 +10,15 @@ module Getch
10
10
  def update
11
11
  return if STATES[:gentoo_update]
12
12
  puts "Downloading the last ebuilds for Gentoo..."
13
+ Helpers::create_dir("#{MOUNTPOINT}/var/db/repos/gentoo")
13
14
  cmd = "emerge-webrsync"
14
15
  exec_chroot(cmd)
15
16
  end
16
17
 
17
18
  def world
18
19
  return if STATES[:gentoo_update]
19
- puts "Update Gentoo"
20
- cmd = "emerge --update --deep --newuse @world"
21
- exec_chroot(cmd)
20
+ puts "Update Gentoo world"
21
+ Getch::Emerge.new("emerge --update --deep --newuse @world").run!
22
22
  @state.update
23
23
  end
24
24
 
@@ -30,7 +30,6 @@ module Getch
30
30
 
31
31
  def kernel
32
32
  return if Dir.exist? "#{MOUNTPOINT}/usr/src/linux"
33
- puts "Installing kernel gentoo-sources..."
34
33
  license = "#{MOUNTPOINT}/etc/portage/package.license"
35
34
  File.write(license, "sys-kernel/linux-firmware linux-fw-redistributable no-source-code\n")
36
35
  @pkgs << "sys-kernel/gentoo-sources"
@@ -46,7 +45,9 @@ module Getch
46
45
  def install_pkgs
47
46
  @pkgs << "app-admin/sudo"
48
47
  @pkgs << "app-editors/vim"
49
- Helpers::emerge(@pkgs.join(" "), MOUNTPOINT)
48
+ all_pkgs = @pkgs.join(" ")
49
+ puts "Installing #{all_pkgs}..."
50
+ Getch::Emerge.new(all_pkgs).pkg!
50
51
  end
51
52
 
52
53
  private
@@ -62,7 +63,7 @@ module Getch
62
63
  end
63
64
 
64
65
  def garden_dep
65
- Helpers::emerge("gentoolkit", MOUNTPOINT)
66
+ Getch::Emerge.new("gentoolkit").pkg!
66
67
  exec_chroot("euse -p sys-apps/kmod -E lzma")
67
68
  @pkgs << "sys-apps/kmod"
68
69
  end
@@ -12,10 +12,12 @@ module Getch
12
12
  def portage
13
13
  nproc = `nproc`.chomp()
14
14
  grub_pc = Helpers::efi? ? '' : 'GRUB_PLATFORMS="pc"'
15
+ quiet = DEFAULT_OPTIONS[:verbose] ? '' : "EMERGE_DEFAULT_OPTS=\"--jobs=#{nproc} --load-average=#{nproc}\""
15
16
  data = [
16
17
  '',
17
- 'ACCEPT_KEYWORD="amd64 ~amd64"',
18
+ 'ACCEPT_KEYWORDS="amd64"',
18
19
  "MAKEOPTS=\"-j#{nproc} -l#{nproc}\"",
20
+ quiet,
19
21
  'INPUT_DEVICES="libinput"',
20
22
  grub_pc
21
23
  ]
@@ -3,79 +3,87 @@ module Getch
3
3
  class Sources
4
4
  def initialize
5
5
  @lsmod = `lsmod`.chomp
6
- @linux = '/usr/src/linux'
6
+ @filesystem = OPTIONS_FS[DEFAULT_OPTIONS[:fs]]::Deps.new()
7
7
  end
8
8
 
9
9
  def build_others
10
- install_wifi if ismatch?('iwlwifi')
11
10
  install_zfs if ismatch?('zfs')
12
11
  virtualbox_guest
13
12
  qemu_guest
13
+ install_wifi
14
+ install_audio
14
15
  end
15
16
 
16
17
  def build_kspp
17
18
  puts "Adding KSPP to the kernel source"
18
- exec("./kernel.sh -b -a systemd -k #{@linux}")
19
+ garden("-b -a systemd")
19
20
  end
20
21
 
21
22
  def make
22
- puts "Compiling kernel sources"
23
- cmd = "cd #{@linux} && make -j$(nproc) && make modules_install && make install"
24
- exec_chroot(cmd)
25
- is_kernel = Dir.glob("#{MOUNTPOINT}/boot/vmlinuz-*")
26
- raise "No kernel installed, compiling source fail..." if is_kernel == []
27
- end
28
-
29
- def only_make
30
- exec_chroot("cd #{@linux} && make -j$(nproc)")
23
+ if DEFAULT_OPTIONS[:fs] == 'lvm'
24
+ @filesystem.make
25
+ else
26
+ just_make
27
+ end
31
28
  end
32
29
 
33
30
  def init_config
34
- exec_chroot("env-update && cd #{@linux} && make localyesconfig")
31
+ Getch::Make.new("make localyesconfig").run!
35
32
  end
36
33
 
37
34
  private
38
35
 
36
+ def only_make
37
+ Getch::Make.new("make -j$(nproc)").run!
38
+ end
39
+
40
+ def just_make
41
+ puts "Compiling kernel sources"
42
+ cmd = "make -j$(nproc) && make modules_install && make install"
43
+ Getch::Make.new(cmd).run!
44
+ is_kernel = Dir.glob("#{MOUNTPOINT}/boot/vmlinuz-*")
45
+ raise "No kernel installed, compiling source fail..." if is_kernel == []
46
+ end
47
+
39
48
  def virtualbox_guest
40
- exec("./kernel.sh -b -a virtualbox-guest -k #{@linux}") if ismatch?('vmwgfx')
41
- Helpers::emerge("app-emulation/virtualbox-guest-additions", MOUNTPOINT)
49
+ return if ! ismatch?('vmwgfx')
50
+ garden("-a virtualbox-guest")
51
+ Getch::Emerge.new("app-emulation/virtualbox-guest-additions").pkg!
42
52
  end
43
53
 
44
54
  def qemu_guest
45
- exec("./kernel.sh -a qemu-guest -k #{@linux}") if ismatch?('virtio')
46
- exec("./kernel.sh -a kvm -k #{@linux}") if ismatch?('kvm')
55
+ garden("-a kvm-guest") if ismatch?('virtio')
56
+ garden("-a kvm") if ismatch?('kvm')
47
57
  end
48
58
 
49
59
  def ismatch?(arg)
50
60
  @lsmod.match?(/#{arg}/)
51
61
  end
52
62
 
53
- def exec(cmd)
54
- script = "chroot #{MOUNTPOINT} /bin/bash -c \"
55
- source /etc/profile
56
- cd /root/garden-master
57
- #{cmd}
58
- \""
59
- Getch::Command.new(script).run!
63
+ def garden(cmd)
64
+ Getch::Garden.new(cmd).run!
60
65
  end
61
66
 
62
- def exec_chroot(cmd)
63
- script = "chroot #{MOUNTPOINT} /bin/bash -c \"
64
- source /etc/profile
65
- #{cmd}
66
- \""
67
- Getch::Command.new(script).run!
67
+ def install_wifi
68
+ return if ! ismatch?('cfg80211')
69
+ garden("-a wifi")
70
+ wifi_drivers
71
+ Getch::Emerge.new("net-wireless/iw wpa_supplicant net-wireless/iwd").pkg!
68
72
  end
69
73
 
70
- def install_wifi
71
- exec("./kernel.sh -b -a wifi -k #{@linux}")
72
- Helpers::emerge("net-wireless/iw wpa_supplicant", MOUNTPOINT)
74
+ def install_audio
75
+ return if ! ismatch?('snd_pcm')
76
+ garden("-a sound")
73
77
  end
74
78
 
75
79
  def install_zfs
76
- exec("./kernel.sh -b -a zfs -k #{@linux}")
80
+ garden("-a zfs")
77
81
  only_make # a first 'make' is necessary before emerge zfs
78
- Helpers::emerge("zfs", MOUNTPOINT)
82
+ Getch::Emerge.new("sys-fs/zfs").pkg!
83
+ end
84
+
85
+ def wifi_drivers
86
+ garden("-a ath9k-driver") if ismatch?('ath9k')
79
87
  end
80
88
  end
81
89
  end
@@ -60,7 +60,7 @@ module Getch
60
60
  # https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Stage
61
61
  def decompress
62
62
  puts "Decompressing archive #{@stage_file}..."
63
- cmd = "tar xpvf #{@stage_file} --xattrs-include='*.*' --numeric-owner"
63
+ cmd = "tar xpf #{@stage_file} --xattrs-include=\'*.*\' --numeric-owner"
64
64
  Getch::Command.new(cmd).run!
65
65
  end
66
66
 
@@ -0,0 +1,54 @@
1
+ require 'logger'
2
+
3
+ module Getch
4
+ class Log
5
+ def initialize
6
+ @log_file = '/tmp/log_install.txt'
7
+ check_file
8
+ init_log
9
+ init_log_text
10
+ end
11
+
12
+ def info(msg)
13
+ @logger.info(msg)
14
+ @logger_text.info(msg)
15
+ end
16
+
17
+ def error(msg)
18
+ @logger.error(msg)
19
+ @logger_text.error(msg)
20
+ end
21
+
22
+ def debug(msg)
23
+ @logger.debug(msg)
24
+ @logger_text.debug(msg)
25
+ end
26
+
27
+ def fatal(msg)
28
+ @logger.fatal(msg)
29
+ @logger_text.fatal(msg)
30
+ end
31
+
32
+ private
33
+
34
+ def check_file
35
+ puts "Creating log at #{@log_file}" if ! File.exist? @log_file
36
+ end
37
+
38
+ def init_log
39
+ @logger = Logger.new(STDOUT)
40
+ @logger.level = DEFAULT_OPTIONS[:verbose] ? Logger::DEBUG : Logger::INFO
41
+ @logger.formatter = proc { |severity, datetime, progname, msg|
42
+ "#{severity}, #{msg}\n"
43
+ }
44
+ end
45
+
46
+ def init_log_text
47
+ @logger_text = Logger.new(@log_file, 1)
48
+ @logger_text.level = Logger::DEBUG
49
+ @logger_text.formatter = proc { |severity, datetime, progname, msg|
50
+ "#{severity}, #{datetime}, #{msg}\n"
51
+ }
52
+ end
53
+ end
54
+ end
@@ -32,8 +32,9 @@ module Getch
32
32
  opts.on("-d", "--disk DISK", "Disk where install Gentoo (sda,sdb)") do |disk|
33
33
  @disk = disk
34
34
  end
35
- opts.on("-f", "--format FS", "Default use ext4") do |fs|
35
+ opts.on("-f", "--format FS", "Can be ext4, lvm. Default use ext4") do |fs|
36
36
  @fs = fs
37
+ DEFAULT_OPTIONS[:fs] = fs # dont known why, but it should be enforce
37
38
  end
38
39
  opts.on("-u", "--username USERNAME", "Initialize /home/username") do |user|
39
40
  @username = user
@@ -1,3 +1,3 @@
1
1
  module Getch
2
- VERSION = '0.0.7'.freeze
2
+ VERSION = '0.0.8'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: getch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - szorfein
@@ -35,7 +35,7 @@ cert_chain:
35
35
  J/zT/q2Ac7BWpSLbv6p9lChBiEnD9j24x463LR5QQjDNS5SsjzRQfFuprsa9Nqf2
36
36
  Tw==
37
37
  -----END CERTIFICATE-----
38
- date: 2020-09-22 00:00:00.000000000 Z
38
+ date: 2020-09-30 00:00:00.000000000 Z
39
39
  dependencies: []
40
40
  description:
41
41
  email:
@@ -69,6 +69,13 @@ files:
69
69
  - lib/getch/filesystem/ext4/format.rb
70
70
  - lib/getch/filesystem/ext4/mount.rb
71
71
  - lib/getch/filesystem/ext4/partition.rb
72
+ - lib/getch/filesystem/lvm.rb
73
+ - lib/getch/filesystem/lvm/config.rb
74
+ - lib/getch/filesystem/lvm/deps.rb
75
+ - lib/getch/filesystem/lvm/device.rb
76
+ - lib/getch/filesystem/lvm/format.rb
77
+ - lib/getch/filesystem/lvm/mount.rb
78
+ - lib/getch/filesystem/lvm/partition.rb
72
79
  - lib/getch/gentoo.rb
73
80
  - lib/getch/gentoo/boot.rb
74
81
  - lib/getch/gentoo/chroot.rb
@@ -76,6 +83,7 @@ files:
76
83
  - lib/getch/gentoo/sources.rb
77
84
  - lib/getch/gentoo/stage.rb
78
85
  - lib/getch/helpers.rb
86
+ - lib/getch/log.rb
79
87
  - lib/getch/options.rb
80
88
  - lib/getch/states.rb
81
89
  - lib/getch/version.rb
metadata.gz.sig CHANGED
Binary file