getch 0.1.0 → 0.1.6
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.tar.gz.sig +0 -0
- data/README.md +95 -22
- data/assets/network-stack.conf +63 -0
- data/bin/getch +12 -4
- data/lib/getch.rb +116 -66
- data/lib/getch/command.rb +19 -5
- data/lib/getch/config.rb +42 -0
- data/lib/getch/config/gentoo.rb +59 -0
- data/lib/getch/config/void.rb +49 -0
- data/lib/getch/filesystem.rb +5 -0
- data/lib/getch/filesystem/.mount.rb.swp +0 -0
- data/lib/getch/filesystem/clean.rb +58 -0
- data/lib/getch/filesystem/device.rb +61 -0
- data/lib/getch/filesystem/ext4.rb +1 -0
- data/lib/getch/filesystem/ext4/config.rb +8 -9
- data/lib/getch/filesystem/ext4/device.rb +2 -7
- data/lib/getch/filesystem/ext4/encrypt.rb +1 -0
- data/lib/getch/filesystem/ext4/encrypt/config.rb +8 -9
- data/lib/getch/filesystem/ext4/encrypt/deps.rb +3 -19
- data/lib/getch/filesystem/ext4/encrypt/device.rb +3 -8
- data/lib/getch/filesystem/ext4/encrypt/format.rb +3 -6
- data/lib/getch/filesystem/ext4/encrypt/mount.rb +5 -43
- data/lib/getch/filesystem/ext4/encrypt/partition.rb +29 -54
- data/lib/getch/filesystem/ext4/encrypt/void.rb +100 -0
- data/lib/getch/filesystem/ext4/format.rb +4 -6
- data/lib/getch/filesystem/ext4/mount.rb +7 -46
- data/lib/getch/filesystem/ext4/partition.rb +16 -39
- data/lib/getch/filesystem/ext4/void.rb +43 -0
- data/lib/getch/filesystem/lvm.rb +1 -0
- data/lib/getch/filesystem/lvm/config.rb +11 -15
- data/lib/getch/filesystem/lvm/deps.rb +4 -19
- data/lib/getch/filesystem/lvm/device.rb +33 -9
- data/lib/getch/filesystem/lvm/encrypt.rb +1 -0
- data/lib/getch/filesystem/lvm/encrypt/config.rb +9 -12
- data/lib/getch/filesystem/lvm/encrypt/deps.rb +4 -21
- data/lib/getch/filesystem/lvm/encrypt/device.rb +33 -9
- data/lib/getch/filesystem/lvm/encrypt/format.rb +3 -4
- data/lib/getch/filesystem/lvm/encrypt/mount.rb +7 -47
- data/lib/getch/filesystem/lvm/encrypt/partition.rb +30 -38
- data/lib/getch/filesystem/lvm/encrypt/void.rb +100 -0
- data/lib/getch/filesystem/lvm/format.rb +12 -8
- data/lib/getch/filesystem/lvm/mount.rb +7 -46
- data/lib/getch/filesystem/lvm/partition.rb +19 -31
- data/lib/getch/filesystem/lvm/void.rb +45 -0
- data/lib/getch/filesystem/mount.rb +56 -0
- data/lib/getch/filesystem/partition.rb +77 -0
- data/lib/getch/filesystem/zfs.rb +1 -0
- data/lib/getch/filesystem/zfs/config.rb +7 -8
- data/lib/getch/filesystem/zfs/deps.rb +24 -12
- data/lib/getch/filesystem/zfs/device.rb +54 -9
- data/lib/getch/filesystem/zfs/encrypt.rb +1 -0
- data/lib/getch/filesystem/zfs/encrypt/.mount.rb.swp +0 -0
- data/lib/getch/filesystem/zfs/encrypt/config.rb +11 -11
- data/lib/getch/filesystem/zfs/encrypt/deps.rb +24 -14
- data/lib/getch/filesystem/zfs/encrypt/device.rb +54 -9
- data/lib/getch/filesystem/zfs/encrypt/format.rb +84 -3
- data/lib/getch/filesystem/zfs/encrypt/mount.rb +8 -28
- data/lib/getch/filesystem/zfs/encrypt/partition.rb +26 -109
- data/lib/getch/filesystem/zfs/encrypt/void.rb +96 -0
- data/lib/getch/filesystem/zfs/format.rb +97 -4
- data/lib/getch/filesystem/zfs/mount.rb +10 -32
- data/lib/getch/filesystem/zfs/partition.rb +25 -106
- data/lib/getch/filesystem/zfs/void.rb +81 -0
- data/lib/getch/gentoo.rb +20 -16
- data/lib/getch/gentoo/boot.rb +24 -16
- data/lib/getch/gentoo/chroot.rb +16 -25
- data/lib/getch/gentoo/config.rb +67 -15
- data/lib/getch/gentoo/sources.rb +55 -13
- data/lib/getch/gentoo/stage.rb +0 -1
- data/lib/getch/gentoo/use.rb +43 -0
- data/lib/getch/gentoo/use_flag.rb +63 -0
- data/lib/getch/guard.rb +64 -0
- data/lib/getch/helpers.rb +133 -0
- data/lib/getch/log.rb +3 -2
- data/lib/getch/options.rb +46 -24
- data/lib/getch/version.rb +1 -1
- data/lib/getch/void.rb +59 -0
- data/lib/getch/void/boot.rb +80 -0
- data/lib/getch/void/chroot.rb +55 -0
- data/lib/getch/void/config.rb +87 -0
- data/lib/getch/void/stage.rb +70 -0
- metadata +46 -25
- metadata.gz.sig +0 -0
- data/.gitignore +0 -2
- data/CHANGELOG.md +0 -60
- data/Rakefile +0 -21
- data/bin/setup.sh +0 -90
- data/getch.gemspec +0 -25
|
@@ -3,23 +3,13 @@ module Getch
|
|
|
3
3
|
module Ext4
|
|
4
4
|
module Encrypt
|
|
5
5
|
class Deps
|
|
6
|
-
def initialize
|
|
7
|
-
if Helpers::efi?
|
|
8
|
-
install_efi
|
|
9
|
-
else
|
|
10
|
-
install_bios
|
|
11
|
-
end
|
|
12
|
-
install_deps
|
|
13
|
-
end
|
|
14
|
-
|
|
15
6
|
def make
|
|
7
|
+
install_deps
|
|
16
8
|
genkernel
|
|
17
9
|
Getch::Make.new("genkernel --kernel-config=/usr/src/linux/.config all").run!
|
|
18
10
|
end
|
|
19
11
|
|
|
20
12
|
private
|
|
21
|
-
def install_efi
|
|
22
|
-
end
|
|
23
13
|
|
|
24
14
|
def genkernel
|
|
25
15
|
grub = Helpers::efi? ? 'BOOTLOADER="no"' : 'BOOTLOADER="grub2"'
|
|
@@ -39,18 +29,12 @@ module Getch
|
|
|
39
29
|
File.write(file, datas.join("\n"), mode: 'a')
|
|
40
30
|
end
|
|
41
31
|
|
|
42
|
-
def install_bios
|
|
43
|
-
exec("euse -p sys-boot/grub -E device-mapper")
|
|
44
|
-
exec("euse -p sys-fs/cryptsetup -E luks1_default")
|
|
45
|
-
end
|
|
46
|
-
|
|
47
32
|
def install_deps
|
|
48
|
-
|
|
49
|
-
Getch::Emerge.new('genkernel sys-apps/systemd sys-fs/cryptsetup').pkg!
|
|
33
|
+
Getch::Emerge.new('genkernel').pkg!
|
|
50
34
|
end
|
|
51
35
|
|
|
52
36
|
def exec(cmd)
|
|
53
|
-
|
|
37
|
+
Getch::Chroot.new(cmd).run!
|
|
54
38
|
end
|
|
55
39
|
end
|
|
56
40
|
end
|
|
@@ -2,16 +2,11 @@ module Getch
|
|
|
2
2
|
module FileSystem
|
|
3
3
|
module Ext4
|
|
4
4
|
module Encrypt
|
|
5
|
-
class Device
|
|
5
|
+
class Device < Getch::FileSystem::Device
|
|
6
6
|
def initialize
|
|
7
|
-
|
|
8
|
-
@user = DEFAULT_OPTIONS[:username]
|
|
9
|
-
@dev_boot_efi = Helpers::efi? ? "/dev/#{@disk}1" : nil
|
|
10
|
-
@dev_root = "/dev/#{@disk}2"
|
|
11
|
-
@dev_swap = "/dev/#{@disk}3"
|
|
12
|
-
@dev_home = @user ? "/dev/#{@disk}4" : nil
|
|
7
|
+
super
|
|
13
8
|
@luks_root = "/dev/mapper/cryptroot"
|
|
14
|
-
@luks_home = @
|
|
9
|
+
@luks_home = @home_disk ? "/dev/mapper/crypthome" : nil
|
|
15
10
|
@luks_swap = "/dev/mapper/cryptswap"
|
|
16
11
|
end
|
|
17
12
|
end
|
|
@@ -5,18 +5,15 @@ module Getch
|
|
|
5
5
|
class Format < Getch::FileSystem::Ext4::Encrypt::Device
|
|
6
6
|
def initialize
|
|
7
7
|
super
|
|
8
|
-
@fs = 'ext4'
|
|
9
8
|
@state = Getch::States.new()
|
|
10
9
|
format
|
|
11
10
|
end
|
|
12
11
|
|
|
13
12
|
def format
|
|
14
13
|
return if STATES[:format]
|
|
15
|
-
|
|
16
|
-
exec("mkfs.
|
|
17
|
-
exec("mkfs
|
|
18
|
-
exec("mkswap -f #{@dev_swap}")
|
|
19
|
-
exec("mkfs.#{@fs} -F #{@luks_home}") if @dev_home
|
|
14
|
+
exec("mkfs.fat -F32 #{@dev_esp}") if @dev_esp
|
|
15
|
+
exec("mkfs.ext4 -F #{@luks_root}")
|
|
16
|
+
exec("mkfs.ext4 -F #{@luks_home}") if @dev_home
|
|
20
17
|
@state.format
|
|
21
18
|
end
|
|
22
19
|
|
|
@@ -7,54 +7,16 @@ module Getch
|
|
|
7
7
|
class Mount < Getch::FileSystem::Ext4::Encrypt::Device
|
|
8
8
|
def initialize
|
|
9
9
|
super
|
|
10
|
-
@
|
|
11
|
-
@boot_dir = "#{@root_dir}/boot"
|
|
12
|
-
@boot_efi_dir = "#{@root_dir}/boot/efi"
|
|
13
|
-
@home_dir = @user ? "#{@root_dir}/home/#{@user}" : nil
|
|
10
|
+
@mount = Getch::FileSystem::Mount.new
|
|
14
11
|
@state = Getch::States.new()
|
|
15
12
|
end
|
|
16
13
|
|
|
17
14
|
def run
|
|
18
15
|
return if STATES[:mount]
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
mount_boot_efi
|
|
24
|
-
@state.mount
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
private
|
|
28
|
-
|
|
29
|
-
def mount_swap
|
|
30
|
-
return if ! @dev_swap
|
|
31
|
-
system("swapon #{@dev_swap}")
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def mount_root
|
|
35
|
-
return if ! @dev_root
|
|
36
|
-
Dir.mkdir(@root_dir, 0700) if ! Dir.exist?(@root_dir)
|
|
37
|
-
system("mount #{@luks_root} #{@root_dir}")
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def mount_boot_efi
|
|
41
|
-
return if ! @dev_boot_efi
|
|
42
|
-
FileUtils.mkdir_p @boot_efi_dir, mode: 0700 if ! Dir.exist?(@boot_efi_dir)
|
|
43
|
-
system("mount #{@dev_boot_efi} #{@boot_efi_dir}")
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def mount_boot
|
|
47
|
-
return if ! @dev_boot
|
|
48
|
-
FileUtils.mkdir_p @boot_dir, mode: 0700 if ! Dir.exist?(@boot_dir)
|
|
49
|
-
system("mount #{@dev_boot} #{@boot_dir}")
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def mount_home
|
|
53
|
-
return if ! @dev_home
|
|
54
|
-
if @user != nil then
|
|
55
|
-
FileUtils.mkdir_p @home_dir, mode: 0700 if ! Dir.exist?(@home_dir)
|
|
56
|
-
system("mount #{@luks_home} #{@home_dir}")
|
|
57
|
-
end
|
|
16
|
+
@mount.root(@luks_root)
|
|
17
|
+
@mount.boot(@dev_boot)
|
|
18
|
+
@mount.esp(@dev_esp)
|
|
19
|
+
@mount.home(@luks_home)
|
|
58
20
|
@state.mount
|
|
59
21
|
end
|
|
60
22
|
end
|
|
@@ -1,75 +1,52 @@
|
|
|
1
|
+
require_relative '../../../helpers'
|
|
2
|
+
|
|
1
3
|
module Getch
|
|
2
4
|
module FileSystem
|
|
3
5
|
module Ext4
|
|
4
6
|
module Encrypt
|
|
5
|
-
class Partition <
|
|
7
|
+
class Partition < Device
|
|
8
|
+
include Helpers::Cryptsetup
|
|
9
|
+
|
|
6
10
|
def initialize
|
|
7
11
|
super
|
|
8
|
-
@state = Getch::States.new
|
|
12
|
+
@state = Getch::States.new
|
|
13
|
+
@partition = Getch::FileSystem::Partition.new
|
|
14
|
+
@clean = Getch::FileSystem::Clean
|
|
9
15
|
@log = Log.new
|
|
10
16
|
run_partition
|
|
11
17
|
end
|
|
12
18
|
|
|
13
19
|
def run_partition
|
|
14
20
|
return if STATES[:partition ]
|
|
15
|
-
|
|
16
|
-
|
|
21
|
+
@clean.hdd(@disk)
|
|
22
|
+
@clean.external_disk(@disk, @boot_disk, @cache_disk, @home_disk)
|
|
17
23
|
if Helpers::efi?
|
|
18
24
|
partition_efi
|
|
19
|
-
encrypt_efi
|
|
20
25
|
else
|
|
21
26
|
partition_bios
|
|
22
|
-
encrypt_bios
|
|
23
27
|
end
|
|
28
|
+
encrypting
|
|
24
29
|
@state.partition
|
|
25
30
|
end
|
|
26
31
|
|
|
27
32
|
private
|
|
28
33
|
|
|
29
|
-
def clear_struct
|
|
30
|
-
exec("sgdisk -Z /dev/#{@disk}")
|
|
31
|
-
exec("wipefs -a /dev/#{@disk}")
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def cleaning
|
|
35
|
-
puts
|
|
36
|
-
print "Cleaning data on #{@disk}, can be long, avoid this on Flash Memory (SSD,USB,...) ? (n,y) "
|
|
37
|
-
case gets.chomp
|
|
38
|
-
when /^y|^Y/
|
|
39
|
-
bloc=`blockdev --getbsz /dev/#{@disk}`.chomp
|
|
40
|
-
exec("dd if=/dev/urandom of=/dev/#{@disk} bs=#{bloc} status=progress")
|
|
41
|
-
else
|
|
42
|
-
return
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
34
|
# Follow https://wiki.archlinux.org/index.php/Partitioning
|
|
47
35
|
def partition_efi
|
|
48
|
-
# /
|
|
49
|
-
#
|
|
50
|
-
#
|
|
51
|
-
# /home
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
exec("sgdisk -n3:0:+#{mem} -t3:8200 /dev/#{@disk}")
|
|
57
|
-
exec("sgdisk -n4:0:0 -t4:8309 /dev/#{@disk}") if @dev_home
|
|
36
|
+
# /efi - EFI system partition - 260MB
|
|
37
|
+
# swap - Linux Swap - size of the ram
|
|
38
|
+
# / - Root
|
|
39
|
+
# /home - Home
|
|
40
|
+
@partition.efi(@dev_esp)
|
|
41
|
+
@partition.swap(@dev_swap)
|
|
42
|
+
@partition.root(@dev_root, "8309")
|
|
43
|
+
@partition.home(@dev_home, "8309") if @dev_home
|
|
58
44
|
end
|
|
59
45
|
|
|
60
|
-
def
|
|
61
|
-
@log.info("
|
|
62
|
-
|
|
63
|
-
@
|
|
64
|
-
Helpers::sys("cryptsetup open --type luks #{@dev_root} cryptroot")
|
|
65
|
-
encrypt_home
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def encrypt_bios
|
|
69
|
-
@log.info("Format root for bios")
|
|
70
|
-
Helpers::sys("cryptsetup luksFormat --type luks1 #{@dev_root}")
|
|
71
|
-
@log.debug("Opening root")
|
|
72
|
-
Helpers::sys("cryptsetup open --type luks1 #{@dev_root} cryptroot")
|
|
46
|
+
def encrypting
|
|
47
|
+
@log.info("Cryptsetup")
|
|
48
|
+
encrypt(@dev_root)
|
|
49
|
+
open_crypt(@dev_root, "cryptroot")
|
|
73
50
|
encrypt_home
|
|
74
51
|
end
|
|
75
52
|
|
|
@@ -90,20 +67,18 @@ module Getch
|
|
|
90
67
|
key_name = "crypto_keyfile.bin"
|
|
91
68
|
@key_path = "#{keys_dir}/#{key_name}"
|
|
92
69
|
FileUtils.mkdir keys_dir, mode: 0700 if ! Dir.exist?(keys_dir)
|
|
93
|
-
|
|
70
|
+
exec("dd bs=512 count=4 if=/dev/urandom of=#{@key_path}")
|
|
94
71
|
end
|
|
95
72
|
|
|
96
73
|
def partition_bios
|
|
97
74
|
# None - Bios Boot Partition - 1MiB
|
|
98
|
-
# / - Root
|
|
99
75
|
# swap - Linux Swap - size of the ram
|
|
76
|
+
# / - Root
|
|
100
77
|
# /home - Home
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
exec("sgdisk -n3:0:+#{mem} -t3:8200 /dev/#{@disk}")
|
|
106
|
-
exec("sgdisk -n4:0:0 -t4:8309 /dev/#{@disk}") if @dev_home
|
|
78
|
+
@partition.gpt(@dev_gpt)
|
|
79
|
+
@partition.swap(@dev_swap)
|
|
80
|
+
@partition.root(@dev_root, "8309")
|
|
81
|
+
@partition.home(@dev_home, "8309") if @dev_home
|
|
107
82
|
end
|
|
108
83
|
|
|
109
84
|
def exec(cmd)
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
require_relative '../../../helpers'
|
|
2
|
+
|
|
3
|
+
module Getch
|
|
4
|
+
module FileSystem
|
|
5
|
+
module Ext4
|
|
6
|
+
module Encrypt
|
|
7
|
+
class Void < Device
|
|
8
|
+
include Helpers::Void
|
|
9
|
+
attr_reader :boot_disk
|
|
10
|
+
|
|
11
|
+
# Create key to avoid enter password twice
|
|
12
|
+
def create_key
|
|
13
|
+
add_key("volume.key", @dev_root)
|
|
14
|
+
add_key("home.key", @dev_home) if @home_disk
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Key need to be added in dracut.conf.d and crypttab
|
|
18
|
+
def add_key(name, dev)
|
|
19
|
+
command "dd bs=1 count=64 if=/dev/urandom of=/boot/#{name}"
|
|
20
|
+
puts " => Creating a key for #{dev}, password required:"
|
|
21
|
+
chroot "cryptsetup luksAddKey #{dev} /boot/#{name}"
|
|
22
|
+
command "chmod 000 /boot/#{name}"
|
|
23
|
+
#command "chmod -R g-rwx,o-rwx /boot"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def fstab
|
|
27
|
+
conf = "#{MOUNTPOINT}/etc/fstab"
|
|
28
|
+
File.write(conf, "\n", mode: 'w', chmod: 0644)
|
|
29
|
+
line_fstab(@dev_esp, "/efi vfat noauto,rw,relatime 0 0") if @dev_esp
|
|
30
|
+
line_fstab(@dev_boot, "/boot ext4 noauto,rw,relatime 0 0") if @dev_boot
|
|
31
|
+
add_line(conf, "#{@luks_swap} none swap sw 0 0") if @dev_swap
|
|
32
|
+
add_line(conf, "#{@luks_home} /home ext4 rw,discard 0 0") if @home_disk
|
|
33
|
+
add_line(conf, "#{@luks_root} / ext4 rw,relatime 0 1")
|
|
34
|
+
add_line(conf, "tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def crypttab
|
|
38
|
+
conf = "#{MOUNTPOINT}/etc/crypttab"
|
|
39
|
+
File.write(conf, "\n", mode: 'w', chmod: 0644)
|
|
40
|
+
line_crypttab("cryptswap", @dev_swap, "/dev/urandom", "swap,discard,cipher=aes-xts-plain64:sha256,size=512") if @dev_swap
|
|
41
|
+
line_crypttab("cryptroot", @dev_root, "/boot/volume.key", "luks")
|
|
42
|
+
line_crypttab("crypthome", @dev_home, "/boot/home.key", "luks") if @home_disk
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def config_grub
|
|
46
|
+
conf = "#{MOUNTPOINT}/etc/default/grub"
|
|
47
|
+
content = "GRUB_ENABLE_CRYPTODISK=y"
|
|
48
|
+
unless search(conf, content)
|
|
49
|
+
File.write(conf, "#{content}\n", mode: 'a')
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def config_dracut
|
|
54
|
+
conf = "#{MOUNTPOINT}/etc/dracut.conf.d/ext4.conf"
|
|
55
|
+
content = [
|
|
56
|
+
"hostonly=\"yes\"",
|
|
57
|
+
"omit_dracutmodules+=\" btrfs lvm \"",
|
|
58
|
+
"install_items+=\" /boot/volume.key /etc/crypttab \"",
|
|
59
|
+
""
|
|
60
|
+
]
|
|
61
|
+
File.write(conf, content.join("\n"), mode: 'w', chmod: 0644)
|
|
62
|
+
#add_line(conf, "install_items+=\" /boot/home.key \"") if @home_disk
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def kernel_cmdline_dracut
|
|
66
|
+
conf = "#{MOUNTPOINT}/etc/dracut.conf.d/cmdline.conf"
|
|
67
|
+
root_uuid = b_uuid(@dev_root)
|
|
68
|
+
args = "rd.luks.uuid=#{root_uuid} rootfstype=ext4 rootflags=rw,relatime"
|
|
69
|
+
line = "kernel_cmdline=\"#{args}\""
|
|
70
|
+
File.write(conf, "#{line}\n", mode: 'w', chmod: 0644)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def finish
|
|
74
|
+
puts "+ Enter in your system: chroot /mnt /bin/bash"
|
|
75
|
+
puts "+ Reboot with: shutdown -r now"
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
private
|
|
79
|
+
|
|
80
|
+
def b_uuid(dev)
|
|
81
|
+
device = dev.delete_prefix("/dev/")
|
|
82
|
+
Dir.glob("/dev/disk/by-uuid/*").each { |f|
|
|
83
|
+
link = File.readlink(f)
|
|
84
|
+
return f.delete_prefix("/dev/disk/by-uuid/") if link.match(/#{device}$/)
|
|
85
|
+
}
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# line_crypttab("cryptswap", "sda2", "/dev/urandom", "luks")
|
|
89
|
+
def line_crypttab(mapname, dev, point, rest)
|
|
90
|
+
conf = "#{MOUNTPOINT}/etc/crypttab"
|
|
91
|
+
device = s_uuid(dev)
|
|
92
|
+
raise "No partuuid for #{dev} #{device}" if !device
|
|
93
|
+
raise "Bad partuuid for #{dev} #{device}" if device.kind_of? Array
|
|
94
|
+
add_line(conf, "#{mapname} PARTUUID=#{device} #{point} #{rest}")
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -4,18 +4,16 @@ module Getch
|
|
|
4
4
|
class Format < Getch::FileSystem::Ext4::Device
|
|
5
5
|
def initialize
|
|
6
6
|
super
|
|
7
|
-
@
|
|
8
|
-
@state = Getch::States.new()
|
|
7
|
+
@state = Getch::States.new
|
|
9
8
|
format
|
|
10
9
|
end
|
|
11
10
|
|
|
12
11
|
def format
|
|
13
12
|
return if STATES[:format]
|
|
14
|
-
|
|
15
|
-
exec("mkfs.fat -F32 #{@dev_boot_efi}") if Helpers::efi?
|
|
13
|
+
exec("mkfs.fat -F32 #{@dev_esp}") if @dev_esp
|
|
16
14
|
exec("mkswap -f #{@dev_swap}")
|
|
17
|
-
exec("mkfs
|
|
18
|
-
exec("mkfs
|
|
15
|
+
exec("mkfs.ext4 -F #{@dev_root}")
|
|
16
|
+
exec("mkfs.ext4 -F #{@dev_home}") if @dev_home
|
|
19
17
|
@state.format
|
|
20
18
|
end
|
|
21
19
|
|
|
@@ -1,59 +1,20 @@
|
|
|
1
|
-
require 'fileutils'
|
|
2
|
-
|
|
3
1
|
module Getch
|
|
4
2
|
module FileSystem
|
|
5
3
|
module Ext4
|
|
6
4
|
class Mount < Getch::FileSystem::Ext4::Device
|
|
7
5
|
def initialize
|
|
8
6
|
super
|
|
9
|
-
@
|
|
10
|
-
@
|
|
11
|
-
@boot_efi_dir = "#{@root_dir}/boot/efi"
|
|
12
|
-
@home_dir = @user ? "#{@root_dir}/home/#{@user}" : nil
|
|
13
|
-
@state = Getch::States.new()
|
|
7
|
+
@mount = Getch::FileSystem::Mount.new
|
|
8
|
+
@state = Getch::States.new
|
|
14
9
|
end
|
|
15
10
|
|
|
16
11
|
def run
|
|
17
12
|
return if STATES[:mount]
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
@state.mount
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
private
|
|
27
|
-
|
|
28
|
-
def mount_swap
|
|
29
|
-
return if ! @dev_swap
|
|
30
|
-
system("swapon #{@dev_swap}")
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def mount_root
|
|
34
|
-
return if ! @dev_root
|
|
35
|
-
Dir.mkdir(@root_dir, 0700) if ! Dir.exist?(@root_dir)
|
|
36
|
-
system("mount #{@dev_root} #{@root_dir}")
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def mount_boot_efi
|
|
40
|
-
return if ! @dev_boot_efi
|
|
41
|
-
FileUtils.mkdir_p @boot_efi_dir, mode: 0700 if ! Dir.exist?(@boot_efi_dir)
|
|
42
|
-
system("mount #{@dev_boot_efi} #{@boot_efi_dir}")
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def mount_boot
|
|
46
|
-
return if ! @dev_boot
|
|
47
|
-
FileUtils.mkdir_p @boot_dir, mode: 0700 if ! Dir.exist?(@boot_dir)
|
|
48
|
-
system("mount #{@dev_boot} #{@boot_dir}")
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def mount_home
|
|
52
|
-
return if ! @dev_home
|
|
53
|
-
if @user != nil then
|
|
54
|
-
FileUtils.mkdir_p @home_dir, mode: 0700 if ! Dir.exist?(@home_dir)
|
|
55
|
-
system("mount #{@dev_home} #{@home_dir}")
|
|
56
|
-
end
|
|
13
|
+
@mount.swap(@dev_swap)
|
|
14
|
+
@mount.root(@dev_root)
|
|
15
|
+
@mount.boot(@dev_boot)
|
|
16
|
+
@mount.esp(@dev_esp)
|
|
17
|
+
@mount.home(@dev_home)
|
|
57
18
|
@state.mount
|
|
58
19
|
end
|
|
59
20
|
end
|