getch 0.1.9 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +132 -0
- data/LICENSE +10 -0
- data/README.md +35 -29
- data/bin/getch +8 -6
- data/getch.gemspec +31 -0
- 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 +3 -3
- 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 +144 -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 +113 -74
- 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,150 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'clean'
|
|
4
|
+
require 'nito'
|
|
5
|
+
require 'cryptsetup'
|
|
6
|
+
|
|
7
|
+
module Getch
|
|
8
|
+
class Assembly
|
|
9
|
+
include NiTo
|
|
10
|
+
|
|
11
|
+
def initialize
|
|
12
|
+
@os = Tree::Os.new.select
|
|
13
|
+
@fs = Tree::FS.new.select
|
|
14
|
+
@state = Getch::States.new
|
|
15
|
+
Getch::Device.new
|
|
16
|
+
init_devs
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def init_devs
|
|
20
|
+
DEVS[:root] && return
|
|
21
|
+
|
|
22
|
+
@fs::Device.new
|
|
23
|
+
DEVS[:root] || Log.new.fatal('No root, device prob !')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def clean
|
|
27
|
+
return if STATES[:partition]
|
|
28
|
+
|
|
29
|
+
print "\nPartition and format disk #{OPTIONS[:disk]}, this will erase all data, continue? (y,N) "
|
|
30
|
+
case gets.chomp
|
|
31
|
+
when /^y|^Y/
|
|
32
|
+
else
|
|
33
|
+
exit
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
Clean.new(OPTIONS).x
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def partition
|
|
40
|
+
return if STATES[:partition]
|
|
41
|
+
|
|
42
|
+
@fs::Partition.new
|
|
43
|
+
@state.partition
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def format
|
|
47
|
+
return if STATES[:format]
|
|
48
|
+
|
|
49
|
+
@fs::Format.new
|
|
50
|
+
@state.format
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def mount
|
|
54
|
+
return if STATES[:mount]
|
|
55
|
+
|
|
56
|
+
@fs::Mount.new
|
|
57
|
+
@state.mount
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def tarball
|
|
61
|
+
return if STATES[:tarball]
|
|
62
|
+
|
|
63
|
+
@os::Tarball.new.x
|
|
64
|
+
@state.tarball
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# pre_config
|
|
68
|
+
# Pre configuration before updates and install packages
|
|
69
|
+
# Can contain config for a repository, CPU compilation flags, etc...
|
|
70
|
+
def pre_config
|
|
71
|
+
return if STATES[:pre_config]
|
|
72
|
+
|
|
73
|
+
@os::PreConfig.new
|
|
74
|
+
@state.pre_config
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# update
|
|
78
|
+
# Synchronise and Update the new system
|
|
79
|
+
def update
|
|
80
|
+
return if STATES[:update]
|
|
81
|
+
|
|
82
|
+
Helpers.mount_all
|
|
83
|
+
@os::Update.new
|
|
84
|
+
@state.update
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def post_config
|
|
88
|
+
return if STATES[:post_config]
|
|
89
|
+
|
|
90
|
+
@os::PostConfig.new
|
|
91
|
+
@state.post_config
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# terraform
|
|
95
|
+
# Install all the required packages
|
|
96
|
+
# Also add services
|
|
97
|
+
def terraform
|
|
98
|
+
return if STATES[:terraform]
|
|
99
|
+
|
|
100
|
+
#@fs::PreDeps.new
|
|
101
|
+
@os::Terraform.new
|
|
102
|
+
@fs::Deps.new
|
|
103
|
+
@state.terraform
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def services
|
|
107
|
+
return if STATES[:services]
|
|
108
|
+
|
|
109
|
+
@os::Services.new
|
|
110
|
+
@state.services
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Luks_keys
|
|
114
|
+
# Install external keys to avoid enter password multiple times
|
|
115
|
+
def luks_keys
|
|
116
|
+
return if not OPTIONS[:encrypt] or OPTIONS[:fs] == 'zfs'
|
|
117
|
+
|
|
118
|
+
return if STATES[:luks_keys]
|
|
119
|
+
|
|
120
|
+
CryptSetup.new(DEVS, OPTIONS).keys
|
|
121
|
+
@state.luks_keys
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# bootloader
|
|
125
|
+
# Install and configure Grub2 or Systemd-boot with Dracut
|
|
126
|
+
# Adding keys for Luks
|
|
127
|
+
def bootloader
|
|
128
|
+
return if STATES[:bootloader]
|
|
129
|
+
|
|
130
|
+
bootloader = @os::Bootloader.new
|
|
131
|
+
bootloader.dependencies
|
|
132
|
+
@fs::Config.new
|
|
133
|
+
bootloader.install
|
|
134
|
+
@state.bootloader
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# finalize
|
|
138
|
+
# Password for root, etc
|
|
139
|
+
def finalize
|
|
140
|
+
return if STATES[:finalize]
|
|
141
|
+
|
|
142
|
+
@os::Finalize.new
|
|
143
|
+
puts
|
|
144
|
+
puts '[*!*] Installation finished [*!*]'
|
|
145
|
+
puts
|
|
146
|
+
@fs.end
|
|
147
|
+
@state.finalize
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
data/lib/getch/command.rb
CHANGED
|
@@ -1,161 +1,71 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'open3'
|
|
4
|
+
require 'nito'
|
|
4
5
|
|
|
5
6
|
module Getch
|
|
6
7
|
class Command
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
attr_reader :res
|
|
9
|
+
|
|
10
|
+
def initialize(*args)
|
|
11
|
+
@cmd = args.join(' ')
|
|
10
12
|
@log = Getch::Log.new
|
|
13
|
+
x
|
|
11
14
|
end
|
|
12
15
|
|
|
13
|
-
def
|
|
14
|
-
@
|
|
15
|
-
|
|
16
|
-
Open3.popen3(@cmd) do |stdin, stdout, stderr, wait_thr|
|
|
17
|
-
stdin.close_write
|
|
18
|
-
code = wait_thr.value
|
|
19
|
-
|
|
20
|
-
# only stderr
|
|
21
|
-
begin
|
|
22
|
-
@log.debug stderr.readline until stderr.eof.nil?
|
|
23
|
-
rescue
|
|
24
|
-
end
|
|
16
|
+
def to_s
|
|
17
|
+
@res
|
|
18
|
+
end
|
|
25
19
|
|
|
26
|
-
|
|
27
|
-
files = [stdout, stderr]
|
|
20
|
+
protected
|
|
28
21
|
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
def x
|
|
23
|
+
@log.info 'Exec: ' + @cmd
|
|
24
|
+
cmd = build_cmd
|
|
31
25
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
# exceptions = ready[2]
|
|
26
|
+
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
|
|
27
|
+
stdin.close_write
|
|
28
|
+
code = wait_thr.value
|
|
36
29
|
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
unless code.success?
|
|
31
|
+
begin
|
|
32
|
+
@log.debug stderr.readline until stderr.eof.nil?
|
|
33
|
+
rescue EOFError
|
|
34
|
+
print
|
|
39
35
|
end
|
|
40
|
-
rescue IOError => e
|
|
41
|
-
puts "IOError: #{e}"
|
|
42
36
|
end
|
|
43
37
|
|
|
44
|
-
|
|
45
|
-
@log.
|
|
46
|
-
|
|
38
|
+
if code.success?
|
|
39
|
+
@log.result_ok
|
|
40
|
+
@res = stdout.read.chomp
|
|
41
|
+
return
|
|
47
42
|
end
|
|
48
43
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
private
|
|
54
|
-
|
|
55
|
-
# Returns true if all files are EOF
|
|
56
|
-
def all_eof(files)
|
|
57
|
-
files.find { |f| !f.eof }.nil?
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def display_lines(block)
|
|
61
|
-
block.each do |f|
|
|
62
|
-
begin
|
|
63
|
-
data = f.read_nonblock(@block_size)
|
|
64
|
-
puts data if OPTIONS[:verbose]
|
|
65
|
-
rescue EOFError
|
|
66
|
-
puts
|
|
67
|
-
rescue => e
|
|
68
|
-
puts "Fatal - #{e}"
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
# Use system, the only ruby method to display stdout with colors !
|
|
75
|
-
class Emerge
|
|
76
|
-
def initialize(cmd)
|
|
77
|
-
@gentoo = MOUNTPOINT
|
|
78
|
-
@cmd = cmd
|
|
79
|
-
@log = Getch::Log.new
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def run!
|
|
83
|
-
@log.info "Running emerge: #{@cmd}"
|
|
84
|
-
system('chroot', @gentoo, '/bin/bash', '-c', "source /etc/profile && #{@cmd}")
|
|
85
|
-
read_exit
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def pkg!
|
|
89
|
-
@log.info "Running emerge pkg: #{@cmd}"
|
|
90
|
-
system('chroot', @gentoo, '/bin/bash', '-c', "source /etc/profile && emerge --changed-use #{@cmd}")
|
|
91
|
-
read_exit
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
private
|
|
95
|
-
|
|
96
|
-
def read_exit
|
|
97
|
-
if $?.exitstatus > 0
|
|
44
|
+
puts
|
|
45
|
+
@log.error "#{@cmd} - #{code}"
|
|
98
46
|
@log.fatal "Running #{@cmd}"
|
|
99
|
-
else
|
|
100
|
-
@log.info "Done #{@cmd}"
|
|
101
47
|
end
|
|
102
48
|
end
|
|
103
|
-
end
|
|
104
49
|
|
|
105
|
-
|
|
106
|
-
def initialize(cmd)
|
|
107
|
-
@gentoo = MOUNTPOINT
|
|
108
|
-
@cmd = cmd
|
|
109
|
-
@log = Getch::Log.new
|
|
110
|
-
end
|
|
50
|
+
private
|
|
111
51
|
|
|
112
|
-
def
|
|
113
|
-
@
|
|
114
|
-
cmd = "chroot #{@gentoo} /bin/bash -c \"source /etc/profile \
|
|
115
|
-
&& env-update \
|
|
116
|
-
&& cd /usr/src/linux \
|
|
117
|
-
&& #{@cmd}\""
|
|
118
|
-
Open3.popen2e(cmd) do |_, stdout_err, wait_thr|
|
|
119
|
-
stdout_err.each { |l| puts l }
|
|
120
|
-
|
|
121
|
-
exit_status = wait_thr.value
|
|
122
|
-
unless exit_status.success?
|
|
123
|
-
@log.fatal "Running #{cmd}"
|
|
124
|
-
exit 1
|
|
125
|
-
end
|
|
126
|
-
end
|
|
52
|
+
def build_cmd
|
|
53
|
+
@cmd
|
|
127
54
|
end
|
|
128
55
|
end
|
|
129
56
|
|
|
130
57
|
class Bask
|
|
131
58
|
def initialize(cmd)
|
|
132
59
|
@cmd = cmd
|
|
133
|
-
@log =
|
|
60
|
+
@log = Log.new
|
|
134
61
|
@version = '0.6'
|
|
135
62
|
@config = "#{MOUNTPOINT}/etc/kernel/config.d"
|
|
136
63
|
download_bask unless Dir.exist? "#{MOUNTPOINT}/root/bask-#{@version}"
|
|
137
64
|
end
|
|
138
65
|
|
|
139
|
-
def run!
|
|
140
|
-
@log.info "Running Bask: #{@cmd}"
|
|
141
|
-
cmd = "chroot #{MOUNTPOINT} /bin/bash -c \"source /etc/profile \
|
|
142
|
-
&& env-update \
|
|
143
|
-
&& cd /root/bask-#{@version} \
|
|
144
|
-
&& ./bask.sh #{@cmd} -k /usr/src/linux\""
|
|
145
|
-
Open3.popen2e(cmd) do |_, stdout_err, wait_thr|
|
|
146
|
-
stdout_err.each { |l| puts l }
|
|
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
|
|
155
|
-
|
|
156
66
|
def cp
|
|
157
|
-
|
|
158
|
-
|
|
67
|
+
NiTo.mkdir @config
|
|
68
|
+
NiTo.cp(
|
|
159
69
|
"#{MOUNTPOINT}/root/bask-#{@version}/config.d/#{@cmd}",
|
|
160
70
|
"#{@config}/#{@cmd}"
|
|
161
71
|
)
|
|
@@ -168,20 +78,70 @@ module Getch
|
|
|
168
78
|
private
|
|
169
79
|
|
|
170
80
|
def download_bask
|
|
171
|
-
@log.info
|
|
81
|
+
@log.info "Installing Bask...\n"
|
|
172
82
|
url = "https://github.com/szorfein/bask/archive/refs/tags/#{@version}.tar.gz"
|
|
173
83
|
file = "bask-#{@version}.tar.gz"
|
|
174
84
|
|
|
175
85
|
Dir.chdir("#{MOUNTPOINT}/root")
|
|
176
86
|
Helpers.get_file_online(url, file)
|
|
177
|
-
Getch::Command.new("tar xzf #{file}")
|
|
87
|
+
Getch::Command.new("tar xzf #{file}")
|
|
178
88
|
end
|
|
179
89
|
end
|
|
180
90
|
|
|
181
91
|
class Chroot < Command
|
|
182
|
-
def
|
|
183
|
-
|
|
184
|
-
|
|
92
|
+
def build_cmd
|
|
93
|
+
dest = OPTIONS[:mountpoint]
|
|
94
|
+
case OPTIONS[:os]
|
|
95
|
+
when 'gentoo'
|
|
96
|
+
"chroot #{dest} /bin/bash -c \"source /etc/profile; #{@cmd}\""
|
|
97
|
+
when 'void'
|
|
98
|
+
"chroot #{dest} /bin/bash -c \"#{@cmd}\""
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
class ChrootOutput
|
|
104
|
+
def initialize(*args)
|
|
105
|
+
@cmd = args.join(' ')
|
|
106
|
+
@log = Log.new
|
|
107
|
+
x
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
private
|
|
111
|
+
|
|
112
|
+
def x
|
|
113
|
+
msg
|
|
114
|
+
system('chroot', OPTIONS[:mountpoint], '/bin/bash', '-c', other_args)
|
|
115
|
+
$?.success? && return
|
|
116
|
+
|
|
117
|
+
@log.fatal "Running #{@cmd}"
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def msg
|
|
121
|
+
@log.info "Exec: #{@cmd}...\n"
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def other_args
|
|
125
|
+
case OPTIONS[:os]
|
|
126
|
+
when 'gentoo' then "source /etc/profile && #{@cmd}"
|
|
127
|
+
when 'void' then @cmd
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# Install
|
|
133
|
+
# use system() to install packages
|
|
134
|
+
# Usage: Install.new(pkg_name)
|
|
135
|
+
class Install < ChrootOutput
|
|
136
|
+
def msg
|
|
137
|
+
@log.info "Installing #{@cmd}...\n"
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def other_args
|
|
141
|
+
case OPTIONS[:os]
|
|
142
|
+
when 'gentoo' then "source /etc/profile && emerge --changed-use #{@cmd}"
|
|
143
|
+
when 'void' then "/usr/bin/xbps-install -y #{@cmd}"
|
|
144
|
+
end
|
|
185
145
|
end
|
|
186
146
|
end
|
|
187
147
|
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Getch
|
|
4
|
+
module Config
|
|
5
|
+
class Account
|
|
6
|
+
def initialize
|
|
7
|
+
@user = OPTIONS[:username] ||= nil
|
|
8
|
+
@log = Log.new
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def root
|
|
12
|
+
@log.info "Add a password for root.\n"
|
|
13
|
+
ChrootOutput.new('passwd')
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def new_user
|
|
17
|
+
return unless @user
|
|
18
|
+
|
|
19
|
+
create_user
|
|
20
|
+
@log.info "Add a password for #{@user}.\n"
|
|
21
|
+
ChrootOutput.new("passwd #{@user}")
|
|
22
|
+
fix_perm
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def create_user
|
|
28
|
+
@log.info "Creating a new user #{@user}..."
|
|
29
|
+
Getch::Chroot.new("useradd -m -G users,wheel,audio,video #{@user}")
|
|
30
|
+
@log.result_ok
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def fix_perm
|
|
34
|
+
Getch::Chroot.new("chown -R #{@user}:#{@user} /home/#{@user}")
|
|
35
|
+
Getch::Chroot.new("chmod 700 -R /home/#{@user}")
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'nito'
|
|
4
|
+
|
|
5
|
+
module Getch
|
|
6
|
+
module Config
|
|
7
|
+
class Dhcp
|
|
8
|
+
include NiTo
|
|
9
|
+
|
|
10
|
+
def initialize
|
|
11
|
+
x
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
protected
|
|
15
|
+
|
|
16
|
+
def x
|
|
17
|
+
runit
|
|
18
|
+
systemd
|
|
19
|
+
openrc
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
# https://docs.voidlinux.org/config/network/iwd.html
|
|
25
|
+
def runit
|
|
26
|
+
Helpers.runit? || return
|
|
27
|
+
|
|
28
|
+
echo_a "#{OPTIONS[:mountpoint]}/etc/dhcpcd.conf", 'nohook resolv.conf'
|
|
29
|
+
resolv_conf
|
|
30
|
+
service = '/etc/runit/runsvdir/default/'
|
|
31
|
+
Chroot.new("ln -fs /etc/sv/dhcpcd #{service}")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def systemd
|
|
35
|
+
Helpers.systemd? || return
|
|
36
|
+
|
|
37
|
+
systemd_ethernet
|
|
38
|
+
systemd_wireless
|
|
39
|
+
systemd_resolve
|
|
40
|
+
Chroot.new('systemctl enable systemd-networkd')
|
|
41
|
+
Chroot.new('systemctl enable systemd-resolved')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def openrc
|
|
45
|
+
Helpers.openrc? || return
|
|
46
|
+
|
|
47
|
+
echo_a "#{OPTIONS[:mountpoint]}/etc/dhcpcd.conf", 'nohook resolv.conf'
|
|
48
|
+
resolv_conf
|
|
49
|
+
Chroot.new('rc-update add dhcpcd default')
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# https://www.dnsknowledge.com/tutorials/how-to-setup-quad9-dns-on-a-linux/
|
|
53
|
+
def resolv_conf
|
|
54
|
+
conf = "#{OPTIONS[:mountpoint]}/etc/resolv.conf"
|
|
55
|
+
content = <<~CONF
|
|
56
|
+
nameserver 9.9.9.9
|
|
57
|
+
nameserver 2620:fe::fe
|
|
58
|
+
options rotate
|
|
59
|
+
CONF
|
|
60
|
+
File.write conf, "#{content}\n"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def systemd_ethernet
|
|
64
|
+
conf = "#{OPTIONS[:mountpoint]}/etc/systemd/network/20-ethernet.network"
|
|
65
|
+
content = <<~NETWORK
|
|
66
|
+
[Match]
|
|
67
|
+
Name=en*
|
|
68
|
+
Name=eth*
|
|
69
|
+
[Network]
|
|
70
|
+
DHCP=yes
|
|
71
|
+
IPv6PrivacyExtensions=yes
|
|
72
|
+
[DHCP]
|
|
73
|
+
RouteMetric=512
|
|
74
|
+
NETWORK
|
|
75
|
+
File.write(conf, "#{content}\n")
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def systemd_wireless
|
|
79
|
+
conf = "#{OPTIONS[:mountpoint]}/etc/systemd/network/20-wireless.network"
|
|
80
|
+
content = <<~NETWORK
|
|
81
|
+
[Match]
|
|
82
|
+
Name=wl*
|
|
83
|
+
[Network]
|
|
84
|
+
DHCP=yes
|
|
85
|
+
IPv6PrivacyExtensions=yes
|
|
86
|
+
[DHCP]
|
|
87
|
+
RouteMetric=1024
|
|
88
|
+
NETWORK
|
|
89
|
+
File.write conf, "#{content}\n"
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def systemd_resolve
|
|
93
|
+
mkdir "#{OPTIONS[:mountpoint]}/etc/systemd/resolved.conf.d"
|
|
94
|
+
conf = "#{OPTIONS[:mountpoint]}/etc/systemd/resolved.conf.d/dns_tls.conf"
|
|
95
|
+
content = <<~CONF
|
|
96
|
+
[Resolve]
|
|
97
|
+
DNS=9.9.9.9#dns.quad9.net
|
|
98
|
+
DNSOverTLS=yes
|
|
99
|
+
CONF
|
|
100
|
+
File.write conf, "#{content}\n"
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'nito'
|
|
4
|
+
|
|
5
|
+
module Getch
|
|
6
|
+
module Config
|
|
7
|
+
class Grub
|
|
8
|
+
def initialize
|
|
9
|
+
@log = Log.new
|
|
10
|
+
@disk = OPTIONS[:boot_disk] ||= OPTIONS[:disk]
|
|
11
|
+
# https://wiki.archlinux.org/title/Install_Arch_Linux_on_ZFS
|
|
12
|
+
@prefix = OPTIONS[:fs] == 'zfs' ? 'ZPOOL_VDEV_NAME_PATH=1' : ''
|
|
13
|
+
@os_name = OPTIONS[:os].capitalize
|
|
14
|
+
x
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def x
|
|
18
|
+
@log.info "Installing Grub on #{@disk}...\n"
|
|
19
|
+
Helpers.efi? ? grub_efi : grub_bios
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def grub_efi
|
|
25
|
+
mount_efivars
|
|
26
|
+
cmd = "#{@prefix} grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=\"#{@os_name}\""
|
|
27
|
+
ChrootOutput.new(cmd)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def grub_bios
|
|
31
|
+
cmd = "#{@prefix} grub-install /dev/#{@disk}"
|
|
32
|
+
ChrootOutput.new(cmd)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# In case where efivars is not mounted
|
|
36
|
+
# avoid error with grub
|
|
37
|
+
def mount_efivars
|
|
38
|
+
NiTo.mount '-t efivarfs', 'efivarfs', '/sys/firmware/efi/efivars'
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
module Getch
|
|
2
|
+
module Config
|
|
3
|
+
class Iwd
|
|
4
|
+
include NiTo
|
|
5
|
+
|
|
6
|
+
def initialize
|
|
7
|
+
x
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
protected
|
|
11
|
+
|
|
12
|
+
def x
|
|
13
|
+
runit
|
|
14
|
+
systemd
|
|
15
|
+
openrc
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
# https://docs.voidlinux.org/config/network/iwd.html
|
|
21
|
+
def runit
|
|
22
|
+
Helpers.runit? || return
|
|
23
|
+
|
|
24
|
+
iwd_conf
|
|
25
|
+
service = '/etc/runit/runsvdir/default/'
|
|
26
|
+
Chroot.new("ln -fs /etc/sv/dbus #{service}")
|
|
27
|
+
Chroot.new("ln -fs /etc/sv/iwd #{service}")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def systemd
|
|
31
|
+
Helpers.systemd? || return
|
|
32
|
+
|
|
33
|
+
iwd_conf
|
|
34
|
+
Chroot.new('systemctl enable iwd')
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def openrc
|
|
38
|
+
Helpers.openrc? || return
|
|
39
|
+
|
|
40
|
+
iwd_conf
|
|
41
|
+
Chroot.new('rc-update add iwd default')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# https://docs.voidlinux.org/config/network/iwd.html#troubleshooting
|
|
45
|
+
def iwd_conf
|
|
46
|
+
conf = "#{OPTIONS[:mountpoint]}/etc/iwd/main.conf"
|
|
47
|
+
content = "[General]\n"
|
|
48
|
+
content << "UseDefaultInterface=true\n"
|
|
49
|
+
content << "[Network]\n"
|
|
50
|
+
Helpers.systemd? ?
|
|
51
|
+
content << "NameResolvingService=systemd\n" :
|
|
52
|
+
content << "NameResolvingService=resolvconf\n"
|
|
53
|
+
content << "[Scan]\n"
|
|
54
|
+
content << "DisablePeriodicScan=true\n"
|
|
55
|
+
mkdir "#{OPTIONS[:mountpoint]}/etc/iwd"
|
|
56
|
+
echo conf, "#{content}\n"
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|