getch 0.0.6 → 0.0.7
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.tar.gz.sig +0 -0
- data/CHANGELOG.md +7 -2
- data/bin/setup.sh +24 -10
- data/lib/getch.rb +7 -8
- data/lib/getch/filesystem.rb +0 -1
- data/lib/getch/filesystem/ext4.rb +8 -70
- data/lib/getch/filesystem/ext4/config.rb +58 -0
- data/lib/getch/filesystem/ext4/deps.rb +22 -0
- data/lib/getch/filesystem/ext4/device.rb +16 -0
- data/lib/getch/filesystem/ext4/encrypt.rb +15 -0
- data/lib/getch/filesystem/ext4/encrypt/config.rb +62 -0
- data/lib/getch/filesystem/ext4/encrypt/deps.rb +37 -0
- data/lib/getch/filesystem/ext4/encrypt/device.rb +20 -0
- data/lib/getch/filesystem/ext4/encrypt/format.rb +26 -0
- data/lib/getch/filesystem/ext4/encrypt/mount.rb +64 -0
- data/lib/getch/filesystem/ext4/encrypt/partition.rb +95 -0
- data/lib/getch/filesystem/ext4/format.rb +24 -0
- data/lib/getch/filesystem/ext4/mount.rb +62 -0
- data/lib/getch/filesystem/ext4/partition.rb +75 -0
- data/lib/getch/gentoo.rb +1 -1
- data/lib/getch/gentoo/boot.rb +5 -17
- data/lib/getch/gentoo/chroot.rb +9 -6
- data/lib/getch/gentoo/config.rb +2 -2
- data/lib/getch/gentoo/sources.rb +4 -3
- data/lib/getch/helpers.rb +8 -0
- data/lib/getch/options.rb +6 -2
- data/lib/getch/version.rb +1 -1
- metadata +16 -5
- metadata.gz.sig +2 -2
- data/lib/getch/filesystem/root.rb +0 -63
- data/lib/getch/mount.rb +0 -88
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb6075f7c63fb0a9b3d9cae63e24aae84cb3c90947985aa54ba48bc0dd284dcc
|
4
|
+
data.tar.gz: 26ad192fed5685f42e62d400706d6127c3d28a0fc5ce67296da6ef758955de25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe321ca0175f95f07c68026269830932609ba2fe5a1757efb7228bc26a069c4f5c322b21c534d05077c98a4dddfb0ed33bb2aa2fb30b1bc2df234e25b47acb56
|
7
|
+
data.tar.gz: 5b3540c9a1f07162bfbb3e4772f78c0b74b9525ec74fed7ce71c507da5f58befc85e6f8198abc595b49fa767abc77349f56b0ab9790d56730c45771365268fb0
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
+
* Repair GRUB/fstab for BIOS system, add config and all
|
2
|
+
* New option --encrypt (LVM/EXT4/LUKS for now)
|
3
|
+
* Adding LVM
|
4
|
+
* Create a swap volume equal to the memory installed
|
5
|
+
|
1
6
|
## 0.0.6, release 2020-09-19
|
2
|
-
* Add support for QEMU guest
|
7
|
+
* Add support for QEMU guest with KVM and Virtio driver
|
3
8
|
* Kernel compilation, initialize a config file with `make localyesconfig`.
|
4
9
|
* More modular codes to start with encryption and other filesystems.
|
5
|
-
* Add the new option --verbose to display output of compilation, etc...
|
10
|
+
* Add the new option --verbose to display output of compilation, etc...
|
6
11
|
|
7
12
|
## 0.0.5, release 2020-09-17
|
8
13
|
* Generate a hostname
|
data/bin/setup.sh
CHANGED
@@ -37,19 +37,33 @@ search_ruby() {
|
|
37
37
|
fi
|
38
38
|
}
|
39
39
|
|
40
|
+
install_with_gem() {
|
41
|
+
gem install getch
|
42
|
+
getch -h
|
43
|
+
}
|
44
|
+
|
45
|
+
dll_test_version() {
|
46
|
+
echo "Downloading the test version..."
|
47
|
+
cd /tmp
|
48
|
+
[ -f ./getch.tar.gz ] && rm ./getch.tar.gz
|
49
|
+
[ -d ./getch-master ] && rm -rf ./getch-master
|
50
|
+
|
51
|
+
curl -s -L -o getch.tar.gz https://github.com/szorfein/getch/archive/master.tar.gz
|
52
|
+
tar xzf getch.tar.gz \
|
53
|
+
&& cd $DIR \
|
54
|
+
&& ruby -I lib bin/getch -h
|
55
|
+
}
|
56
|
+
|
40
57
|
get_getch() {
|
41
58
|
if hash gem 2>/dev/null ; then
|
42
|
-
|
43
|
-
|
59
|
+
printf "Which version? [1] stable , [2] test (no recommended) " ; read -r
|
60
|
+
if echo "$REPLY" | grep -qP "2" ; then
|
61
|
+
dll_test_version
|
62
|
+
else
|
63
|
+
install_with_gem
|
64
|
+
fi
|
44
65
|
else
|
45
|
-
|
46
|
-
[ -f ./getch.tar.gz ] && rm ./getch.tar.gz
|
47
|
-
[ -d ./getch-master ] && rm -rf ./getch-master
|
48
|
-
|
49
|
-
curl -s -L -o getch.tar.gz https://github.com/szorfein/getch/archive/master.tar.gz
|
50
|
-
tar xzf getch.tar.gz \
|
51
|
-
&& cd $DIR \
|
52
|
-
&& ruby -I lib bin/getch -h
|
66
|
+
dll_test_version
|
53
67
|
fi
|
54
68
|
}
|
55
69
|
|
data/lib/getch.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require_relative 'getch/options'
|
2
2
|
require_relative 'getch/states'
|
3
|
-
require_relative 'getch/mount'
|
4
3
|
require_relative 'getch/gentoo'
|
5
4
|
require_relative 'getch/filesystem'
|
6
5
|
require_relative 'getch/command'
|
@@ -15,6 +14,7 @@ module Getch
|
|
15
14
|
disk: 'sda',
|
16
15
|
fs: 'ext4',
|
17
16
|
username: nil,
|
17
|
+
encrypt: false,
|
18
18
|
verbose: false
|
19
19
|
}
|
20
20
|
|
@@ -30,7 +30,7 @@ module Getch
|
|
30
30
|
|
31
31
|
MOUNTPOINT = "/mnt/gentoo".freeze
|
32
32
|
OPTIONS_FS = {
|
33
|
-
'ext4' => Getch::FileSystem::Ext4
|
33
|
+
'ext4' => DEFAULT_OPTIONS[:encrypt] ? Getch::FileSystem::Ext4::Encrypt : Getch::FileSystem::Ext4
|
34
34
|
}.freeze
|
35
35
|
|
36
36
|
def self.resume_options(opts)
|
@@ -41,6 +41,7 @@ module Getch
|
|
41
41
|
puts "disk: #{DEFAULT_OPTIONS[:disk]}"
|
42
42
|
puts "fs: #{DEFAULT_OPTIONS[:fs]}"
|
43
43
|
puts "username: #{DEFAULT_OPTIONS[:username]}"
|
44
|
+
puts "encrypt: #{DEFAULT_OPTIONS[:encrypt]}"
|
44
45
|
puts
|
45
46
|
print "Continue? (n,y) "
|
46
47
|
case gets.chomp
|
@@ -57,11 +58,8 @@ module Getch
|
|
57
58
|
print "Partition and format disk #{disk}, this will erase all data, continue? (n,y) "
|
58
59
|
case gets.chomp
|
59
60
|
when /^y|^Y/
|
60
|
-
|
61
|
-
|
62
|
-
filesystem.partition
|
63
|
-
filesystem.format
|
64
|
-
OPTIONS_FS[fs]::Mount.new(disk, user).run
|
61
|
+
OPTIONS_FS[fs]::Partition.new
|
62
|
+
OPTIONS_FS[fs]::Format.new
|
65
63
|
else
|
66
64
|
exit 1
|
67
65
|
end
|
@@ -80,8 +78,9 @@ module Getch
|
|
80
78
|
options = Options.new(argv)
|
81
79
|
DEFAULT_OPTIONS.freeze
|
82
80
|
resume_options(options)
|
83
|
-
Getch::States.new
|
81
|
+
Getch::States.new # Update States
|
84
82
|
format(options.disk, options.fs, options.username)
|
83
|
+
OPTIONS_FS[DEFAULT_OPTIONS[:fs]]::Mount.new.run
|
85
84
|
init_gentoo(options)
|
86
85
|
end
|
87
86
|
end
|
data/lib/getch/filesystem.rb
CHANGED
@@ -1,75 +1,13 @@
|
|
1
1
|
module Getch
|
2
2
|
module FileSystem
|
3
|
-
|
4
|
-
def initialize(disk)
|
5
|
-
@disk = disk
|
6
|
-
@fs = 'ext4'
|
7
|
-
super
|
8
|
-
end
|
9
|
-
|
10
|
-
class Mount < Getch::Mount
|
11
|
-
def initialize(disk, user)
|
12
|
-
@disk = disk
|
13
|
-
@user = user
|
14
|
-
super
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def gen_vars
|
20
|
-
@dev_boot_efi = Helpers::efi? ? "/dev/#{@disk}1" : nil
|
21
|
-
@dev_swap = "/dev/#{@disk}2"
|
22
|
-
@dev_root = "/dev/#{@disk}3"
|
23
|
-
@dev_home = @user ? "/dev/#{@disk}4" : nil
|
24
|
-
end
|
25
|
-
|
26
|
-
def data_fstab
|
27
|
-
boot_efi = @dev_boot_efi ? "UUID=#{@uuid_boot_efi} /boot/efi vfat noauto,defaults 0 2" : ''
|
28
|
-
swap = @dev_swap ? "UUID=#{@uuid_swap} none swap discard 0 0" : ''
|
29
|
-
root = @dev_root ? "UUID=#{@uuid_root} / ext4 defaults 0 1" : ''
|
30
|
-
home = @dev_home ? "UUID=#{@uuid_home} /home/#{@user} ext4 defaults 0 2" : ''
|
31
|
-
|
32
|
-
return [ boot_efi, swap, root, home ]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
# Follow https://wiki.archlinux.org/index.php/Partitioning
|
39
|
-
def partition_efi
|
40
|
-
# /boot/efi - EFI system partition - 260MB
|
41
|
-
# swap - Linux Swap - size of the ram
|
42
|
-
# / - Root
|
43
|
-
# /home - Home
|
44
|
-
system("sgdisk -n1:1M:+260M -t1:EF00 /dev/#{@disk}") # boot EFI
|
45
|
-
system("sgdisk -n2:0:+2G -t2:8200 /dev/#{@disk}") # swap
|
46
|
-
system("sgdisk -n3:0:+15G -t3:8304 /dev/#{@disk}") # root
|
47
|
-
system("sgdisk -n4:0:0 -t3:8302 /dev/#{@disk}") # home
|
48
|
-
end
|
49
|
-
|
50
|
-
def format_efi
|
51
|
-
system("mkfs.fat -F32 /dev/#{@disk}1")
|
52
|
-
system("mkswap /dev/#{@disk}2")
|
53
|
-
system("mkfs.#{@fs} /dev/#{@disk}3")
|
54
|
-
system("mkfs.#{@fs} /dev/#{@disk}4")
|
55
|
-
end
|
56
|
-
|
57
|
-
def partition_bios
|
58
|
-
# None - Bios Boot Partition - 1MiB
|
59
|
-
# swap - Linux Swap - size of the ram
|
60
|
-
# / - Root
|
61
|
-
# /home - Home
|
62
|
-
system("sgdisk -n1:1MiB:+1MiB -t1:EF02 /dev/#{@disk}")
|
63
|
-
system("sgdisk -n2:0:+2G -t2:8200 /dev/#{@disk}")
|
64
|
-
system("sgdisk -n3:0:+15G -t3:8304 /dev/#{@disk}")
|
65
|
-
system("sgdisk -n4:0:0 -t3:8302 /dev/#{@disk}")
|
66
|
-
end
|
67
|
-
|
68
|
-
def format_bios
|
69
|
-
system("mkswap /dev/#{@disk}2")
|
70
|
-
system("mkfs.#{@fs} /dev/#{@disk}3")
|
71
|
-
system("mkfs.#{@fs} /dev/#{@disk}4")
|
72
|
-
end
|
3
|
+
module Ext4
|
73
4
|
end
|
74
5
|
end
|
75
6
|
end
|
7
|
+
|
8
|
+
require_relative 'ext4/device'
|
9
|
+
require_relative 'ext4/partition'
|
10
|
+
require_relative 'ext4/format'
|
11
|
+
require_relative 'ext4/mount'
|
12
|
+
require_relative 'ext4/config'
|
13
|
+
require_relative 'ext4/deps'
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Ext4
|
4
|
+
class Config < Getch::FileSystem::Ext4::Device
|
5
|
+
def initialize
|
6
|
+
super
|
7
|
+
gen_uuid
|
8
|
+
@root_dir = MOUNTPOINT
|
9
|
+
@init = '/usr/lib/systemd/systemd'
|
10
|
+
end
|
11
|
+
|
12
|
+
def fstab
|
13
|
+
file = "#{@root_dir}/etc/fstab"
|
14
|
+
datas = data_fstab
|
15
|
+
File.write(file, datas.join("\n"))
|
16
|
+
end
|
17
|
+
|
18
|
+
def systemd_boot
|
19
|
+
return if ! Helpers::efi?
|
20
|
+
esp = '/boot/efi'
|
21
|
+
dir = "#{@root_dir}/#{esp}/loader/entries/"
|
22
|
+
datas_gentoo = [
|
23
|
+
'title Gentoo Linux',
|
24
|
+
'linux /vmlinuz',
|
25
|
+
"options root=UUID=#{uuid_root} init=#{@init} rw"
|
26
|
+
]
|
27
|
+
File.write("#{dir}/gentoo.conf", datas_gentoo.join("\n"))
|
28
|
+
end
|
29
|
+
|
30
|
+
def grub
|
31
|
+
return if Helpers::efi?
|
32
|
+
file = "#{@root_dir}/etc/default/grub"
|
33
|
+
cmdline = "GRUB_CMDLINE_LINUX=\"resume=#{@dev_swap} 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\"\n"
|
34
|
+
File.write(file, cmdline, mode: 'a')
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def gen_uuid
|
40
|
+
@uuid_swap = `lsblk -o "UUID" #{@dev_swap} | tail -1`.chomp() if @dev_swap
|
41
|
+
@uuid_root = `lsblk -o "UUID" #{@dev_root} | tail -1`.chomp() if @dev_root
|
42
|
+
@uuid_boot = `lsblk -o "UUID" #{@dev_boot} | tail -1`.chomp() if @dev_boot
|
43
|
+
@uuid_boot_efi = `lsblk -o "UUID" #{@dev_boot_efi} | tail -1`.chomp() if @dev_boot_efi
|
44
|
+
@uuid_home = `lsblk -o "UUID" #{@dev_home} | tail -1`.chomp() if @dev_home
|
45
|
+
end
|
46
|
+
|
47
|
+
def data_fstab
|
48
|
+
boot_efi = @dev_boot_efi ? "UUID=#{@uuid_boot_efi} /boot/efi vfat noauto,noatime 1 2" : ''
|
49
|
+
swap = @dev_swap ? "UUID=#{@uuid_swap} none swap discard 0 0" : ''
|
50
|
+
root = @dev_root ? "UUID=#{@uuid_root} / ext4 defaults 0 1" : ''
|
51
|
+
home = @dev_home ? "UUID=#{@uuid_home} /home/#{@user} ext4 defaults 0 2" : ''
|
52
|
+
|
53
|
+
[ boot_efi, swap, root, home ]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Ext4
|
4
|
+
class Deps
|
5
|
+
def initialize
|
6
|
+
if Helpers::efi?
|
7
|
+
install_efi
|
8
|
+
else
|
9
|
+
install_bios
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def install_efi
|
15
|
+
end
|
16
|
+
|
17
|
+
def install_bios
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Ext4
|
4
|
+
class Device
|
5
|
+
def initialize
|
6
|
+
@disk = DEFAULT_OPTIONS[:disk]
|
7
|
+
@user = DEFAULT_OPTIONS[:username]
|
8
|
+
@dev_boot_efi = Helpers::efi? ? "/dev/#{@disk}1" : nil
|
9
|
+
@dev_root = "/dev/#{@disk}2"
|
10
|
+
@dev_swap = "/dev/#{@disk}3"
|
11
|
+
@dev_home = @user ? "/dev/#{@disk}4" : nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Ext4
|
4
|
+
module Encrypt
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
require_relative 'encrypt/device'
|
11
|
+
require_relative 'encrypt/partition'
|
12
|
+
require_relative 'encrypt/format'
|
13
|
+
require_relative 'encrypt/mount'
|
14
|
+
require_relative 'encrypt/config'
|
15
|
+
require_relative 'encrypt/deps'
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Ext4
|
4
|
+
class Config < Getch::FileSystem::Ext4::Encrypt::Device
|
5
|
+
def initialize
|
6
|
+
super
|
7
|
+
gen_uuid
|
8
|
+
@root_dir = MOUNTPOINT
|
9
|
+
@init = '/usr/lib/systemd/systemd'
|
10
|
+
end
|
11
|
+
|
12
|
+
def fstab
|
13
|
+
file = "#{@root_dir}/etc/fstab"
|
14
|
+
datas = data_fstab
|
15
|
+
File.write(file, datas.join("\n"))
|
16
|
+
end
|
17
|
+
|
18
|
+
def systemd_boot
|
19
|
+
return if ! Helpers::efi?
|
20
|
+
esp = '/boot/efi'
|
21
|
+
dir = "#{@root_dir}/#{esp}/loader/entries/"
|
22
|
+
datas_gentoo = [
|
23
|
+
'title Gentoo Linux',
|
24
|
+
'linux /vmlinuz',
|
25
|
+
"options crypt_root=UUID=#{uuid_dev_root} root=/dev/mapper/#{@vg}-root init=#{@init} dolvm rw"
|
26
|
+
]
|
27
|
+
File.write("#{dir}/gentoo.conf", datas_gentoo.join("\n"))
|
28
|
+
end
|
29
|
+
|
30
|
+
def grub
|
31
|
+
return if Helpers::efi?
|
32
|
+
file = "#{@root_dir}/etc/default/grub"
|
33
|
+
cmdline = [
|
34
|
+
"GRUB_CMDLINE_LINUX=\"resume=UUID=#{@uuid_swap} crypt_root=UUID=#{@uuid_dev_root} root=/dev/mapper/#{@vg}-root init=#{@init} dolvm rw\"",
|
35
|
+
"GRUB_ENABLE_CRYPTODISK=y"
|
36
|
+
]
|
37
|
+
File.write("#{file}", cmdline.join("\n"), mode: 'a')
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def gen_uuid
|
43
|
+
@uuid_swap = `lsblk -o "UUID" #{@lv_swap} | tail -1`.chomp() if @lv_swap
|
44
|
+
@uuid_root = `lsblk -o "UUID" #{@lv_root} | tail -1`.chomp() if @lv_root
|
45
|
+
@uuid_dev_root = `lsblk -o "UUID" #{@dev_root} | tail -1`.chomp() if @dev_root
|
46
|
+
@uuid_boot = `lsblk -o "UUID" #{@dev_boot} | tail -1`.chomp() if @dev_boot
|
47
|
+
@uuid_boot_efi = `lsblk -o "UUID" #{@dev_boot_efi} | tail -1`.chomp() if @dev_boot_efi
|
48
|
+
@uuid_home = `lsblk -o "UUID" #{@lv_home} | tail -1`.chomp() if @lv_home
|
49
|
+
end
|
50
|
+
|
51
|
+
def data_fstab
|
52
|
+
boot_efi = @lv_boot_efi ? "UUID=#{@uuid_boot_efi} /boot/efi vfat noauto,noatime 1 2" : ''
|
53
|
+
swap = @lv_swap ? "UUID=#{@uuid_swap} none swap discard 0 0" : ''
|
54
|
+
root = @lv_root ? "UUID=#{@uuid_root} / ext4 defaults 0 1" : ''
|
55
|
+
home = @lv_home ? "UUID=#{@uuid_home} /home/#{@user} ext4 defaults 0 2" : ''
|
56
|
+
|
57
|
+
[ boot_efi, swap, root, home ]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Ext4
|
4
|
+
module Encrypt
|
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
|
+
private
|
16
|
+
def install_efi
|
17
|
+
end
|
18
|
+
|
19
|
+
def install_bios
|
20
|
+
exec("euse -p sys-boot/grub -E device-mapper")
|
21
|
+
end
|
22
|
+
|
23
|
+
def install_deps
|
24
|
+
exec("euse -p sys-apps/systemd -E cryptsetup")
|
25
|
+
Helpers::emerge('genkernel cryptsetup lvm2')
|
26
|
+
exec("genkernel --install --luks --keymap #{DEFAULT_OPTIONS[:keyboard]} --lvm --kernel-config=/usr/src/linux/.config initramfs")
|
27
|
+
exec("systemctl enable lvm2-monitor")
|
28
|
+
end
|
29
|
+
|
30
|
+
def exec(cmd)
|
31
|
+
Helpers::run_chroot(cmd, MOUNTPOINT)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Ext4
|
4
|
+
module Encrypt
|
5
|
+
class Device
|
6
|
+
def initialize
|
7
|
+
@disk = DEFAULT_OPTIONS[:disk]
|
8
|
+
@user = DEFAULT_OPTIONS[:username]
|
9
|
+
@dev_boot_efi = Helpers::efi? ? "/dev/#{@disk}1" : nil
|
10
|
+
@dev_root = "/dev/#{@disk}2"
|
11
|
+
@vg = 'vg0'
|
12
|
+
@lv_root = "/dev/mapper/#{@vg}-root"
|
13
|
+
@lv_swap = "/dev/mapper/#{@vg}-swap"
|
14
|
+
@lv_home = @user ? "/dev/mapper/#{@vg}-home" : nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Ext4
|
4
|
+
module Encrypt
|
5
|
+
class Format < Getch::FileSystem::Ext4::Encrypt::Device
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
@fs = 'ext4'
|
9
|
+
@state = Getch::States.new()
|
10
|
+
format
|
11
|
+
end
|
12
|
+
|
13
|
+
def format
|
14
|
+
return if STATES[:format]
|
15
|
+
puts "Format #{@disk} with #{@fs}"
|
16
|
+
system("mkfs.fat -F32 #{@dev_boot_efi}") if Helpers::efi?
|
17
|
+
system("mkswap #{@lv_swap}")
|
18
|
+
system("mkfs.#{@fs} #{@lv_root}")
|
19
|
+
system("mkfs.#{@fs} #{@lv_home}") if @lv_home
|
20
|
+
@state.format
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Getch
|
4
|
+
module FileSystem
|
5
|
+
module Ext4
|
6
|
+
module Encrypt
|
7
|
+
class Mount < Getch::FileSystem::Ext4::Encrypt::Device
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
@root_dir = MOUNTPOINT
|
11
|
+
@boot_dir = "#{@root_dir}/boot"
|
12
|
+
@boot_efi_dir = "#{@root_dir}/boot/efi"
|
13
|
+
@home_dir = @user ? "#{@root_dir}/home/#{@user}" : nil
|
14
|
+
@state = Getch::States.new()
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
return if STATES[:mount]
|
19
|
+
mount_swap
|
20
|
+
mount_root
|
21
|
+
mount_boot
|
22
|
+
mount_home
|
23
|
+
mount_boot_efi
|
24
|
+
@state.mount
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def mount_swap
|
30
|
+
return if ! @lv_swap
|
31
|
+
system("swapon #{@lv_swap}")
|
32
|
+
end
|
33
|
+
|
34
|
+
def mount_root
|
35
|
+
return if ! @lv_root
|
36
|
+
Dir.mkdir(@root_dir, 0700) if ! Dir.exist?(@root_dir)
|
37
|
+
system("mount #{@lv_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 ! @lv_home
|
54
|
+
if @user != nil then
|
55
|
+
FileUtils.mkdir_p @home_dir, mode: 0700 if ! Dir.exist?(@home_dir)
|
56
|
+
system("mount #{@lv_home} #{@home_dir}")
|
57
|
+
end
|
58
|
+
@state.mount
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Ext4
|
4
|
+
module Encrypt
|
5
|
+
class Partition < Getch::FileSystem::Ext4::Encrypt::Device
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
@state = Getch::States.new()
|
9
|
+
run_partition
|
10
|
+
end
|
11
|
+
|
12
|
+
def run_partition
|
13
|
+
return if STATES[:partition ]
|
14
|
+
clear_struct
|
15
|
+
cleaning
|
16
|
+
boot
|
17
|
+
others
|
18
|
+
luks
|
19
|
+
lvm
|
20
|
+
@state.partition
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def clear_struct
|
26
|
+
exec("sgdisk -Z /dev/#{@disk}")
|
27
|
+
exec("wipefs -a /dev/#{@disk}")
|
28
|
+
end
|
29
|
+
|
30
|
+
def cleaning
|
31
|
+
puts
|
32
|
+
print "Cleaning data on #{@disk}, can be long, avoid this on Flash Memory (SSD,USB,...) ? (n,y) "
|
33
|
+
case gets.chomp
|
34
|
+
when /^y|^Y/
|
35
|
+
bloc=`blockdev --getbsz /dev/#{@disk}`.chomp
|
36
|
+
exec("dd if=/dev/urandom of=/dev/#{@disk} bs=#{bloc} status=progress")
|
37
|
+
else
|
38
|
+
return
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def boot
|
43
|
+
if Helpers::efi?
|
44
|
+
exec("sgdisk -n1:1M:+260M -t1:EF00 /dev/#{@disk}}")
|
45
|
+
else
|
46
|
+
exec("sgdisk -n1:1MiB:+1MiB -t1:EF02 /dev/#{@disk}")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def others
|
51
|
+
exec("sgdisk -n2:0:+0 -t2:8309 /dev/#{@disk}")
|
52
|
+
end
|
53
|
+
|
54
|
+
def luks
|
55
|
+
if Helpers::efi?
|
56
|
+
exec("cryptsetup --use-random luksFormat /dev/#{@disk}2")
|
57
|
+
exec("cryptsetup open --type luks /dev/#{@disk}2 crypt-lvm")
|
58
|
+
else
|
59
|
+
# GRUB do not support LUKS2
|
60
|
+
exec("cryptsetup --use-random luksFormat --type luks1 /dev/#{@disk}2")
|
61
|
+
exec("cryptsetup open --type luks1 /dev/#{@disk}2 crypt-lvm")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def lvm
|
66
|
+
mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
|
67
|
+
exec("pvcreate /dev/mapper/crypt-lvm")
|
68
|
+
exec("vgcreate #{@vg} /dev/mapper/crypt-lvm")
|
69
|
+
exec("lvcreate -L 15G -n root #{@vg}")
|
70
|
+
exec("lvcreate -L #{mem} -n swap #{@vg}")
|
71
|
+
exec("lvcreate -l 100%FREE -n home #{@vg}") if @user
|
72
|
+
exec("vgchange --available y")
|
73
|
+
end
|
74
|
+
|
75
|
+
# Follow https://wiki.archlinux.org/index.php/Partitioning
|
76
|
+
# Partition_efi
|
77
|
+
# /boot/efi - EFI system partition - 260MB
|
78
|
+
# / - Root
|
79
|
+
# swap - Linux Swap - size of the ram
|
80
|
+
# /home - Home
|
81
|
+
|
82
|
+
# Partition_bios
|
83
|
+
# None - Bios Boot Partition - 1MiB
|
84
|
+
# / - Root
|
85
|
+
# swap - Linux Swap - size of the ram
|
86
|
+
# /home - Home
|
87
|
+
|
88
|
+
def exec(cmd)
|
89
|
+
Getch::Command.new(cmd).run!
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Ext4
|
4
|
+
class Format < Getch::FileSystem::Ext4::Device
|
5
|
+
def initialize
|
6
|
+
super
|
7
|
+
@fs = 'ext4'
|
8
|
+
@state = Getch::States.new()
|
9
|
+
format
|
10
|
+
end
|
11
|
+
|
12
|
+
def format
|
13
|
+
return if STATES[:format]
|
14
|
+
puts "Format #{@disk} with #{@fs}"
|
15
|
+
system("mkfs.fat -F32 #{@dev_boot_efi}") if Helpers::efi?
|
16
|
+
system("mkswap -f #{@dev_swap}")
|
17
|
+
system("mkfs.#{@fs} #{@dev_root}")
|
18
|
+
system("mkfs.#{@fs} #{@dev_home}") if @dev_home
|
19
|
+
@state.format
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Getch
|
4
|
+
module FileSystem
|
5
|
+
module Ext4
|
6
|
+
class Mount < Getch::FileSystem::Ext4::Device
|
7
|
+
def initialize
|
8
|
+
super
|
9
|
+
@root_dir = MOUNTPOINT
|
10
|
+
@boot_dir = "#{@root_dir}/boot"
|
11
|
+
@boot_efi_dir = "#{@root_dir}/boot/efi"
|
12
|
+
@home_dir = @user ? "#{@root_dir}/home/#{@user}" : nil
|
13
|
+
@state = Getch::States.new()
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
return if STATES[:mount]
|
18
|
+
mount_swap
|
19
|
+
mount_root
|
20
|
+
mount_boot
|
21
|
+
mount_home
|
22
|
+
mount_boot_efi
|
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
|
57
|
+
@state.mount
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Ext4
|
4
|
+
class Partition < Getch::FileSystem::Ext4::Device
|
5
|
+
def initialize
|
6
|
+
super
|
7
|
+
@state = Getch::States.new()
|
8
|
+
run_partition
|
9
|
+
end
|
10
|
+
|
11
|
+
def run_partition
|
12
|
+
return if STATES[:partition ]
|
13
|
+
clear_struct
|
14
|
+
cleaning
|
15
|
+
if Helpers::efi?
|
16
|
+
partition_efi
|
17
|
+
else
|
18
|
+
partition_bios
|
19
|
+
end
|
20
|
+
@state.partition
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def clear_struct
|
26
|
+
exec("sgdisk -Z /dev/#{@disk}")
|
27
|
+
exec("wipefs -a /dev/#{@disk}")
|
28
|
+
end
|
29
|
+
|
30
|
+
def cleaning
|
31
|
+
puts
|
32
|
+
print "Cleaning data on #{@disk}, can be long, avoid this on Flash Memory (SSD,USB,...) ? (n,y) "
|
33
|
+
case gets.chomp
|
34
|
+
when /^y|^Y/
|
35
|
+
bloc=`blockdev --getbsz /dev/#{@disk}`.chomp
|
36
|
+
exec("dd if=/dev/urandom of=/dev/#{@disk} bs=#{bloc} status=progress")
|
37
|
+
else
|
38
|
+
return
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Follow https://wiki.archlinux.org/index.php/Partitioning
|
43
|
+
def partition_efi
|
44
|
+
# /boot/efi - EFI system partition - 260MB
|
45
|
+
# / - Root
|
46
|
+
# swap - Linux Swap - size of the ram
|
47
|
+
# /home - Home
|
48
|
+
mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
|
49
|
+
|
50
|
+
exec("sgdisk -n1:1M:+260M -t1:EF00 /dev/#{@disk}")
|
51
|
+
exec("sgdisk -n2:0:+15G -t2:8304 /dev/#{@disk}")
|
52
|
+
exec("sgdisk -n3:0:+#{mem} -t3:8200 /dev/#{@disk}")
|
53
|
+
exec("sgdisk -n4:0:0 -t4:8302 /dev/#{@disk}") if @dev_home
|
54
|
+
end
|
55
|
+
|
56
|
+
def partition_bios
|
57
|
+
# None - Bios Boot Partition - 1MiB
|
58
|
+
# / - Root
|
59
|
+
# swap - Linux Swap - size of the ram
|
60
|
+
# /home - Home
|
61
|
+
mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
|
62
|
+
|
63
|
+
exec("sgdisk -n1:1MiB:+1MiB -t1:EF02 /dev/#{@disk}")
|
64
|
+
exec("sgdisk -n2:0:+15G -t2:8304 /dev/#{@disk}")
|
65
|
+
exec("sgdisk -n3:0:+#{mem} -t3:8200 /dev/#{@disk}")
|
66
|
+
exec("sgdisk -n4:0:0 -t4:8302 /dev/#{@disk}") if @dev_home
|
67
|
+
end
|
68
|
+
|
69
|
+
def exec(cmd)
|
70
|
+
Getch::Command.new(cmd).run!
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/getch/gentoo.rb
CHANGED
data/lib/getch/gentoo/boot.rb
CHANGED
@@ -6,10 +6,12 @@ module Getch
|
|
6
6
|
def initialize(opts)
|
7
7
|
@disk = opts.disk
|
8
8
|
@user = opts.username
|
9
|
+
@config = OPTIONS_FS[DEFAULT_OPTIONS[:fs]]::Config.new()
|
9
10
|
end
|
10
11
|
|
11
12
|
def start
|
12
|
-
|
13
|
+
@config.fstab
|
14
|
+
OPTIONS_FS[DEFAULT_OPTIONS[:fs]]::Deps.new()
|
13
15
|
bootloader
|
14
16
|
password
|
15
17
|
umount
|
@@ -29,23 +31,13 @@ module Getch
|
|
29
31
|
puts "Configuring systemd-boot."
|
30
32
|
# ref: https://forums.gentoo.org/viewtopic-p-8118822.html
|
31
33
|
esp = '/boot/efi'
|
32
|
-
#systemd = "#{MOUNTPOINT}/usr/lib/systemd"
|
33
|
-
#FileUtils.mkdir_p "#{systemd}#{esp}", mode: 0700 if ! Dir.exist?("#{systemd}#{esp}")
|
34
34
|
exec_chroot("bootctl --path #{esp} install")
|
35
|
-
|
36
|
-
root = `lsblk -o "PARTUUID" /dev/#{@disk}3 | tail -1`.chomp()
|
37
|
-
init = '/usr/lib/systemd/systemd'
|
38
|
-
datas_gentoo = [
|
39
|
-
'title Gentoo Linux',
|
40
|
-
'linux /vmlinuz',
|
41
|
-
"options root=PARTUUID=#{root} init=#{init} rw"
|
42
|
-
]
|
43
35
|
datas_loader = [
|
44
36
|
'default gentoo',
|
45
37
|
'timeout 3',
|
46
38
|
'editor 0'
|
47
39
|
]
|
48
|
-
|
40
|
+
@config.systemd_boot
|
49
41
|
File.write("#{MOUNTPOINT}/#{esp}/loader/loader.conf", datas_loader.join("\n"))
|
50
42
|
|
51
43
|
FileUtils.cp("#{MOUNTPOINT}/usr/src/linux/arch/x86/boot/bzImage", "#{MOUNTPOINT}/#{esp}/vmlinuz", preserve: true)
|
@@ -61,6 +53,7 @@ module Getch
|
|
61
53
|
def grub
|
62
54
|
puts 'Installing GRUB...'
|
63
55
|
Helpers::emerge("sys-boot/grub:2", MOUNTPOINT)
|
56
|
+
@config.grub
|
64
57
|
exec_chroot("grub-install /dev/#{@disk}")
|
65
58
|
exec_chroot('grub-mkconfig -o /boot/grub/grub.cfg')
|
66
59
|
end
|
@@ -86,11 +79,6 @@ module Getch
|
|
86
79
|
|
87
80
|
private
|
88
81
|
|
89
|
-
def gen_fstab
|
90
|
-
mount = Getch::Mount.new(@disk, @user)
|
91
|
-
mount.gen_fstab
|
92
|
-
end
|
93
|
-
|
94
82
|
def exec_chroot(cmd)
|
95
83
|
script = "chroot #{MOUNTPOINT} /bin/bash -c \"
|
96
84
|
source /etc/profile
|
data/lib/getch/gentoo/chroot.rb
CHANGED
@@ -3,6 +3,7 @@ module Getch
|
|
3
3
|
class Chroot
|
4
4
|
def initialize
|
5
5
|
@state = Getch::States.new()
|
6
|
+
@pkgs = []
|
6
7
|
mount
|
7
8
|
end
|
8
9
|
|
@@ -32,7 +33,8 @@ module Getch
|
|
32
33
|
puts "Installing kernel gentoo-sources..."
|
33
34
|
license = "#{MOUNTPOINT}/etc/portage/package.license"
|
34
35
|
File.write(license, "sys-kernel/linux-firmware linux-fw-redistributable no-source-code\n")
|
35
|
-
|
36
|
+
@pkgs << "sys-kernel/gentoo-sources"
|
37
|
+
@pkgs << "dev-util/dwarves"
|
36
38
|
end
|
37
39
|
|
38
40
|
def kernel_deps
|
@@ -41,8 +43,10 @@ module Getch
|
|
41
43
|
garden_dep
|
42
44
|
end
|
43
45
|
|
44
|
-
def
|
45
|
-
|
46
|
+
def install_pkgs
|
47
|
+
@pkgs << "app-admin/sudo"
|
48
|
+
@pkgs << "app-editors/vim"
|
49
|
+
Helpers::emerge(@pkgs.join(" "), MOUNTPOINT)
|
46
50
|
end
|
47
51
|
|
48
52
|
private
|
@@ -59,9 +63,8 @@ module Getch
|
|
59
63
|
|
60
64
|
def garden_dep
|
61
65
|
Helpers::emerge("gentoolkit", MOUNTPOINT)
|
62
|
-
|
63
|
-
|
64
|
-
exec_chroot(cmd)
|
66
|
+
exec_chroot("euse -p sys-apps/kmod -E lzma")
|
67
|
+
@pkgs << "sys-apps/kmod"
|
65
68
|
end
|
66
69
|
|
67
70
|
def mount
|
data/lib/getch/gentoo/config.rb
CHANGED
@@ -11,13 +11,13 @@ module Getch
|
|
11
11
|
|
12
12
|
def portage
|
13
13
|
nproc = `nproc`.chomp()
|
14
|
-
|
14
|
+
grub_pc = Helpers::efi? ? '' : 'GRUB_PLATFORMS="pc"'
|
15
15
|
data = [
|
16
16
|
'',
|
17
17
|
'ACCEPT_KEYWORD="amd64 ~amd64"',
|
18
18
|
"MAKEOPTS=\"-j#{nproc} -l#{nproc}\"",
|
19
19
|
'INPUT_DEVICES="libinput"',
|
20
|
-
|
20
|
+
grub_pc
|
21
21
|
]
|
22
22
|
File.write(@make, data.join("\n"), mode: "a")
|
23
23
|
end
|
data/lib/getch/gentoo/sources.rb
CHANGED
@@ -20,9 +20,10 @@ module Getch
|
|
20
20
|
|
21
21
|
def make
|
22
22
|
puts "Compiling kernel sources"
|
23
|
-
|
24
|
-
cmd = "cd #{@linux} && make modules_install && make install"
|
23
|
+
cmd = "cd #{@linux} && make -j$(nproc) && make modules_install && make install"
|
25
24
|
exec_chroot(cmd)
|
25
|
+
is_kernel = Dir.glob("#{MOUNTPOINT}/boot/vmlinuz-*")
|
26
|
+
raise "No kernel installed, compiling source fail..." if is_kernel == []
|
26
27
|
end
|
27
28
|
|
28
29
|
def only_make
|
@@ -73,7 +74,7 @@ module Getch
|
|
73
74
|
|
74
75
|
def install_zfs
|
75
76
|
exec("./kernel.sh -b -a zfs -k #{@linux}")
|
76
|
-
only_make # a first make is necessary before emerge zfs
|
77
|
+
only_make # a first 'make' is necessary before emerge zfs
|
77
78
|
Helpers::emerge("zfs", MOUNTPOINT)
|
78
79
|
end
|
79
80
|
end
|
data/lib/getch/helpers.rb
CHANGED
data/lib/getch/options.rb
CHANGED
@@ -2,7 +2,7 @@ require 'optparse'
|
|
2
2
|
|
3
3
|
module Getch
|
4
4
|
class Options
|
5
|
-
attr_reader :language, :zoneinfo, :keyboard, :disk, :fs, :username, :verbose
|
5
|
+
attr_reader :language, :zoneinfo, :keyboard, :disk, :fs, :username, :encrypt, :verbose
|
6
6
|
|
7
7
|
def initialize(argv)
|
8
8
|
@language = DEFAULT_OPTIONS[:language]
|
@@ -11,6 +11,7 @@ module Getch
|
|
11
11
|
@disk = DEFAULT_OPTIONS[:disk]
|
12
12
|
@fs = DEFAULT_OPTIONS[:fs]
|
13
13
|
@username = DEFAULT_OPTIONS[:username]
|
14
|
+
@encrypt = DEFAULT_OPTIONS[:encrypt]
|
14
15
|
@verbose = DEFAULT_OPTIONS[:verbose]
|
15
16
|
parse(argv)
|
16
17
|
end
|
@@ -37,7 +38,10 @@ module Getch
|
|
37
38
|
opts.on("-u", "--username USERNAME", "Initialize /home/username") do |user|
|
38
39
|
@username = user
|
39
40
|
end
|
40
|
-
opts.on("
|
41
|
+
opts.on("--encrypt", "Encrypt your filesystem.!! NOT YET READY !!") do
|
42
|
+
@encrypt = true
|
43
|
+
end
|
44
|
+
opts.on("--verbose", "Write more messages to the standard output.") do
|
41
45
|
@verbose = true
|
42
46
|
end
|
43
47
|
opts.on("-h", "--help", "Display this") do
|
data/lib/getch/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: getch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- szorfein
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
J/zT/q2Ac7BWpSLbv6p9lChBiEnD9j24x463LR5QQjDNS5SsjzRQfFuprsa9Nqf2
|
36
36
|
Tw==
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2020-09-
|
38
|
+
date: 2020-09-22 00:00:00.000000000 Z
|
39
39
|
dependencies: []
|
40
40
|
description:
|
41
41
|
email:
|
@@ -56,7 +56,19 @@ files:
|
|
56
56
|
- lib/getch/command.rb
|
57
57
|
- lib/getch/filesystem.rb
|
58
58
|
- lib/getch/filesystem/ext4.rb
|
59
|
-
- lib/getch/filesystem/
|
59
|
+
- lib/getch/filesystem/ext4/config.rb
|
60
|
+
- lib/getch/filesystem/ext4/deps.rb
|
61
|
+
- lib/getch/filesystem/ext4/device.rb
|
62
|
+
- lib/getch/filesystem/ext4/encrypt.rb
|
63
|
+
- lib/getch/filesystem/ext4/encrypt/config.rb
|
64
|
+
- lib/getch/filesystem/ext4/encrypt/deps.rb
|
65
|
+
- lib/getch/filesystem/ext4/encrypt/device.rb
|
66
|
+
- lib/getch/filesystem/ext4/encrypt/format.rb
|
67
|
+
- lib/getch/filesystem/ext4/encrypt/mount.rb
|
68
|
+
- lib/getch/filesystem/ext4/encrypt/partition.rb
|
69
|
+
- lib/getch/filesystem/ext4/format.rb
|
70
|
+
- lib/getch/filesystem/ext4/mount.rb
|
71
|
+
- lib/getch/filesystem/ext4/partition.rb
|
60
72
|
- lib/getch/gentoo.rb
|
61
73
|
- lib/getch/gentoo/boot.rb
|
62
74
|
- lib/getch/gentoo/chroot.rb
|
@@ -64,7 +76,6 @@ files:
|
|
64
76
|
- lib/getch/gentoo/sources.rb
|
65
77
|
- lib/getch/gentoo/stage.rb
|
66
78
|
- lib/getch/helpers.rb
|
67
|
-
- lib/getch/mount.rb
|
68
79
|
- lib/getch/options.rb
|
69
80
|
- lib/getch/states.rb
|
70
81
|
- lib/getch/version.rb
|
@@ -90,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
101
|
- !ruby/object:Gem::Version
|
91
102
|
version: '0'
|
92
103
|
requirements: []
|
93
|
-
rubygems_version: 3.1.
|
104
|
+
rubygems_version: 3.1.4
|
94
105
|
signing_key:
|
95
106
|
specification_version: 4
|
96
107
|
summary: A CLI tool to install Gentoo
|
metadata.gz.sig
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
���L�7Zrz�{
|
2
|
+
1���Q���bp��(�)��m�')��p�6i�N�+�V${8d��
|
@@ -1,63 +0,0 @@
|
|
1
|
-
module Getch
|
2
|
-
module FileSystem
|
3
|
-
class Root
|
4
|
-
def initialize(disk)
|
5
|
-
@disk = disk
|
6
|
-
@fs = nil
|
7
|
-
@state = Getch::States.new()
|
8
|
-
end
|
9
|
-
|
10
|
-
# https://wiki.archlinux.org/index.php/Securely_wipe_disk
|
11
|
-
def cleaning
|
12
|
-
return if STATES[:partition ]
|
13
|
-
puts
|
14
|
-
print "Cleaning data on #{@disk}, can be long, avoid this on Flash Memory (SSD,USB,...) ? (n,y) "
|
15
|
-
case gets.chomp
|
16
|
-
when /^y|^Y/
|
17
|
-
system("dd if=/dev/urandom of=/dev/#{@disk} bs=4M status=progress")
|
18
|
-
else
|
19
|
-
return
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def partition
|
24
|
-
return if STATES[:partition]
|
25
|
-
Helpers::exec_or_die("sgdisk --zap-all /dev/#{@disk}")
|
26
|
-
Helpers::exec_or_die("wipefs -a /dev/#{@disk}")
|
27
|
-
if Helpers::efi? then
|
28
|
-
puts "Partition disk #{@disk} for an EFI system"
|
29
|
-
partition_efi
|
30
|
-
else
|
31
|
-
puts "Partition disk #{@disk} for a Bios system"
|
32
|
-
partition_bios
|
33
|
-
end
|
34
|
-
@state.partition
|
35
|
-
end
|
36
|
-
|
37
|
-
def format
|
38
|
-
return if STATES[:format]
|
39
|
-
puts "Format #{@disk} with #{@fs}"
|
40
|
-
if Helpers::efi? then
|
41
|
-
format_efi
|
42
|
-
else
|
43
|
-
format_bios
|
44
|
-
end
|
45
|
-
@state.format
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def partition_efi
|
51
|
-
end
|
52
|
-
|
53
|
-
def partition_bios
|
54
|
-
end
|
55
|
-
|
56
|
-
def format_efi
|
57
|
-
end
|
58
|
-
|
59
|
-
def format_bios
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
data/lib/getch/mount.rb
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
module Getch
|
4
|
-
class Mount
|
5
|
-
def initialize(disk, user)
|
6
|
-
@disk = disk
|
7
|
-
@user = user
|
8
|
-
@root_dir = MOUNTPOINT
|
9
|
-
@boot_dir = "#{@root_dir}/boot"
|
10
|
-
@boot_efi_dir = "#{@root_dir}/boot/efi"
|
11
|
-
@home_dir = @user ? "#{@root_dir}/home/#{@user}" : nil
|
12
|
-
@state = Getch::States.new()
|
13
|
-
gen_vars
|
14
|
-
end
|
15
|
-
|
16
|
-
def run
|
17
|
-
return if STATES[:mount]
|
18
|
-
mount_swap
|
19
|
-
mount_root
|
20
|
-
mount_boot
|
21
|
-
mount_home
|
22
|
-
mount_boot_efi if Helpers::efi?
|
23
|
-
@state.mount
|
24
|
-
end
|
25
|
-
|
26
|
-
def gen_fstab
|
27
|
-
file = "#{@root_dir}/etc/fstab"
|
28
|
-
FileUtils.mkdir_p "#{@root_dir}/etc", mode: 0700 if ! Dir.exist?("#{@root_dir}/etc")
|
29
|
-
gen_uuid
|
30
|
-
datas = data_fstab
|
31
|
-
File.write(file, datas.join("\n"))
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def gen_vars
|
37
|
-
@dev_boot_efi = nil
|
38
|
-
@dev_boot = nil
|
39
|
-
@dev_root = nil
|
40
|
-
@dev_swap = nil
|
41
|
-
@dev_home = nil
|
42
|
-
end
|
43
|
-
|
44
|
-
def mount_swap
|
45
|
-
return if ! @dev_swap
|
46
|
-
system("swapon #{@dev_swap}")
|
47
|
-
end
|
48
|
-
|
49
|
-
def mount_root
|
50
|
-
return if ! @dev_root
|
51
|
-
Dir.mkdir(@root_dir, 0700) if ! Dir.exist?(@root_dir)
|
52
|
-
system("mount #{@dev_root} #{@root_dir}")
|
53
|
-
end
|
54
|
-
|
55
|
-
def mount_boot_efi
|
56
|
-
return if ! @dev_boot_efi
|
57
|
-
FileUtils.mkdir_p @boot_efi_dir, mode: 0700 if ! Dir.exist?(@boot_efi_dir)
|
58
|
-
system("mount #{@dev_boot_efi} #{@boot_efi_dir}")
|
59
|
-
end
|
60
|
-
|
61
|
-
def mount_boot
|
62
|
-
return if ! @dev_boot
|
63
|
-
FileUtils.mkdir_p @boot_dir, mode: 0700 if ! Dir.exist?(@boot_dir)
|
64
|
-
system("mount #{@dev_boot} #{@boot_dir}")
|
65
|
-
end
|
66
|
-
|
67
|
-
def mount_home
|
68
|
-
return if ! @dev_home
|
69
|
-
if @user != nil then
|
70
|
-
FileUtils.mkdir_p @home_dir, mode: 0700 if ! Dir.exist?(@home_dir)
|
71
|
-
system("mount #{@dev_home} #{@home_dir}")
|
72
|
-
end
|
73
|
-
@state.mount
|
74
|
-
end
|
75
|
-
|
76
|
-
def gen_uuid
|
77
|
-
@uuid_swap = `lsblk -o "UUID" #{@dev_swap} | tail -1`.chomp() if @dev_swap
|
78
|
-
@uuid_root = `lsblk -o "UUID" #{@dev_root} | tail -1`.chomp() if @dev_root
|
79
|
-
@uuid_boot = `lsblk -o "UUID" #{@dev_boot} | tail -1`.chomp() if @dev_boot
|
80
|
-
@uuid_boot_efi = `lsblk -o "UUID" #{@dev_boot_efi} | tail -1`.chomp() if @dev_boot_efi
|
81
|
-
@uuid_home = `lsblk -o "UUID" #{@dev_home} | tail -1`.chomp() if @dev_home
|
82
|
-
end
|
83
|
-
|
84
|
-
def data_fstab
|
85
|
-
return []
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|