getch 0.1.3 → 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 +75 -35
- data/assets/network-stack.conf +63 -0
- data/assets/system.conf +38 -0
- data/bin/getch +14 -4
- data/lib/clean.rb +149 -0
- data/lib/cmdline.rb +128 -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 +94 -124
- 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 +11 -0
- data/lib/getch/config.rb +19 -53
- data/lib/getch/device.rb +67 -0
- data/lib/getch/filesystem/ext4/encrypt/config.rb +11 -68
- data/lib/getch/filesystem/ext4/encrypt/deps.rb +17 -25
- data/lib/getch/filesystem/ext4/encrypt/device.rb +13 -5
- data/lib/getch/filesystem/ext4/encrypt/format.rb +8 -15
- data/lib/getch/filesystem/ext4/encrypt/mount.rb +9 -13
- data/lib/getch/filesystem/ext4/encrypt/partition.rb +10 -82
- data/lib/getch/filesystem/ext4/encrypt/void.rb +63 -0
- data/lib/getch/filesystem/ext4/encrypt.rb +4 -0
- 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/ext4/hybrid/void.rb +62 -0
- 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} +8 -3
- data/lib/getch/filesystem/ext4/minimal/config.rb +25 -0
- data/lib/getch/filesystem/ext4/{device.rb → minimal/deps.rb} +4 -3
- 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 +9 -6
- data/lib/getch/filesystem/zfs/encrypt/config.rb +12 -57
- data/lib/getch/filesystem/zfs/encrypt/deps.rb +7 -86
- data/lib/getch/filesystem/zfs/encrypt/device.rb +9 -45
- data/lib/getch/filesystem/zfs/encrypt/format.rb +8 -90
- data/lib/getch/filesystem/zfs/encrypt/mount.rb +16 -34
- data/lib/getch/filesystem/zfs/encrypt/partition.rb +8 -50
- data/lib/getch/filesystem/zfs/encrypt.rb +4 -0
- 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 +3 -6
- data/lib/getch/filesystem.rb +2 -6
- data/lib/getch/gentoo/bootloader.rb +47 -0
- 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 +82 -52
- 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 +11 -12
- data/lib/getch/gentoo/use_flag.rb +74 -52
- data/lib/getch/gentoo.rb +11 -63
- data/lib/getch/guard.rb +71 -0
- data/lib/getch/helpers.rb +128 -48
- data/lib/getch/log.rb +91 -26
- data/lib/getch/options.rb +79 -40
- data/lib/getch/states.rb +37 -10
- 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/tarball.rb +89 -0
- data/lib/getch/void/terraform.rb +28 -0
- data/lib/getch/void/update.rb +33 -0
- data/lib/getch/void.rb +15 -0
- data/lib/getch.rb +104 -92
- 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 +96 -45
- metadata.gz.sig +0 -0
- data/.gitignore +0 -2
- data/CHANGELOG.md +0 -90
- data/Rakefile +0 -21
- data/bin/setup.sh +0 -90
- data/getch.gemspec +0 -25
- data/lib/getch/filesystem/clean.rb +0 -51
- data/lib/getch/filesystem/device.rb +0 -61
- data/lib/getch/filesystem/ext4/config.rb +0 -58
- data/lib/getch/filesystem/ext4/deps.rb +0 -22
- data/lib/getch/filesystem/ext4/format.rb +0 -28
- data/lib/getch/filesystem/ext4/mount.rb +0 -23
- data/lib/getch/filesystem/ext4/partition.rb +0 -52
- data/lib/getch/filesystem/lvm/config.rb +0 -59
- data/lib/getch/filesystem/lvm/deps.rb +0 -42
- data/lib/getch/filesystem/lvm/device.rb +0 -43
- data/lib/getch/filesystem/lvm/encrypt/config.rb +0 -71
- data/lib/getch/filesystem/lvm/encrypt/deps.rb +0 -46
- data/lib/getch/filesystem/lvm/encrypt/device.rb +0 -46
- data/lib/getch/filesystem/lvm/encrypt/format.rb +0 -32
- data/lib/getch/filesystem/lvm/encrypt/mount.rb +0 -25
- data/lib/getch/filesystem/lvm/encrypt/partition.rb +0 -80
- data/lib/getch/filesystem/lvm/encrypt.rb +0 -15
- data/lib/getch/filesystem/lvm/format.rb +0 -29
- data/lib/getch/filesystem/lvm/mount.rb +0 -23
- data/lib/getch/filesystem/lvm/partition.rb +0 -69
- data/lib/getch/filesystem/mount.rb +0 -56
- data/lib/getch/filesystem/partition.rb +0 -77
- data/lib/getch/filesystem/zfs/config.rb +0 -57
- data/lib/getch/filesystem/zfs/deps.rb +0 -95
- data/lib/getch/filesystem/zfs/device.rb +0 -58
- data/lib/getch/filesystem/zfs/format.rb +0 -114
- data/lib/getch/filesystem/zfs/mount.rb +0 -48
- data/lib/getch/filesystem/zfs/partition.rb +0 -64
- data/lib/getch/gentoo/boot.rb +0 -109
- data/lib/getch/gentoo/chroot.rb +0 -77
- data/lib/getch/gentoo/config.rb +0 -129
- data/lib/getch/gentoo/stage.rb +0 -74
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'nito'
|
4
|
+
|
5
|
+
module Getch
|
6
|
+
module Config
|
7
|
+
# Search and configure the keymap (man loadkeys)
|
8
|
+
class Keymap
|
9
|
+
include NiTo
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@log = Log.new
|
13
|
+
@rc_conf = "#{OPTIONS[:mountpoint]}/etc/rc.conf"
|
14
|
+
@vconsole_conf = "#{OPTIONS[:mountpoint]}/etc/vconsole.conf"
|
15
|
+
@conf_d = "#{OPTIONS[:mountpoint]}/etc/conf.d/keymaps"
|
16
|
+
@keymaps_dir = nil
|
17
|
+
@keymap = nil
|
18
|
+
x
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def x
|
24
|
+
@log.info "Configuring keymap...\n"
|
25
|
+
search_keymap
|
26
|
+
apply_conf
|
27
|
+
end
|
28
|
+
|
29
|
+
def search_keymap
|
30
|
+
search_dir
|
31
|
+
path = "#{OPTIONS[:mountpoint]}#{@keymaps_dir}/**/#{OPTIONS[:keymap]}.map.gz"
|
32
|
+
Dir.glob(path) { |f| @keymap = OPTIONS[:keymap] if f }
|
33
|
+
|
34
|
+
@keymap || @log.fatal("No keymap found for #{OPTIONS[:keymap]}.")
|
35
|
+
end
|
36
|
+
|
37
|
+
def apply_conf
|
38
|
+
@log.info "Setting keymap to \"#{@keymap}\"..."
|
39
|
+
writing_rc_conf
|
40
|
+
writing_vconsole_conf
|
41
|
+
writing_conf_d_keymaps
|
42
|
+
@log.result_ok
|
43
|
+
end
|
44
|
+
|
45
|
+
def writing_rc_conf
|
46
|
+
return unless File.exist? @rc_conf
|
47
|
+
|
48
|
+
echo_a @rc_conf, "KEYMAP=\"#{@keymap}\""
|
49
|
+
end
|
50
|
+
|
51
|
+
def writing_vconsole_conf
|
52
|
+
return unless Helpers.systemd?
|
53
|
+
|
54
|
+
echo_a @vconsole_conf, "KEYMAP=\"#{@keymap}\""
|
55
|
+
end
|
56
|
+
|
57
|
+
def writing_conf_d_keymaps
|
58
|
+
return unless File.exist? @conf_d
|
59
|
+
|
60
|
+
sed @conf_d, /^keymap=/, "keymap=\"#{@keymap}\""
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def search_dir
|
66
|
+
case OPTIONS[:os]
|
67
|
+
when 'gentoo' then @keymaps_dir = '/usr/share/keymaps'
|
68
|
+
when 'void' then @keymaps_dir = '/usr/share/kbd/keymaps'
|
69
|
+
else
|
70
|
+
@log.fatal('OPTIONS[:os] not supported yet.')
|
71
|
+
end
|
72
|
+
|
73
|
+
File.exist? "#{OPTIONS[:mountpoint]}#{@keymaps_dir}" ||
|
74
|
+
@log.fatal("No dir keymaps #{@keymaps_dir} found.")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'nito'
|
4
|
+
|
5
|
+
# Gentoo: https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Base#Locale_generation
|
6
|
+
# Void: https://docs.voidlinux.org/config/locales.html#locales-and-translations
|
7
|
+
module Getch
|
8
|
+
module Config
|
9
|
+
class Locale
|
10
|
+
include NiTo
|
11
|
+
|
12
|
+
# Gentoo use i18n_supported
|
13
|
+
# Void use libc_locale
|
14
|
+
def initialize
|
15
|
+
@log = Log.new
|
16
|
+
@i18n_supported = "#{OPTIONS[:mountpoint]}/usr/share/i18n/SUPPORTED"
|
17
|
+
@libc_locales = "#{OPTIONS[:mountpoint]}/etc/default/libc-locales"
|
18
|
+
@locale_conf = "#{OPTIONS[:mountpoint]}/etc/locale.conf"
|
19
|
+
@i18n = nil
|
20
|
+
@lang = nil
|
21
|
+
x
|
22
|
+
end
|
23
|
+
|
24
|
+
def x
|
25
|
+
@log.info "Configuring locales...\n"
|
26
|
+
search_locale
|
27
|
+
apply_conf
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def search_locale
|
33
|
+
search_i18n
|
34
|
+
search_libc
|
35
|
+
lang
|
36
|
+
end
|
37
|
+
|
38
|
+
def apply_conf
|
39
|
+
return if OPTIONS[:musl]
|
40
|
+
|
41
|
+
File.exist?("#{OPTIONS[:mountpoint]}/etc/locale.gen") && write_locale_gen
|
42
|
+
File.exist?(@libc_locales) && write_libc_locales
|
43
|
+
end
|
44
|
+
|
45
|
+
def write_locale_gen
|
46
|
+
@log.fatal("No UTF8 locale found for #{OPTIONS[:language]}") unless @i18n
|
47
|
+
|
48
|
+
@log.info "Using locale #{@i18n}...\n"
|
49
|
+
echo "#{OPTIONS[:mountpoint]}/etc/locale.gen", @i18n
|
50
|
+
locale_conf
|
51
|
+
Getch::Chroot.new('locale-gen')
|
52
|
+
end
|
53
|
+
|
54
|
+
def write_libc_locales
|
55
|
+
@log.fatal("No UTF8 locale found for #{OPTIONS[:language]}") unless @i18n
|
56
|
+
|
57
|
+
@log.info "Using locale #{@i18n}...\n"
|
58
|
+
echo @libc_locales, @i18n
|
59
|
+
locale_conf
|
60
|
+
Getch::Chroot.new('xbps-reconfigure -f glibc-locales')
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def search_i18n
|
66
|
+
return unless File.exist? @i18n_supported
|
67
|
+
|
68
|
+
File.open(@i18n_supported).each do |l|
|
69
|
+
@i18n = l.chomp if l =~ /#{OPTIONS[:language]}.*UTF-8$/
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def search_libc
|
74
|
+
return unless File.exist? @libc_locales
|
75
|
+
|
76
|
+
File.open(@libc_locales).each do |l|
|
77
|
+
@i18n = l.tr('#', '').chomp if l =~ /\#?#{OPTIONS[:language]}.*UTF-8/
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def lang
|
82
|
+
return unless @i18n
|
83
|
+
|
84
|
+
lang = @i18n.split(' ')
|
85
|
+
@lang = lang[0]
|
86
|
+
end
|
87
|
+
|
88
|
+
def locale_conf
|
89
|
+
return unless Helpers.systemd?
|
90
|
+
|
91
|
+
echo @locale_conf, "LANG=#{@lang}"
|
92
|
+
echo_a @locale_conf, 'LC_COLLATE=C.UTF-8'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'nito'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
module Getch
|
5
|
+
module Config
|
6
|
+
class Portage
|
7
|
+
include NiTo
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@log = Log.new
|
11
|
+
@dest = "#{OPTIONS[:mountpoint]}/etc/portage"
|
12
|
+
@usr_s = "#{OPTIONS[:mountpoint]}/usr/share/portage"
|
13
|
+
x
|
14
|
+
end
|
15
|
+
|
16
|
+
def x
|
17
|
+
@log.info "Configuring Portage...\n"
|
18
|
+
portage_dir
|
19
|
+
gentoo_repo
|
20
|
+
cpu_conf
|
21
|
+
make_conf
|
22
|
+
https_mirror
|
23
|
+
license
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def portage_dir
|
29
|
+
mkdir "#{@dest}/package.use", 0744
|
30
|
+
mkdir "#{@dest}/package.accept_keywords", 0744
|
31
|
+
mkdir "#{@dest}/package.unmask", 0744
|
32
|
+
mkdir "#{@dest}/package.license", 0744
|
33
|
+
|
34
|
+
touch "#{@dest}/package.use/zzz_via_autounmask"
|
35
|
+
touch "#{@dest}/package.accept_keywords/zzz_via_autounmask"
|
36
|
+
touch "#{@dest}/package.unmask/zzz_via_autounmask"
|
37
|
+
end
|
38
|
+
|
39
|
+
# Recreate a gentoo.conf from /usr/share/portage/config/repos.conf
|
40
|
+
def gentoo_repo
|
41
|
+
mkdir "#{@dest}/repos.conf", 0644
|
42
|
+
cp "#{@usr_s}/config/repos.conf", "#{@dest}/repos.conf/gentoo.conf"
|
43
|
+
sed "#{@dest}/repos.conf/gentoo.conf", /^sync-type/, 'sync-type = webrsync'
|
44
|
+
end
|
45
|
+
|
46
|
+
# -fomit-frame-pointer reduce code compiled
|
47
|
+
# but have repercussions on the debugging of applications
|
48
|
+
def cpu_conf
|
49
|
+
change = 'COMMON_FLAGS="-march=native -O2 -pipe -fomit-frame-pointer"'
|
50
|
+
sed "#{@dest}/make.conf", /^COMMON_FLAGS/, change
|
51
|
+
end
|
52
|
+
|
53
|
+
# https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Stage#MAKEOPTS
|
54
|
+
def make_conf
|
55
|
+
mem = get_memory
|
56
|
+
makeopts = mem[0].to_i / 2
|
57
|
+
|
58
|
+
echo_a "#{@dest}/make.conf", 'ACCEPT_KEYWORDS="amd64"'
|
59
|
+
echo_a "#{@dest}/make.conf", 'INPUT_DEVICES="libinput"'
|
60
|
+
echo_a "#{@dest}/make.conf", "MAKEOPTS=\"-j#{makeopts}\""
|
61
|
+
end
|
62
|
+
|
63
|
+
# https://www.gentoo.org/downloads/mirrors/
|
64
|
+
def https_mirror
|
65
|
+
list = 'https://gentoo.osuosl.org'
|
66
|
+
list << ' https://mirrors.rit.edu/gentoo'
|
67
|
+
list << ' https://ftp.belnet.be/pub/rsync.gentoo.org/gentoo'
|
68
|
+
list << ' https://mirror.init7.net/gentoo'
|
69
|
+
echo_a "#{@dest}/make.conf", "GENTOO_MIRRORS=\"#{list}\""
|
70
|
+
end
|
71
|
+
|
72
|
+
def license
|
73
|
+
conf = "#{@dest}/package.license/kernel"
|
74
|
+
echo conf, 'sys-kernel/linux-firmware @BINARY-REDISTRIBUTABLE'
|
75
|
+
echo_a conf, 'sys-firmware/intel-microcode intel-ucode'
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def get_memory
|
81
|
+
mem = '2048'
|
82
|
+
File.open('/proc/meminfo').each do |l|
|
83
|
+
t = l.split(' ') if l =~ /memtotal/i
|
84
|
+
t && mem = t[1]
|
85
|
+
end
|
86
|
+
mem
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'nito'
|
2
|
+
|
3
|
+
module Getch
|
4
|
+
module Config
|
5
|
+
class PreNetwork
|
6
|
+
include NiTo
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@log = Log.new
|
10
|
+
x
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def x
|
16
|
+
@log.info "Configuring pre-network...\n"
|
17
|
+
hostname
|
18
|
+
copy_dns
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def hostname
|
24
|
+
@log.info 'Writing /etc/hostname...'
|
25
|
+
echo "#{OPTIONS[:mountpoint]}/etc/hostname", 'host'
|
26
|
+
@log.result_ok
|
27
|
+
end
|
28
|
+
|
29
|
+
def copy_dns
|
30
|
+
@log.info 'Copying DNS from current host...'
|
31
|
+
cp '/etc/resolv.conf', "#{OPTIONS[:mountpoint]}/etc/resolv.conf"
|
32
|
+
echo_a "#{OPTIONS[:mountpoint]}/etc/resolv.conf", 'nameserver 127.0.0.1'
|
33
|
+
@log.result_ok
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'nito'
|
4
|
+
|
5
|
+
module Getch
|
6
|
+
module Config
|
7
|
+
class TimeZone
|
8
|
+
include NiTo
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@log = Log.new
|
12
|
+
@etc_timezone = "#{OPTIONS[:mountpoint]}/etc/timezone"
|
13
|
+
@rc_conf = "#{OPTIONS[:mountpoint]}/etc/rc.conf"
|
14
|
+
@openrc = "#{OPTIONS[:mountpoint]}/etc/conf.d/keymaps"
|
15
|
+
@timezone = OPTIONS[:timezone]
|
16
|
+
x
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def x
|
22
|
+
@log.info "Configuring timezone to #{@timezone}...\n"
|
23
|
+
for_runit
|
24
|
+
for_openrc
|
25
|
+
for_systemd
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def for_runit
|
31
|
+
return unless Helpers.runit?
|
32
|
+
|
33
|
+
echo_a @rc_conf, "TIMEZONE=\"#{@timezone}\""
|
34
|
+
end
|
35
|
+
|
36
|
+
def for_openrc
|
37
|
+
return unless Helpers.openrc?
|
38
|
+
|
39
|
+
echo_a @etc_timezone, OPTIONS[:timezone]
|
40
|
+
Getch::Chroot.new('emerge --config sys-libs/timezone-data')
|
41
|
+
end
|
42
|
+
|
43
|
+
def for_systemd
|
44
|
+
return unless Helpers.systemd?
|
45
|
+
|
46
|
+
src = "/usr/share/zoneinfo/#{OPTIONS[:timezone]}"
|
47
|
+
dest = "/etc/localtime"
|
48
|
+
Getch::Chroot.new('ln', '-sf', src, dest)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/getch/config.rb
CHANGED
@@ -1,58 +1,24 @@
|
|
1
|
-
|
2
|
-
class Config
|
3
|
-
def initialize
|
4
|
-
@systemd_net_dir = "#{MOUNTPOINT}/etc/systemd"
|
5
|
-
end
|
6
|
-
|
7
|
-
def network
|
8
|
-
ethernet
|
9
|
-
wifi
|
10
|
-
resolved
|
11
|
-
Getch::Chroot.new('systemctl enable systemd-networkd').run!
|
12
|
-
Getch::Chroot.new('systemctl enable systemd-resolved').run!
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
1
|
+
# frozen_string_literal: true
|
16
2
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
"Name=eth*",
|
23
|
-
"[Network]",
|
24
|
-
"DHCP=yes",
|
25
|
-
"IPv6PrivacyExtensions=yes",
|
26
|
-
"[DHCP]",
|
27
|
-
"RouteMetric=512"
|
28
|
-
]
|
29
|
-
File.write(conf, datas.join("\n"), mode: 'w')
|
30
|
-
end
|
31
|
-
|
32
|
-
def wifi
|
33
|
-
conf = "#{@systemd_net_dir}/network/20-wireless.network"
|
34
|
-
datas = [
|
35
|
-
"[Match]",
|
36
|
-
"Name=wlp*",
|
37
|
-
"Name=wlan*",
|
38
|
-
"[Network]",
|
39
|
-
"DHCP=yes",
|
40
|
-
"IPv6PrivacyExtensions=yes",
|
41
|
-
"[DHCP]",
|
42
|
-
"RouteMetric=1024",
|
43
|
-
]
|
44
|
-
File.write(conf, datas.join("\n"), mode: 'w')
|
45
|
-
end
|
3
|
+
module Getch
|
4
|
+
module Config
|
5
|
+
def sysctl
|
6
|
+
pwd = File.expand_path(File.dirname(__FILE__))
|
7
|
+
dest = "#{Getch::MOUNTPOINT}/etc/sysctl.d/"
|
46
8
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
"[Resolve]",
|
51
|
-
"DNS=9.9.9.9#dns.quad9.net",
|
52
|
-
"DNSOverTLS=yes",
|
53
|
-
]
|
54
|
-
Helpers::create_dir("#{@systemd_net_dir}/resolved.conf.d")
|
55
|
-
File.write(conf, datas.join("\n"), mode: 'w')
|
9
|
+
mkdir dest
|
10
|
+
Helpers.cp("#{pwd}/../../assets/network-stack.conf", dest)
|
11
|
+
Helpers.cp("#{pwd}/../../assets/system.conf", dest)
|
56
12
|
end
|
57
13
|
end
|
58
14
|
end
|
15
|
+
|
16
|
+
require_relative 'config/portage'
|
17
|
+
require_relative 'config/locale'
|
18
|
+
require_relative 'config/pre_network'
|
19
|
+
require_relative 'config/keymap'
|
20
|
+
require_relative 'config/timezone'
|
21
|
+
require_relative 'config/grub'
|
22
|
+
require_relative 'config/account'
|
23
|
+
require_relative 'config/iwd'
|
24
|
+
require_relative 'config/dhcp'
|
data/lib/getch/device.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module Getch
|
6
|
+
class Device
|
7
|
+
def initialize
|
8
|
+
@file = File.join('/tmp/getch_devs.yaml')
|
9
|
+
load_devs
|
10
|
+
end
|
11
|
+
|
12
|
+
def gpt(dev)
|
13
|
+
DEVS[:gpt] = dev
|
14
|
+
save
|
15
|
+
end
|
16
|
+
|
17
|
+
def efi(dev)
|
18
|
+
DEVS[:efi] = dev
|
19
|
+
save
|
20
|
+
end
|
21
|
+
|
22
|
+
def boot(dev)
|
23
|
+
DEVS[:boot] = dev
|
24
|
+
save
|
25
|
+
end
|
26
|
+
|
27
|
+
def swap(dev)
|
28
|
+
DEVS[:swap] = dev
|
29
|
+
save
|
30
|
+
end
|
31
|
+
|
32
|
+
def root(dev)
|
33
|
+
DEVS[:root] = dev
|
34
|
+
save
|
35
|
+
end
|
36
|
+
|
37
|
+
def home(dev)
|
38
|
+
DEVS[:home] = dev
|
39
|
+
save
|
40
|
+
end
|
41
|
+
|
42
|
+
def zlog(dev)
|
43
|
+
DEVS[:zlog] = dev
|
44
|
+
save
|
45
|
+
end
|
46
|
+
|
47
|
+
def zcache(dev)
|
48
|
+
DEVS[:zcache] = dev
|
49
|
+
save
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def load_devs
|
55
|
+
if File.exist? @file
|
56
|
+
DEVS.merge! YAML.load_file @file
|
57
|
+
else
|
58
|
+
save
|
59
|
+
warn "Init devs at #{@file}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def save
|
64
|
+
File.open(@file, 'w') { |f| YAML.dump(DEVS, f) }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -1,81 +1,24 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fstab'
|
4
|
+
require 'dracut'
|
5
|
+
require 'cryptsetup'
|
2
6
|
|
3
7
|
module Getch
|
4
8
|
module FileSystem
|
5
9
|
module Ext4
|
6
10
|
module Encrypt
|
7
|
-
class Config
|
11
|
+
class Config
|
8
12
|
def initialize
|
9
|
-
|
10
|
-
gen_uuid
|
11
|
-
@root_dir = MOUNTPOINT
|
12
|
-
@init = '/usr/lib/systemd/systemd'
|
13
|
-
move_secret_keys
|
14
|
-
crypttab
|
15
|
-
end
|
16
|
-
|
17
|
-
def fstab
|
18
|
-
file = "#{@root_dir}/etc/fstab"
|
19
|
-
datas = data_fstab
|
20
|
-
File.write(file, datas.join("\n"))
|
21
|
-
end
|
22
|
-
|
23
|
-
def systemd_boot
|
24
|
-
return if ! Helpers::efi?
|
25
|
-
esp = '/efi'
|
26
|
-
dir = "#{@root_dir}/#{esp}/loader/entries/"
|
27
|
-
datas_gentoo = [
|
28
|
-
'title Gentoo Linux',
|
29
|
-
'linux /vmlinuz',
|
30
|
-
'initrd /initramfs',
|
31
|
-
"options crypt_root=UUID=#{@uuid_dev_root} root=/dev/mapper/root init=#{@init} keymap=#{DEFAULT_OPTIONS[:keymap]} rw"
|
32
|
-
]
|
33
|
-
File.write("#{dir}/gentoo.conf", datas_gentoo.join("\n"))
|
34
|
-
end
|
35
|
-
|
36
|
-
def crypttab
|
37
|
-
home = @home_disk ? "crypthome UUID=#{@uuid_home} /root/secretkeys/crypto_keyfile.bin luks" : ''
|
38
|
-
datas = [
|
39
|
-
"cryptswap PARTUUID=#{@partuuid_swap} /dev/urandom swap,cipher=aes-xts-plain64:sha256,size=512",
|
40
|
-
home
|
41
|
-
]
|
42
|
-
File.write("#{@root_dir}/etc/crypttab", datas.join("\n"))
|
43
|
-
end
|
44
|
-
|
45
|
-
def grub
|
46
|
-
return if Helpers::efi?
|
47
|
-
file = "#{@root_dir}/etc/default/grub"
|
48
|
-
cmdline = [
|
49
|
-
"GRUB_CMDLINE_LINUX=\"crypt_root=UUID=#{@uuid_dev_root} root=/dev/mapper/root init=#{@init} rw slub_debug=P page_poison=1 slab_nomerge pti=on vsyscall=none spectre_v2=on spec_store_bypass_disable=seccomp iommu=force keymap=#{DEFAULT_OPTIONS[:keymap]}\"",
|
50
|
-
"GRUB_ENABLE_CRYPTODISK=y"
|
51
|
-
]
|
52
|
-
File.write(file, cmdline.join("\n"), mode: 'a')
|
13
|
+
x
|
53
14
|
end
|
54
15
|
|
55
16
|
private
|
56
17
|
|
57
|
-
def
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
@uuid_root = `lsblk -d -o "UUID" #{@luks_root} | tail -1`.chomp() if @dev_root
|
62
|
-
@uuid_home = `lsblk -d -o "UUID" #{@dev_home} | tail -1`.chomp() if @luks_home
|
63
|
-
end
|
64
|
-
|
65
|
-
def data_fstab
|
66
|
-
boot_efi = @dev_esp ? "UUID=#{@uuid_esp} /efi vfat noauto,noatime 1 2" : ''
|
67
|
-
swap = @dev_swap ? "#{@luks_swap} none swap discard 0 0 " : ''
|
68
|
-
root = @dev_root ? "UUID=#{@uuid_root} / ext4 defaults 0 1" : ''
|
69
|
-
home = @dev_home ? "#{@luks_home} /home/#{@user} ext4 defaults 0 2" : ''
|
70
|
-
|
71
|
-
[ boot_efi, swap, root, home ]
|
72
|
-
end
|
73
|
-
|
74
|
-
def move_secret_keys
|
75
|
-
return if ! @luks_home
|
76
|
-
puts "Moving secret keys"
|
77
|
-
keys_path = "#{@root_dir}/root/secretkeys"
|
78
|
-
FileUtils.mv("/root/secretkeys", keys_path) if ! Dir.exist?(keys_path)
|
18
|
+
def x
|
19
|
+
Fstab::Encrypt.new(DEVS, OPTIONS).generate
|
20
|
+
Dracut::Encrypt.new(DEVS, OPTIONS).generate
|
21
|
+
CryptSetup.new(DEVS, OPTIONS).configs
|
79
22
|
end
|
80
23
|
end
|
81
24
|
end
|
@@ -1,40 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Getch
|
2
4
|
module FileSystem
|
3
5
|
module Ext4
|
4
6
|
module Encrypt
|
5
7
|
class Deps
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
Getch::Make.new("genkernel --kernel-config=/usr/src/linux/.config all").run!
|
8
|
+
def initialize
|
9
|
+
install
|
10
|
+
service
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
|
+
protected
|
13
14
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
'INSTALL="yes"',
|
20
|
-
'MENUCONFIG="no"',
|
21
|
-
'CLEAN="yes"',
|
22
|
-
'KEYMAP="yes"',
|
23
|
-
'SAVE_CONFIG="yes"',
|
24
|
-
'MOUNTBOOT="yes"',
|
25
|
-
'MRPROPER="no"',
|
26
|
-
'LUKS="yes"',
|
27
|
-
]
|
28
|
-
file = "#{MOUNTPOINT}/etc/genkernel.conf"
|
29
|
-
File.write(file, datas.join("\n"), mode: 'a')
|
15
|
+
def install
|
16
|
+
case OPTIONS[:os]
|
17
|
+
when 'gentoo' then Install.new('sys-fs/cryptsetup')
|
18
|
+
when 'void' then Install.new('cryptsetup')
|
19
|
+
end
|
30
20
|
end
|
31
21
|
|
32
|
-
def
|
33
|
-
|
22
|
+
def service
|
23
|
+
openrc
|
34
24
|
end
|
35
25
|
|
36
|
-
def
|
37
|
-
|
26
|
+
def openrc
|
27
|
+
Helpers.openrc? || return
|
28
|
+
|
29
|
+
Chroot.new('rc-update add dmcrypt boot')
|
38
30
|
end
|
39
31
|
end
|
40
32
|
end
|
@@ -1,13 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'devs'
|
4
|
+
|
1
5
|
module Getch
|
2
6
|
module FileSystem
|
3
7
|
module Ext4
|
4
8
|
module Encrypt
|
5
|
-
class Device
|
9
|
+
class Device
|
6
10
|
def initialize
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
@args = { start: true, boot: true, swap: true, root: true }
|
12
|
+
x
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def x
|
18
|
+
Devs::Settings.new(@args, OPTIONS)
|
11
19
|
end
|
12
20
|
end
|
13
21
|
end
|