getch 0.1.9 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +35 -29
- data/bin/getch +8 -6
- data/lib/clean.rb +149 -0
- data/lib/cryptsetup.rb +132 -0
- data/lib/devs.rb +199 -0
- data/lib/dracut/encrypt.rb +36 -0
- data/lib/dracut/hybrid.rb +15 -0
- data/lib/dracut/lvm.rb +14 -0
- data/lib/dracut/minimal.rb +11 -0
- data/lib/dracut/root.rb +45 -0
- data/lib/dracut/zfs.rb +35 -0
- data/lib/dracut.rb +11 -0
- data/lib/fstab/encrypt.rb +44 -0
- data/lib/fstab/hybrid.rb +34 -0
- data/lib/fstab/lvm.rb +25 -0
- data/lib/fstab/minimal.rb +6 -0
- data/lib/fstab/root.rb +93 -0
- data/lib/fstab/zfs.rb +23 -0
- data/lib/fstab.rb +11 -0
- data/lib/getch/assembly.rb +150 -0
- data/lib/getch/command.rb +88 -128
- data/lib/getch/config/account.rb +39 -0
- data/lib/getch/config/dhcp.rb +104 -0
- data/lib/getch/config/grub.rb +42 -0
- data/lib/getch/config/iwd.rb +60 -0
- data/lib/getch/config/keymap.rb +78 -0
- data/lib/getch/config/locale.rb +96 -0
- data/lib/getch/config/portage.rb +90 -0
- data/lib/getch/config/pre_network.rb +37 -0
- data/lib/getch/config/timezone.rb +52 -0
- data/lib/getch/config/void.rb +0 -36
- data/lib/getch/config.rb +16 -37
- data/lib/getch/device.rb +67 -0
- data/lib/getch/filesystem/ext4/encrypt/config.rb +9 -71
- data/lib/getch/filesystem/ext4/encrypt/deps.rb +15 -25
- data/lib/getch/filesystem/ext4/encrypt/device.rb +11 -5
- data/lib/getch/filesystem/ext4/encrypt/format.rb +6 -15
- data/lib/getch/filesystem/ext4/encrypt/mount.rb +7 -11
- data/lib/getch/filesystem/ext4/encrypt/partition.rb +10 -76
- data/lib/getch/filesystem/ext4/encrypt/void.rb +0 -38
- data/lib/getch/filesystem/ext4/encrypt.rb +2 -1
- data/lib/getch/filesystem/ext4/hybrid/config.rb +27 -0
- data/lib/getch/filesystem/ext4/hybrid/deps.rb +55 -0
- data/lib/getch/filesystem/ext4/hybrid/device.rb +24 -0
- data/lib/getch/filesystem/ext4/hybrid/format.rb +23 -0
- data/lib/getch/filesystem/ext4/hybrid/mount.rb +21 -0
- data/lib/getch/filesystem/ext4/hybrid/partition.rb +27 -0
- data/lib/getch/filesystem/{lvm/encrypt → ext4/hybrid}/void.rb +0 -39
- data/lib/getch/filesystem/ext4/hybrid.rb +19 -0
- data/lib/getch/filesystem/ext4/lvm/config.rb +25 -0
- data/lib/getch/filesystem/ext4/lvm/deps.rb +56 -0
- data/lib/getch/filesystem/ext4/lvm/device.rb +28 -0
- data/lib/getch/filesystem/ext4/lvm/format.rb +21 -0
- data/lib/getch/filesystem/ext4/lvm/mount.rb +21 -0
- data/lib/getch/filesystem/ext4/lvm/partition.rb +28 -0
- data/lib/getch/filesystem/{lvm.rb → ext4/lvm.rb} +6 -4
- data/lib/getch/filesystem/ext4/minimal/config.rb +25 -0
- data/lib/getch/filesystem/ext4/{device.rb → minimal/deps.rb} +3 -1
- data/lib/getch/filesystem/ext4/minimal/device.rb +22 -0
- data/lib/getch/filesystem/ext4/minimal/format.rb +23 -0
- data/lib/getch/filesystem/ext4/minimal/mount.rb +21 -0
- data/lib/getch/filesystem/ext4/minimal/partition.rb +28 -0
- data/lib/getch/filesystem/ext4/minimal.rb +19 -0
- data/lib/getch/filesystem/ext4.rb +7 -7
- data/lib/getch/filesystem/zfs/encrypt/config.rb +10 -39
- data/lib/getch/filesystem/zfs/encrypt/deps.rb +4 -55
- data/lib/getch/filesystem/zfs/encrypt/device.rb +7 -51
- data/lib/getch/filesystem/zfs/encrypt/format.rb +6 -90
- data/lib/getch/filesystem/zfs/encrypt/mount.rb +16 -35
- data/lib/getch/filesystem/zfs/encrypt/partition.rb +6 -54
- data/lib/getch/filesystem/zfs/encrypt.rb +2 -1
- data/lib/getch/filesystem/zfs/minimal/config.rb +37 -0
- data/lib/getch/filesystem/zfs/minimal/deps.rb +126 -0
- data/lib/getch/filesystem/zfs/minimal/device.rb +24 -0
- data/lib/getch/filesystem/zfs/minimal/format.rb +23 -0
- data/lib/getch/filesystem/zfs/minimal/mount.rb +23 -0
- data/lib/getch/filesystem/zfs/minimal/partition.rb +23 -0
- data/lib/getch/filesystem/zfs/minimal.rb +19 -0
- data/lib/getch/filesystem/zfs.rb +1 -7
- data/lib/getch/filesystem.rb +0 -6
- data/lib/getch/gentoo/bootloader.rb +23 -44
- data/lib/getch/gentoo/finalize.rb +25 -0
- data/lib/getch/gentoo/post_config.rb +75 -0
- data/lib/getch/gentoo/pre_config.rb +37 -0
- data/lib/getch/gentoo/services.rb +18 -0
- data/lib/getch/gentoo/sources.rb +39 -33
- data/lib/getch/gentoo/tarball.rb +91 -0
- data/lib/getch/gentoo/terraform.rb +34 -0
- data/lib/getch/gentoo/update.rb +54 -0
- data/lib/getch/gentoo/use.rb +9 -6
- data/lib/getch/gentoo/use_flag.rb +17 -20
- data/lib/getch/gentoo.rb +9 -75
- data/lib/getch/guard.rb +2 -2
- data/lib/getch/helpers.rb +63 -115
- data/lib/getch/log.rb +87 -25
- data/lib/getch/options.rb +41 -11
- data/lib/getch/states.rb +28 -8
- data/lib/getch/tree.rb +56 -0
- data/lib/getch/version.rb +1 -1
- data/lib/getch/void/bootloader.rb +18 -0
- data/lib/getch/void/finalize.rb +31 -0
- data/lib/getch/void/post_config.rb +19 -0
- data/lib/getch/void/pre_config.rb +18 -0
- data/lib/getch/void/services.rb +18 -0
- data/lib/getch/void/{stage.rb → tarball.rb} +34 -14
- data/lib/getch/void/terraform.rb +28 -0
- data/lib/getch/void/update.rb +33 -0
- data/lib/getch/void.rb +9 -59
- data/lib/getch.rb +58 -90
- data/lib/luks.rb +239 -0
- data/lib/lvm2.rb +112 -0
- data/lib/mkfs/zfs.rb +167 -0
- data/lib/mkfs.rb +140 -0
- data/lib/mountfs.rb +154 -0
- data/lib/nito.rb +131 -0
- data/lib/sgdisk.rb +160 -0
- data.tar.gz.sig +0 -0
- metadata +83 -47
- metadata.gz.sig +0 -0
- data/lib/getch/config/gentoo.rb +0 -58
- data/lib/getch/filesystem/clean.rb +0 -58
- data/lib/getch/filesystem/device.rb +0 -63
- data/lib/getch/filesystem/ext4/config.rb +0 -62
- data/lib/getch/filesystem/ext4/deps.rb +0 -24
- data/lib/getch/filesystem/ext4/format.rb +0 -31
- data/lib/getch/filesystem/ext4/mount.rb +0 -26
- data/lib/getch/filesystem/ext4/partition.rb +0 -55
- data/lib/getch/filesystem/ext4/void.rb +0 -44
- data/lib/getch/filesystem/lvm/config.rb +0 -44
- data/lib/getch/filesystem/lvm/deps.rb +0 -44
- data/lib/getch/filesystem/lvm/device.rb +0 -45
- data/lib/getch/filesystem/lvm/encrypt/config.rb +0 -74
- data/lib/getch/filesystem/lvm/encrypt/deps.rb +0 -49
- data/lib/getch/filesystem/lvm/encrypt/device.rb +0 -48
- data/lib/getch/filesystem/lvm/encrypt/format.rb +0 -35
- data/lib/getch/filesystem/lvm/encrypt/mount.rb +0 -27
- data/lib/getch/filesystem/lvm/encrypt/partition.rb +0 -84
- data/lib/getch/filesystem/lvm/encrypt.rb +0 -18
- data/lib/getch/filesystem/lvm/format.rb +0 -32
- data/lib/getch/filesystem/lvm/mount.rb +0 -26
- data/lib/getch/filesystem/lvm/partition.rb +0 -72
- data/lib/getch/filesystem/lvm/void.rb +0 -46
- data/lib/getch/filesystem/mount.rb +0 -63
- data/lib/getch/filesystem/partition.rb +0 -85
- data/lib/getch/filesystem/zfs/config.rb +0 -43
- data/lib/getch/filesystem/zfs/deps.rb +0 -67
- data/lib/getch/filesystem/zfs/device.rb +0 -66
- data/lib/getch/filesystem/zfs/encrypt/void.rb +0 -97
- data/lib/getch/filesystem/zfs/format.rb +0 -117
- data/lib/getch/filesystem/zfs/mount.rb +0 -47
- data/lib/getch/filesystem/zfs/partition.rb +0 -69
- data/lib/getch/filesystem/zfs/void.rb +0 -81
- data/lib/getch/gentoo/boot.rb +0 -64
- data/lib/getch/gentoo/chroot.rb +0 -75
- data/lib/getch/gentoo/config.rb +0 -167
- data/lib/getch/gentoo/stage.rb +0 -73
- data/lib/getch/void/boot.rb +0 -84
- data/lib/getch/void/chroot.rb +0 -56
- data/lib/getch/void/config.rb +0 -90
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'open-uri'
|
4
|
+
require 'open3'
|
5
|
+
|
6
|
+
module Getch
|
7
|
+
module Gentoo
|
8
|
+
class Tarball
|
9
|
+
def initialize
|
10
|
+
@log = Log.new
|
11
|
+
@mirror = 'https://mirror.rackspace.com/gentoo'
|
12
|
+
@release = release
|
13
|
+
@stage_file = OPTIONS[:musl] ?
|
14
|
+
"stage3-amd64-musl-#{@release}.tar.xz" :
|
15
|
+
"stage3-amd64-systemd-#{@release}.tar.xz"
|
16
|
+
end
|
17
|
+
|
18
|
+
def x
|
19
|
+
get_stage3
|
20
|
+
control_files
|
21
|
+
checksum
|
22
|
+
install
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def stage3
|
28
|
+
OPTIONS[:musl] ?
|
29
|
+
@mirror + '/releases/amd64/autobuilds/latest-stage3-amd64-musl.txt' :
|
30
|
+
@mirror + '/releases/amd64/autobuilds/latest-stage3-amd64-systemd.txt'
|
31
|
+
end
|
32
|
+
|
33
|
+
def release
|
34
|
+
URI.open(stage3) do |file|
|
35
|
+
file.read.match(/^[[:alnum:]]+/)
|
36
|
+
end
|
37
|
+
rescue Net::OpenTimeout => e
|
38
|
+
@log.fatal "Problem with DNS? #{e}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def file
|
42
|
+
"#{@release}/#{@stage_file}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_stage3
|
46
|
+
Dir.chdir OPTIONS[:mountpoint]
|
47
|
+
return if File.exist? @stage_file
|
48
|
+
|
49
|
+
@log.info "wget #{@stage_file}, please wait...\n"
|
50
|
+
Helpers.get_file_online(@mirror + '/releases/amd64/autobuilds/' + file, @stage_file)
|
51
|
+
end
|
52
|
+
|
53
|
+
def control_files
|
54
|
+
@log.info "Download other files..."
|
55
|
+
['DIGESTS', 'asc', 'CONTENTS.gz'].each do |f|
|
56
|
+
Helpers.get_file_online("#{@mirror}/releases/amd64/autobuilds/#{file}.#{f}", "#{@stage_file}.#{f}")
|
57
|
+
end
|
58
|
+
@log.result_ok
|
59
|
+
end
|
60
|
+
|
61
|
+
def checksum
|
62
|
+
@log.info 'Checking SHA512 checksum...'
|
63
|
+
command = "awk '/SHA512 HASH/{getline;print}' #{@stage_file}.DIGESTS | sha512sum --check"
|
64
|
+
_, stderr, status = Open3.capture3(command)
|
65
|
+
if status.success? then
|
66
|
+
@log.result_ok
|
67
|
+
else
|
68
|
+
cleaning
|
69
|
+
@log.fatal "Problem with the checksum, stderr\n#{stderr}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def install
|
74
|
+
decompress
|
75
|
+
cleaning
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
# https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Stage
|
81
|
+
def decompress
|
82
|
+
cmd = "tar xpf #{@stage_file} --xattrs-include=\'*.*\' --numeric-owner"
|
83
|
+
Getch::Command.new(cmd)
|
84
|
+
end
|
85
|
+
|
86
|
+
def cleaning
|
87
|
+
Dir.glob('stage3-amd64-*').each { |f| File.delete(f) }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Getch
|
2
|
+
module Gentoo
|
3
|
+
class Terraform
|
4
|
+
def initialize
|
5
|
+
x
|
6
|
+
end
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def x
|
11
|
+
Gentoo::Sources.new
|
12
|
+
install_pkgs
|
13
|
+
emerge_deep
|
14
|
+
end
|
15
|
+
|
16
|
+
def install_pkgs
|
17
|
+
@pkgs = 'app-portage/gentoolkit'
|
18
|
+
@pkgs << ' app-admin/sudo'
|
19
|
+
@pkgs << ' app-editors/vim'
|
20
|
+
@pkgs << ' net-firewall/iptables'
|
21
|
+
@pkgs << ' net-wireless/iwd'
|
22
|
+
@pkgs << ' net-misc/dhcpcd' unless Helpers.systemd?
|
23
|
+
@pkgs << ' sys-kernel/linux-firmware'
|
24
|
+
@pkgs << ' sys-firmware/intel-microcode'
|
25
|
+
@pkgs << ' sys-fs/dosfstools' if Helpers.efi?
|
26
|
+
Install.new(@pkgs)
|
27
|
+
end
|
28
|
+
|
29
|
+
def emerge_deep
|
30
|
+
ChrootOutput.new('emerge --deep --newuse @world')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'nito'
|
4
|
+
|
5
|
+
module Getch
|
6
|
+
module Gentoo
|
7
|
+
class Update
|
8
|
+
include NiTo
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@log = Log.new
|
12
|
+
x
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def x
|
18
|
+
sync
|
19
|
+
add_musl_repo if OPTIONS[:musl]
|
20
|
+
update
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def sync
|
26
|
+
gentoo_conf = "#{OPTIONS[:mountpoint]}/etc/portage/repos.conf/gentoo.conf"
|
27
|
+
@log.info "Synchronize index, please waiting...\n"
|
28
|
+
ChrootOutput.new('emaint sync --auto')
|
29
|
+
sed gentoo_conf, /^sync-type/, 'sync-type = rsync'
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_musl_repo
|
33
|
+
Install.new('dev-vcs/git')
|
34
|
+
|
35
|
+
file = "#{OPTIONS[:mountpoint]}/etc/portage/repos.conf/musl.conf"
|
36
|
+
content = <<~CONF
|
37
|
+
[musl]
|
38
|
+
location = /var/db/repos/musl
|
39
|
+
sync-type = git
|
40
|
+
sync-uri = https://github.com/gentoo/musl.git
|
41
|
+
auto-sync = Yes
|
42
|
+
CONF
|
43
|
+
File.write file, "#{content}\n"
|
44
|
+
|
45
|
+
ChrootOutput.new('emaint sync -r musl')
|
46
|
+
end
|
47
|
+
|
48
|
+
def update
|
49
|
+
cmd = 'emerge --update --deep --newuse @world'
|
50
|
+
ChrootOutput.new(cmd)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/getch/gentoo/use.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'nito'
|
4
|
+
|
3
5
|
module Getch
|
4
6
|
module Gentoo
|
5
7
|
class Use
|
8
|
+
include NiTo
|
9
|
+
|
6
10
|
def initialize(pkg = nil)
|
7
|
-
@use_dir = "#{
|
11
|
+
@use_dir = "#{OPTIONS[:mountpoint]}/etc/portage/package.use"
|
8
12
|
@pkg = pkg
|
9
13
|
@file = @pkg ? @pkg.match(/[\w]+$/) : nil
|
10
|
-
@make = "#{
|
14
|
+
@make = "#{OPTIONS[:mountpoint]}/etc/portage/make.conf"
|
11
15
|
end
|
12
16
|
|
13
17
|
def add(*flags)
|
@@ -24,15 +28,14 @@ module Getch
|
|
24
28
|
|
25
29
|
def write
|
26
30
|
content = "#{@pkg} #{@flags}\n"
|
27
|
-
|
31
|
+
echo "#{@use_dir}/#{@file}", content
|
28
32
|
end
|
29
33
|
|
30
34
|
def write_global
|
31
35
|
list = []
|
32
|
-
@flags.each { |f| list << f unless
|
36
|
+
@flags.each { |f| list << f unless grep?(@make, f) }
|
33
37
|
use = list.join(' ')
|
34
|
-
|
35
|
-
File.write(@make, line, mode: 'a')
|
38
|
+
echo_a @make, "USE=\"${USE} #{use}\""
|
36
39
|
end
|
37
40
|
end
|
38
41
|
end
|
@@ -4,13 +4,15 @@ module Getch
|
|
4
4
|
module Gentoo
|
5
5
|
class UseFlag
|
6
6
|
def initialize
|
7
|
-
|
7
|
+
x
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
protected
|
11
|
+
|
12
|
+
def x
|
13
|
+
dist_kernel
|
11
14
|
systemd
|
12
15
|
pam
|
13
|
-
kernel
|
14
16
|
kmod
|
15
17
|
grub
|
16
18
|
zfs
|
@@ -20,41 +22,40 @@ module Getch
|
|
20
22
|
|
21
23
|
private
|
22
24
|
|
25
|
+
# https://wiki.gentoo.org/wiki/Project:Distribution_Kernel#Trying_it_out
|
26
|
+
def dist_kernel
|
27
|
+
use = Getch::Gentoo::Use.new
|
28
|
+
use.add_global('dist-kernel')
|
29
|
+
end
|
30
|
+
|
23
31
|
def systemd
|
32
|
+
return unless Helpers.systemd?
|
33
|
+
|
24
34
|
flags = []
|
25
35
|
use = Getch::Gentoo::Use.new('sys-apps/systemd')
|
26
36
|
flags << 'dns-over-tls'
|
27
|
-
flags << 'gnuefi' if
|
37
|
+
flags << 'gnuefi' if Helpers.efi?
|
28
38
|
use.add(flags)
|
29
39
|
end
|
30
40
|
|
31
41
|
def pam
|
32
42
|
flags = []
|
33
43
|
use = Getch::Gentoo::Use.new('sys-auth/pambase')
|
34
|
-
flags << '-passwdqc'
|
35
|
-
flags << 'pwquality'
|
36
44
|
flags << 'sha512'
|
37
45
|
use.add(flags)
|
38
46
|
end
|
39
47
|
|
40
|
-
def kernel
|
41
|
-
use = Getch::Gentoo::Use.new('sys-kernel/gentoo-kernel')
|
42
|
-
use.add('hardened')
|
43
|
-
end
|
44
|
-
|
45
48
|
def kmod
|
46
49
|
use = Getch::Gentoo::Use.new('sys-apps/kmod')
|
47
50
|
use.add('zstd', 'lzma')
|
48
51
|
end
|
49
52
|
|
50
53
|
def grub
|
51
|
-
return if @efi
|
52
|
-
|
53
54
|
flags = []
|
54
55
|
use = Getch::Gentoo::Use.new('sys-boot/grub')
|
55
|
-
flags << '-grub_platforms_efi-64'
|
56
|
-
flags << 'libzfs' if
|
57
|
-
flags << 'device-mapper' if
|
56
|
+
flags << '-grub_platforms_efi-64' unless Helpers.efi?
|
57
|
+
flags << 'libzfs' if OPTIONS[:fs] == 'zfs'
|
58
|
+
flags << 'device-mapper' if OPTIONS[:fs] == 'lvm' or OPTIONS[:encrypt]
|
58
59
|
use.add(flags)
|
59
60
|
end
|
60
61
|
|
@@ -65,10 +66,6 @@ module Getch
|
|
65
66
|
use.add('rootfs')
|
66
67
|
use = Getch::Gentoo::Use.new('sys-fs/zfs')
|
67
68
|
use.add('rootfs')
|
68
|
-
|
69
|
-
# https://wiki.gentoo.org/wiki/Project:Distribution_Kernel
|
70
|
-
use = Getch::Gentoo::Use.new
|
71
|
-
use.add_global('dist-kernel')
|
72
69
|
end
|
73
70
|
|
74
71
|
def lvm
|
data/lib/getch/gentoo.rb
CHANGED
@@ -1,85 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'gentoo/stage'
|
4
|
-
require_relative 'gentoo/config'
|
5
|
-
require_relative 'gentoo/chroot'
|
6
|
-
require_relative 'gentoo/bootloader'
|
7
3
|
require_relative 'gentoo/sources'
|
8
|
-
require_relative 'gentoo/boot'
|
9
4
|
require_relative 'gentoo/use'
|
10
5
|
require_relative 'gentoo/use_flag'
|
11
6
|
|
12
7
|
module Getch
|
13
8
|
module Gentoo
|
14
|
-
class Main
|
15
|
-
def initialize
|
16
|
-
@state = Getch::States.new
|
17
|
-
end
|
18
|
-
|
19
|
-
def stage3
|
20
|
-
return if STATES[:gentoo_base]
|
21
|
-
|
22
|
-
stage = Getch::Gentoo::Stage.new
|
23
|
-
stage.get_stage3
|
24
|
-
stage.control_files
|
25
|
-
stage.checksum
|
26
|
-
@state.stage3
|
27
|
-
end
|
28
|
-
|
29
|
-
def config
|
30
|
-
return if STATES[:gentoo_config]
|
31
|
-
|
32
|
-
config = Getch::Gentoo::Config.new
|
33
|
-
config.portage
|
34
|
-
config.portage_fs
|
35
|
-
config.portage_bashrc
|
36
|
-
config.repo
|
37
|
-
config.network
|
38
|
-
config.systemd
|
39
|
-
config.hostname
|
40
|
-
@state.config
|
41
|
-
end
|
42
|
-
|
43
|
-
def chroot
|
44
|
-
return if STATES[:gentoo_update]
|
45
|
-
|
46
|
-
chroot = Getch::Gentoo::Chroot.new
|
47
|
-
chroot.update
|
48
|
-
chroot.cpuflags
|
49
|
-
chroot.systemd
|
50
|
-
|
51
|
-
flags = Getch::Gentoo::UseFlag.new
|
52
|
-
flags.apply
|
53
|
-
|
54
|
-
chroot.world
|
55
|
-
chroot.kernel_license
|
56
|
-
chroot.install_pkgs
|
57
|
-
@state.update
|
58
|
-
end
|
59
|
-
|
60
|
-
def bootloader
|
61
|
-
return if STATES[:gentoo_bootloader]
|
62
|
-
|
63
|
-
bootloader = Getch::Gentoo::Bootloader.new
|
64
|
-
bootloader.start
|
65
|
-
@state.bootloader
|
66
|
-
end
|
67
|
-
|
68
|
-
def kernel
|
69
|
-
return if STATES[:gentoo_kernel]
|
70
|
-
|
71
|
-
source = Getch::Gentoo::Sources.new
|
72
|
-
source.bask
|
73
|
-
source.configs
|
74
|
-
source.make
|
75
|
-
source.load_modules
|
76
|
-
@state.kernel
|
77
|
-
end
|
78
|
-
|
79
|
-
def boot
|
80
|
-
boot = Getch::Gentoo::Boot.new
|
81
|
-
boot.start
|
82
|
-
end
|
83
|
-
end
|
84
9
|
end
|
85
10
|
end
|
11
|
+
|
12
|
+
require_relative 'gentoo/tarball'
|
13
|
+
require_relative 'gentoo/pre_config'
|
14
|
+
require_relative 'gentoo/update'
|
15
|
+
require_relative 'gentoo/post_config'
|
16
|
+
require_relative 'gentoo/terraform'
|
17
|
+
require_relative 'gentoo/services'
|
18
|
+
require_relative 'gentoo/bootloader'
|
19
|
+
require_relative 'gentoo/finalize'
|
data/lib/getch/guard.rb
CHANGED
@@ -27,8 +27,8 @@ module Getch
|
|
27
27
|
|
28
28
|
def self.format(name)
|
29
29
|
raise InvalidFormat, 'No format specified.' unless name
|
30
|
-
raise InvalidFormat, "Format #{name} not yet available." if name.match(/btrfs/)
|
31
|
-
raise InvalidFormat, "Format #{name} not supported." unless name.match(/zfs|
|
30
|
+
raise InvalidFormat, "Format #{name} not yet available." if name.match(/btrfs|xfs/)
|
31
|
+
raise InvalidFormat, "Format #{name} not supported." unless name.match(/zfs|ext4/)
|
32
32
|
|
33
33
|
name
|
34
34
|
rescue InvalidFormat => e
|
data/lib/getch/helpers.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'open-uri'
|
4
4
|
require 'open3'
|
5
5
|
require 'fileutils'
|
6
|
+
require 'nito'
|
6
7
|
|
7
8
|
module Getch
|
8
9
|
module Helpers
|
@@ -10,63 +11,40 @@ module Getch
|
|
10
11
|
Dir.exist? '/sys/firmware/efi/efivars'
|
11
12
|
end
|
12
13
|
|
13
|
-
def self.
|
14
|
-
|
15
|
-
File.open(dest, "wb") { |f| f.write(l.read) }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.exec_or_die(cmd)
|
20
|
-
_, stderr, status = Open3.capture3(cmd)
|
21
|
-
unless status.success?
|
22
|
-
raise "Problem running #{cmd}, stderr was:\n#{stderr}"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.create_dir(path, perm = 0755)
|
27
|
-
FileUtils.mkdir_p path, mode: perm unless Dir.exist? path
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.add_file(path, content = '')
|
31
|
-
File.write path, content unless File.exist? path
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.mkdir(dir)
|
35
|
-
FileUtils.mkdir_p dir unless Dir.exist? dir
|
14
|
+
def self.systemd?
|
15
|
+
Dir.exist? "#{OPTIONS[:mountpoint]}/etc/systemd"
|
36
16
|
end
|
37
17
|
|
38
|
-
def self.
|
39
|
-
File.
|
18
|
+
def self.openrc?
|
19
|
+
File.exist? "#{OPTIONS[:mountpoint]}/etc/conf.d/keymaps"
|
40
20
|
end
|
41
21
|
|
42
|
-
def self.
|
43
|
-
|
22
|
+
def self.runit?
|
23
|
+
Dir.exist? "#{OPTIONS[:mountpoint]}/etc/runit"
|
44
24
|
end
|
45
25
|
|
46
|
-
def self.
|
47
|
-
|
48
|
-
|
49
|
-
File.write(src, "#{content}\n", mode: 'a') unless self.grep?(src, content)
|
26
|
+
def self.grub?
|
27
|
+
File.exist? "#{OPTIONS[:mountpoint]}/etc/default/grub"
|
50
28
|
end
|
51
29
|
|
52
|
-
def self.
|
53
|
-
|
54
|
-
|
55
|
-
|
30
|
+
def self.get_file_online(url, dest)
|
31
|
+
URI.open(url) do |l|
|
32
|
+
File.open(dest, "wb") { |f| f.write(l.read) }
|
33
|
+
end
|
34
|
+
rescue Net::OpenTimeout => e
|
35
|
+
abort "DNS error #{e}"
|
56
36
|
end
|
57
37
|
|
58
|
-
def self.
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
f.each { |l| is_found = true if l.match(regex) }
|
38
|
+
def self.exec_or_die(cmd)
|
39
|
+
_, stderr, status = Open3.capture3(cmd)
|
40
|
+
unless status.success?
|
41
|
+
abort "Problem running #{cmd}, stderr was:\n#{stderr}"
|
63
42
|
end
|
64
|
-
is_found
|
65
43
|
end
|
66
44
|
|
67
45
|
def self.sys(cmd)
|
68
46
|
system(cmd)
|
69
|
-
|
47
|
+
$?.success? || abort("Error with #{cmd}")
|
70
48
|
end
|
71
49
|
|
72
50
|
def self.partuuid(dev)
|
@@ -79,39 +57,58 @@ module Getch
|
|
79
57
|
return f.delete_prefix('/dev/disk/by-uuid/')
|
80
58
|
end
|
81
59
|
end
|
60
|
+
Log.new.fatal("UUID on #{dev} is no found")
|
82
61
|
end
|
83
62
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
`lsblk -o PARTUUID #{dev}`.delete("\n").delete('PARTUUID').match(/\w{5}/)
|
89
|
-
else
|
90
|
-
puts 'Please, enter a pool name'
|
91
|
-
while true
|
92
|
-
print "\n> "
|
93
|
-
value = gets
|
94
|
-
if value.match(/[a-z]{4,20}/)
|
95
|
-
return value
|
96
|
-
end
|
97
|
-
puts "Bad name, you enter: #{value}"
|
98
|
-
puts 'Valid pool name use character only, between 4-20.'
|
63
|
+
def self.get_dm(name)
|
64
|
+
Dir.glob('/dev/mapper/*').each do |f|
|
65
|
+
if f =~ /#{name}/ && f != '/dev/mapper/control'
|
66
|
+
return File.readlink(f).tr('../', '')
|
99
67
|
end
|
100
68
|
end
|
69
|
+
Log.new.fatal("Dm for #{name} is no found")
|
101
70
|
end
|
102
71
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
if
|
109
|
-
|
110
|
-
return
|
72
|
+
# Used by ZFS for the pool creation
|
73
|
+
# sleep is necessary here at least the first time
|
74
|
+
def self.get_id(dev)
|
75
|
+
sleep 3
|
76
|
+
Dir.glob('/dev/disk/by-id/*').each do |f|
|
77
|
+
if File.readlink(f).match(/#{dev}/)
|
78
|
+
return f.delete_prefix('/dev/disk/by-id/')
|
111
79
|
end
|
112
|
-
raise "\n[-] Fail cmd #{args} - #{stderr}."
|
113
80
|
end
|
81
|
+
Log.new.fatal("ID on #{dev} is no found")
|
82
|
+
end
|
83
|
+
|
84
|
+
# https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Base
|
85
|
+
def self.mount_all
|
86
|
+
dest = OPTIONS[:mountpoint]
|
87
|
+
NiTo.mount '--types proc /proc', "#{dest}/proc"
|
88
|
+
['dev', 'sys', 'run'].each do |d|
|
89
|
+
NiTo.mount '--rbind', "/#{d}", "#{dest}/#{d}"
|
90
|
+
NiTo.mount '--make-rslave', "#{dest}/#{d}"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.get_memory
|
95
|
+
mem = nil
|
96
|
+
File.open('/proc/meminfo').each do |l|
|
97
|
+
t = l.split(' ') if l =~ /memtotal/i
|
98
|
+
t && mem = t[1]
|
99
|
+
end
|
100
|
+
mem || Log.new.fatal('get_memory - failed to get memory')
|
101
|
+
|
102
|
+
mem += 'K'
|
103
|
+
end
|
114
104
|
|
105
|
+
# get the sector size of a disk
|
106
|
+
def self.get_bs(path)
|
107
|
+
cmd = Getch::Command.new('blockdev', '--getpbsz', path)
|
108
|
+
cmd.res
|
109
|
+
end
|
110
|
+
|
111
|
+
module Void
|
115
112
|
def command_output(args)
|
116
113
|
print " => Exec: #{args}..."
|
117
114
|
cmd = "chroot #{Getch::MOUNTPOINT} /bin/bash -c \"#{args}\""
|
@@ -126,19 +123,6 @@ module Getch
|
|
126
123
|
end
|
127
124
|
end
|
128
125
|
|
129
|
-
def add_line(file, line)
|
130
|
-
raise "No file #{file} found !" unless File.exist? file
|
131
|
-
|
132
|
-
File.write(file, "#{line}\n", mode: 'a')
|
133
|
-
end
|
134
|
-
|
135
|
-
def search(file, text)
|
136
|
-
File.open(file).each do |line|
|
137
|
-
return true if line.match(/#{text}/)
|
138
|
-
end
|
139
|
-
false
|
140
|
-
end
|
141
|
-
|
142
126
|
# Used only when need password
|
143
127
|
def chroot(cmd)
|
144
128
|
unless system('chroot', Getch::MOUNTPOINT, '/bin/bash', '-c', cmd)
|
@@ -162,42 +146,6 @@ module Getch
|
|
162
146
|
|
163
147
|
add_line(conf, "PARTUUID=#{device} #{rest}")
|
164
148
|
end
|
165
|
-
|
166
|
-
def grub_cmdline(*args)
|
167
|
-
conf = "#{Getch::MOUNTPOINT}/etc/default/grub"
|
168
|
-
list = args.join(' ')
|
169
|
-
secs = "GRUB_CMDLINE_LINUX=\"#{list} init_on_alloc=1 init_on_free=1"
|
170
|
-
secs += ' slab_nomerge pti=on slub_debug=ZF vsyscall=none"'
|
171
|
-
raise 'No default/grub found' unless File.exist? conf
|
172
|
-
|
173
|
-
unless search(conf, 'GRUB_CMDLINE_LINUX=')
|
174
|
-
File.write(conf, "#{secs}\n", mode: 'a')
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
module Cryptsetup
|
180
|
-
def encrypt(dev)
|
181
|
-
raise "No device #{dev}" unless File.exist? dev
|
182
|
-
|
183
|
-
puts " => Encrypting device #{dev}..."
|
184
|
-
if Helpers.efi? && Getch::OPTIONS[:os] == 'gentoo'
|
185
|
-
Helpers.sys("cryptsetup luksFormat --type luks #{dev}")
|
186
|
-
else
|
187
|
-
Helpers.sys("cryptsetup luksFormat --type luks1 #{dev}")
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
def open_crypt(dev, map_name)
|
192
|
-
raise "No device #{dev}" unless File.exist? dev
|
193
|
-
|
194
|
-
puts " => Opening encrypted device #{dev}..."
|
195
|
-
if Helpers.efi? && Getch::OPTIONS[:os] == 'gentoo'
|
196
|
-
Helpers.sys("cryptsetup open --type luks #{dev} #{map_name}")
|
197
|
-
else
|
198
|
-
Helpers.sys("cryptsetup open --type luks1 #{dev} #{map_name}")
|
199
|
-
end
|
200
|
-
end
|
201
149
|
end
|
202
150
|
end
|
203
151
|
end
|