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
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
module Getch
|
4
|
-
module FileSystem
|
5
|
-
module Zfs
|
6
|
-
class Mount < Getch::FileSystem::Zfs::Device
|
7
|
-
def initialize
|
8
|
-
super
|
9
|
-
@root_dir = MOUNTPOINT
|
10
|
-
@mount = Getch::FileSystem::Mount.new
|
11
|
-
@state = Getch::States.new
|
12
|
-
@log = Getch::Log.new
|
13
|
-
end
|
14
|
-
|
15
|
-
def run
|
16
|
-
return if STATES[:mount]
|
17
|
-
exec("zpool export -a")
|
18
|
-
exec("rm -rf #{MOUNTPOINT}/*")
|
19
|
-
exec("zpool import -N -R #{MOUNTPOINT} #{@pool_name}")
|
20
|
-
exec("zpool import -N -R #{MOUNTPOINT} #{@boot_pool_name}") if @dev_boot
|
21
|
-
@mount.swap(@dev_swap)
|
22
|
-
mount_root
|
23
|
-
mount_boot
|
24
|
-
@mount.esp(@dev_esp)
|
25
|
-
exec("zfs mount -a")
|
26
|
-
@state.mount
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def mount_root
|
32
|
-
Helpers::mkdir(@root_dir)
|
33
|
-
exec("zfs mount #{@pool_name}/ROOT/gentoo")
|
34
|
-
end
|
35
|
-
|
36
|
-
def mount_boot
|
37
|
-
return if ! @dev_boot
|
38
|
-
exec("zfs mount #{@boot_pool_name}/BOOT/gentoo")
|
39
|
-
end
|
40
|
-
|
41
|
-
def exec(cmd)
|
42
|
-
@log.info("==> #{cmd}")
|
43
|
-
Helpers::sys(cmd)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
module Getch
|
2
|
-
module FileSystem
|
3
|
-
module Zfs
|
4
|
-
class Partition < Getch::FileSystem::Zfs::Device
|
5
|
-
def initialize
|
6
|
-
super
|
7
|
-
@clean = Getch::FileSystem::Clean
|
8
|
-
@partition = Getch::FileSystem::Partition.new
|
9
|
-
@state = Getch::States.new()
|
10
|
-
@log = Getch::Log.new()
|
11
|
-
run_partition
|
12
|
-
end
|
13
|
-
|
14
|
-
def run_partition
|
15
|
-
return if STATES[:partition ]
|
16
|
-
@clean.old_zpool
|
17
|
-
@clean.struct(@disk, @cache_disk, @home_disk)
|
18
|
-
@clean.hdd(@disk, @cache_disk, @home_disk)
|
19
|
-
partition
|
20
|
-
cache
|
21
|
-
@state.partition
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def partition
|
27
|
-
if @efi
|
28
|
-
@partition.efi(@dev_esp)
|
29
|
-
@partition.swap(@dev_swap)
|
30
|
-
@partition.root(@dev_root, "BF00") if @root_part != 1
|
31
|
-
else
|
32
|
-
@partition.gpt(@dev_gpt)
|
33
|
-
# Boot pool for GRUB2
|
34
|
-
@partition.boot(@dev_boot)
|
35
|
-
@partition.swap(@dev_swap)
|
36
|
-
@partition.root(@dev_root, "BF00") if @root_part != 1
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def cache
|
41
|
-
if @dev_log
|
42
|
-
exec("sgdisk -n2:0:+4G -t2:BF07 #{cache_disk}")
|
43
|
-
end
|
44
|
-
if @dev_cache
|
45
|
-
exec("sgdisk -n3:0:0 -t3:BF08 #{cache_disk}")
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# Partition_efi
|
50
|
-
# /efi - EFI system partition - 260MB
|
51
|
-
# / - Root
|
52
|
-
|
53
|
-
# Partition_bios
|
54
|
-
# None - Bios Boot Partition - 1MiB
|
55
|
-
# /boot - Boot - 8300
|
56
|
-
# / - Root
|
57
|
-
|
58
|
-
def exec(cmd)
|
59
|
-
Getch::Command.new(cmd).run!
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
data/lib/getch/gentoo/boot.rb
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
module Getch
|
4
|
-
module Gentoo
|
5
|
-
class Boot
|
6
|
-
def initialize(opts)
|
7
|
-
@disk = opts.boot_disk ? opts.boot_disk : opts.disk
|
8
|
-
@user = opts.username
|
9
|
-
@config = Getch.class_fs::Config.new()
|
10
|
-
end
|
11
|
-
|
12
|
-
def start
|
13
|
-
@config.fstab
|
14
|
-
bootloader
|
15
|
-
password
|
16
|
-
permission
|
17
|
-
the_end
|
18
|
-
end
|
19
|
-
|
20
|
-
def bootloader
|
21
|
-
if Helpers::efi?
|
22
|
-
bootctl
|
23
|
-
else
|
24
|
-
grub
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# bootctl is alrealy installed with the stage3-amd64-systemd
|
29
|
-
def bootctl
|
30
|
-
bootctl_dep
|
31
|
-
puts "Configuring systemd-boot."
|
32
|
-
# ref: https://forums.gentoo.org/viewtopic-p-8118822.html
|
33
|
-
esp = '/efi'
|
34
|
-
Getch::Chroot.new("bootctl --path #{esp} install").run!
|
35
|
-
datas_loader = [
|
36
|
-
'default gentoo',
|
37
|
-
'timeout 3',
|
38
|
-
'editor 0'
|
39
|
-
]
|
40
|
-
@config.systemd_boot
|
41
|
-
File.write("#{MOUNTPOINT}/#{esp}/loader/loader.conf", datas_loader.join("\n"))
|
42
|
-
|
43
|
-
FileUtils.cp("#{MOUNTPOINT}/usr/src/linux/arch/x86/boot/bzImage", "#{MOUNTPOINT}/#{esp}/vmlinuz", preserve: true)
|
44
|
-
|
45
|
-
initramfs = Dir.glob("#{MOUNTPOINT}/boot/initramfs-*.img")
|
46
|
-
FileUtils.cp("#{initramfs[0]}", "#{MOUNTPOINT}/#{esp}/initramfs", preserve: true) if initramfs != []
|
47
|
-
|
48
|
-
Getch::Chroot.new("bootctl --path #{esp} update").run!
|
49
|
-
end
|
50
|
-
|
51
|
-
def bootctl_dep
|
52
|
-
puts 'Installing systemd-boot...'
|
53
|
-
Getch::Emerge.new("efivar").pkg!
|
54
|
-
end
|
55
|
-
|
56
|
-
def grub
|
57
|
-
puts 'Installing GRUB...'
|
58
|
-
Getch::Emerge.new("sys-boot/grub:2").pkg!
|
59
|
-
@config.grub
|
60
|
-
Getch::Chroot.new("grub-install /dev/#{@disk}").run!
|
61
|
-
Getch::Chroot.new("grub-mkconfig -o /boot/grub/grub.cfg").run!
|
62
|
-
end
|
63
|
-
|
64
|
-
def password
|
65
|
-
puts 'Password for root'
|
66
|
-
cmd = "chroot #{MOUNTPOINT} /bin/bash -c \"source /etc/profile && passwd\""
|
67
|
-
system(cmd)
|
68
|
-
if @user
|
69
|
-
puts "Creating user #{@user}"
|
70
|
-
Getch::Chroot.new("useradd -m -G users,wheel,audio,video #{@user}").run!
|
71
|
-
puts "Password for your user #{@user}"
|
72
|
-
cmd = "chroot #{MOUNTPOINT} /bin/bash -c \"source /etc/profile && passwd #{@user}\""
|
73
|
-
system(cmd)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
private
|
78
|
-
|
79
|
-
def permission
|
80
|
-
FileUtils.chmod_R 0755, "#{MOUNTPOINT}/etc/portage"
|
81
|
-
if @user
|
82
|
-
Getch::Chroot.new("chown -R #{@user}:#{@user} /home/#{@user}").run!
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def the_end
|
87
|
-
#Helpers::exec_or_die("umount -l /mnt/gentoo/dev{/shm,/pts,}")
|
88
|
-
#Helpers::exec_or_die("umount -R #{MOUNTPOINT}")
|
89
|
-
puts
|
90
|
-
puts "getch has finish, before reboot, you can:"
|
91
|
-
puts " + Chroot on your system with: chroot #{MOUNTPOINT} /bin/bash"
|
92
|
-
puts " + Install more packages like networkmanager or emacs"
|
93
|
-
puts
|
94
|
-
puts " + Add more modules for your kernel (graphic, wifi card) and recompile it with:"
|
95
|
-
puts " genkernel --kernel-config=/usr/src/linux/.config all "
|
96
|
-
puts
|
97
|
-
puts "Reboot the system when you have done !"
|
98
|
-
end
|
99
|
-
|
100
|
-
def exec_chroot(cmd)
|
101
|
-
script = "chroot #{MOUNTPOINT} /bin/bash -c \"
|
102
|
-
source /etc/profile
|
103
|
-
#{cmd}
|
104
|
-
\""
|
105
|
-
Getch::Command.new(script).run!
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
data/lib/getch/gentoo/chroot.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
module Getch
|
2
|
-
module Gentoo
|
3
|
-
class Chroot
|
4
|
-
def initialize
|
5
|
-
@state = Getch::States.new()
|
6
|
-
@pkgs = []
|
7
|
-
mount
|
8
|
-
end
|
9
|
-
|
10
|
-
def cpuflags
|
11
|
-
Getch::Emerge.new("app-portage/cpuid2cpuflags").pkg!
|
12
|
-
cpuflags = `chroot #{MOUNTPOINT} /bin/bash -c "source /etc/profile; cpuid2cpuflags"`.chomp
|
13
|
-
File.write("#{MOUNTPOINT}/etc/portage/package.use/00cpuflags", "*/* #{cpuflags}")
|
14
|
-
end
|
15
|
-
|
16
|
-
def update
|
17
|
-
return if STATES[:gentoo_update]
|
18
|
-
puts "Downloading the last ebuilds for Gentoo..."
|
19
|
-
Helpers::create_dir("#{MOUNTPOINT}/var/db/repos/gentoo")
|
20
|
-
cmd = "emaint sync --auto"
|
21
|
-
exec_chroot(cmd)
|
22
|
-
end
|
23
|
-
|
24
|
-
def world
|
25
|
-
return if STATES[:gentoo_update]
|
26
|
-
puts "Update Gentoo world"
|
27
|
-
Getch::Emerge.new("emerge --update --deep --changed-use --newuse @world").run!
|
28
|
-
@state.update
|
29
|
-
end
|
30
|
-
|
31
|
-
def systemd
|
32
|
-
puts "Updating locale, keymap..."
|
33
|
-
cmd = "locale-gen; emerge --config sys-libs/timezone-data"
|
34
|
-
exec_chroot(cmd)
|
35
|
-
end
|
36
|
-
|
37
|
-
def kernel
|
38
|
-
return if Dir.exist? "#{MOUNTPOINT}/usr/src/linux"
|
39
|
-
license = "#{MOUNTPOINT}/etc/portage/package.license"
|
40
|
-
File.write(license, "sys-kernel/linux-firmware linux-fw-redistributable no-source-code\n")
|
41
|
-
@pkgs << "sys-kernel/gentoo-sources"
|
42
|
-
@pkgs << "dev-util/dwarves"
|
43
|
-
end
|
44
|
-
|
45
|
-
def kernel_deps
|
46
|
-
@pkgs << "sys-apps/kmod"
|
47
|
-
end
|
48
|
-
|
49
|
-
def install_pkgs
|
50
|
-
@pkgs << "app-portage/gentoolkit"
|
51
|
-
@pkgs << "app-admin/sudo"
|
52
|
-
@pkgs << "app-editors/vim"
|
53
|
-
@pkgs << "sys-kernel/linux-firmware"
|
54
|
-
all_pkgs = @pkgs.join(" ")
|
55
|
-
puts "Installing #{all_pkgs}..."
|
56
|
-
Getch::Emerge.new(all_pkgs).pkg!
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
def mount
|
62
|
-
puts "Populate /proc, /sys and /dev."
|
63
|
-
Helpers::exec_or_die("mount --types proc /proc \"#{MOUNTPOINT}/proc\"")
|
64
|
-
Helpers::exec_or_die("mount --rbind /sys \"#{MOUNTPOINT}/sys\"")
|
65
|
-
Helpers::exec_or_die("mount --make-rslave \"#{MOUNTPOINT}/sys\"")
|
66
|
-
Helpers::exec_or_die("mount --rbind /dev \"#{MOUNTPOINT}/dev\"")
|
67
|
-
Helpers::exec_or_die("mount --make-rslave \"#{MOUNTPOINT}/dev\"")
|
68
|
-
# Maybe add /dev/shm like describe here:
|
69
|
-
# https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Base
|
70
|
-
end
|
71
|
-
|
72
|
-
def exec_chroot(cmd)
|
73
|
-
Getch::Chroot.new(cmd).run!
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
data/lib/getch/gentoo/config.rb
DELETED
@@ -1,129 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'tempfile'
|
3
|
-
require 'securerandom'
|
4
|
-
|
5
|
-
module Getch
|
6
|
-
module Gentoo
|
7
|
-
class Config
|
8
|
-
def initialize
|
9
|
-
@make = "#{MOUNTPOINT}/etc/portage/make.conf"
|
10
|
-
@log = Getch::Log.new
|
11
|
-
end
|
12
|
-
|
13
|
-
def portage
|
14
|
-
grub_pc = Helpers::efi? ? '' : 'GRUB_PLATFORMS="pc"'
|
15
|
-
nproc = `nproc`.chomp()
|
16
|
-
|
17
|
-
# Add cpu name
|
18
|
-
cpu=`chroot #{MOUNTPOINT} /bin/bash -c \"source /etc/profile ; gcc -c -Q -march=native --help=target | grep march\" | awk '{print $2}' | head -1`.chomp
|
19
|
-
raise "Error, no cpu found" if ! cpu or cpu == ""
|
20
|
-
@log.debug "CPU found ==> #{cpu}"
|
21
|
-
|
22
|
-
tmp = Tempfile.new('make.conf')
|
23
|
-
|
24
|
-
File.open(@make).each { |l|
|
25
|
-
if l.match(/^COMMON_FLAGS/)
|
26
|
-
File.write(tmp, "COMMON_FLAGS=\"-march=#{cpu} -O2 -pipe -fomit-frame-pointer\"\n", mode: 'a')
|
27
|
-
else
|
28
|
-
File.write(tmp, l, mode: 'a')
|
29
|
-
end
|
30
|
-
}
|
31
|
-
|
32
|
-
FileUtils.copy_file(tmp, @make, preserve = true)
|
33
|
-
|
34
|
-
# Add the rest
|
35
|
-
data = [
|
36
|
-
'',
|
37
|
-
"MAKEOPTS=\"-j#{nproc}\"",
|
38
|
-
'ACCEPT_KEYWORDS="amd64"',
|
39
|
-
'INPUT_DEVICES="libinput"',
|
40
|
-
grub_pc
|
41
|
-
]
|
42
|
-
File.write(@make, data.join("\n"), mode: "a")
|
43
|
-
end
|
44
|
-
|
45
|
-
# Write a repos.conf/gentoo.conf with the gpg verification
|
46
|
-
def repo
|
47
|
-
src = "#{MOUNTPOINT}/usr/share/portage/config/repos.conf"
|
48
|
-
dest = "#{MOUNTPOINT}/etc/portage/repos.conf"
|
49
|
-
FileUtils.mkdir dest, mode: 0644 if ! Dir.exist?(dest)
|
50
|
-
tmp = Tempfile.new('gentoo.conf')
|
51
|
-
line_count = 0
|
52
|
-
|
53
|
-
File.open(src).each { |l|
|
54
|
-
File.write(tmp, "sync-allow-hardlinks = yes\n", mode: 'a') if line_count == 2
|
55
|
-
if l.match(/^sync-type = rsync/)
|
56
|
-
File.write(tmp, "sync-type = webrsync\n", mode: 'a')
|
57
|
-
else
|
58
|
-
File.write(tmp, l, mode: 'a')
|
59
|
-
end
|
60
|
-
line_count += 1
|
61
|
-
}
|
62
|
-
|
63
|
-
FileUtils.copy_file(tmp, "#{dest}/gentoo.conf", preserve = true)
|
64
|
-
end
|
65
|
-
|
66
|
-
def network
|
67
|
-
src = '/etc/resolv.conf'
|
68
|
-
dest = "#{MOUNTPOINT}/etc/resolv.conf"
|
69
|
-
FileUtils.copy_file(src, dest, preserve = true)
|
70
|
-
end
|
71
|
-
|
72
|
-
def systemd(options)
|
73
|
-
control_options(options)
|
74
|
-
File.write("#{MOUNTPOINT}/etc/locale.gen", @utf8)
|
75
|
-
File.write("#{MOUNTPOINT}/etc/locale.conf", "LANG=#{@lang}\n")
|
76
|
-
File.write("#{MOUNTPOINT}/etc/locale.conf", 'LC_COLLATE=C', mode: 'a')
|
77
|
-
File.write("#{MOUNTPOINT}/etc/timezone", "#{options.zoneinfo}")
|
78
|
-
File.write("#{MOUNTPOINT}/etc/vconsole.conf", "KEYMAP=#{options.keymap}")
|
79
|
-
end
|
80
|
-
|
81
|
-
def hostname
|
82
|
-
id = SecureRandom.hex(2)
|
83
|
-
File.write("#{MOUNTPOINT}/etc/hostname", "gentoo-hatch-#{id}")
|
84
|
-
end
|
85
|
-
|
86
|
-
def portage_fs
|
87
|
-
portage = "#{MOUNTPOINT}/etc/portage"
|
88
|
-
Helpers::create_dir("#{portage}/package.use")
|
89
|
-
Helpers::create_dir("#{portage}/package.accept_keywords")
|
90
|
-
Helpers::create_dir("#{portage}/package.unmask")
|
91
|
-
|
92
|
-
Helpers::add_file("#{portage}/package.use/zzz_via_autounmask")
|
93
|
-
Helpers::add_file("#{portage}/package.accept_keywords/zzz_via_autounmask")
|
94
|
-
Helpers::add_file("#{portage}/package.unmask/zzz_via_autounmask")
|
95
|
-
end
|
96
|
-
|
97
|
-
private
|
98
|
-
|
99
|
-
def control_options(options)
|
100
|
-
search_zone(options.zoneinfo)
|
101
|
-
search_utf8(options.language)
|
102
|
-
search_key(options.keymap)
|
103
|
-
end
|
104
|
-
|
105
|
-
def search_key(keys)
|
106
|
-
@keymap = nil
|
107
|
-
Dir.glob("#{MOUNTPOINT}/usr/share/keymaps/**/#{keys}.map.gz") { |f|
|
108
|
-
@keymap = f
|
109
|
-
}
|
110
|
-
raise ArgumentError, "No keymap #{@keymap} found" if ! @keymap
|
111
|
-
end
|
112
|
-
|
113
|
-
def search_zone(zone)
|
114
|
-
if !File.exist?("#{MOUNTPOINT}/usr/share/zoneinfo/#{zone}")
|
115
|
-
raise ArgumentError, "Zoneinfo #{zone} doesn\'t exist."
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def search_utf8(lang)
|
120
|
-
@utf8, @lang = nil, nil
|
121
|
-
File.open("#{MOUNTPOINT}/usr/share/i18n/SUPPORTED").each { |l|
|
122
|
-
@utf8 = $~[0] if l.match(/^#{lang}[. ]+[utf\-8 ]+/i)
|
123
|
-
@lang = $~[0] if l.match(/^#{lang}[. ]+utf\-8/i)
|
124
|
-
}
|
125
|
-
raise ArgumentError, "Lang #{lang} no found" if ! @utf8
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
data/lib/getch/gentoo/stage.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
require 'open3'
|
3
|
-
|
4
|
-
module Getch
|
5
|
-
module Gentoo
|
6
|
-
class Stage
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
@mirror = "https://mirrors.soeasyto.com/distfiles.gentoo.org"
|
10
|
-
@release = release
|
11
|
-
@stage_file="stage3-amd64-systemd-#{@release}.tar.xz"
|
12
|
-
end
|
13
|
-
|
14
|
-
def stage3
|
15
|
-
@mirror + '/releases/amd64/autobuilds/latest-stage3-amd64-systemd.txt'
|
16
|
-
end
|
17
|
-
|
18
|
-
def release
|
19
|
-
URI.open(stage3) do |file|
|
20
|
-
file.read.match(/^[[:alnum:]]+/)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def file
|
25
|
-
"#{@release}/#{@stage_file}"
|
26
|
-
end
|
27
|
-
|
28
|
-
def get_stage3
|
29
|
-
Dir.chdir(MOUNTPOINT)
|
30
|
-
return if File.exist?(@stage_file)
|
31
|
-
puts "Download the last #{@stage_file}, please wait..."
|
32
|
-
Helpers::get_file_online(@mirror + "/releases/amd64/autobuilds/" + file, @stage_file)
|
33
|
-
end
|
34
|
-
|
35
|
-
def control_files
|
36
|
-
puts "Download the DIGESTS"
|
37
|
-
Helpers::get_file_online(@mirror + "/releases/amd64/autobuilds/" + file + ".DIGESTS", "#{@stage_file}.DIGESTS")
|
38
|
-
puts "Download the DIGESTS.asc"
|
39
|
-
Helpers::get_file_online(@mirror + "/releases/amd64/autobuilds/" + file + ".DIGESTS.asc", "#{@stage_file}.DIGESTS.asc")
|
40
|
-
puts "Download the CONTENTS.gz"
|
41
|
-
Helpers::get_file_online(@mirror + "/releases/amd64/autobuilds/" + file + ".CONTENTS.gz", "#{@stage_file}.CONTENTS.gz")
|
42
|
-
end
|
43
|
-
|
44
|
-
def checksum
|
45
|
-
puts 'Check the SHA512 checksum.'
|
46
|
-
command = "awk '/SHA512 HASH/{getline;print}' #{@stage_file}.DIGESTS.asc | sha512sum --check"
|
47
|
-
_, stderr, status = Open3.capture3(command)
|
48
|
-
if status.success? then
|
49
|
-
puts "Checksum is ok"
|
50
|
-
decompress
|
51
|
-
cleaning
|
52
|
-
else
|
53
|
-
cleaning
|
54
|
-
raise "Problem with the checksum, stderr\n#{stderr}"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
# https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Stage
|
61
|
-
def decompress
|
62
|
-
puts "Decompressing archive #{@stage_file}..."
|
63
|
-
cmd = "tar xpf #{@stage_file} --xattrs-include=\'*.*\' --numeric-owner"
|
64
|
-
Getch::Command.new(cmd).run!
|
65
|
-
end
|
66
|
-
|
67
|
-
def cleaning
|
68
|
-
Dir.glob("stage3-amd64-systemd*").each do |f|
|
69
|
-
File.delete(f)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|