getch 0.1.6 → 0.1.9

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.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +17 -26
  4. data/assets/system.conf +38 -0
  5. data/lib/cmdline.rb +128 -0
  6. data/lib/getch/command.rb +31 -21
  7. data/lib/getch/config/gentoo.rb +22 -23
  8. data/lib/getch/config/void.rb +8 -10
  9. data/lib/getch/config.rb +5 -2
  10. data/lib/getch/filesystem/clean.rb +15 -15
  11. data/lib/getch/filesystem/device.rb +3 -1
  12. data/lib/getch/filesystem/ext4/config.rb +8 -4
  13. data/lib/getch/filesystem/ext4/deps.rb +3 -1
  14. data/lib/getch/filesystem/ext4/device.rb +2 -3
  15. data/lib/getch/filesystem/ext4/encrypt/config.rb +12 -7
  16. data/lib/getch/filesystem/ext4/encrypt/deps.rb +4 -2
  17. data/lib/getch/filesystem/ext4/encrypt/device.rb +5 -3
  18. data/lib/getch/filesystem/ext4/encrypt/format.rb +4 -1
  19. data/lib/getch/filesystem/ext4/encrypt/mount.rb +3 -2
  20. data/lib/getch/filesystem/ext4/encrypt/partition.rb +21 -21
  21. data/lib/getch/filesystem/ext4/encrypt/void.rb +22 -21
  22. data/lib/getch/filesystem/ext4/encrypt.rb +2 -0
  23. data/lib/getch/filesystem/ext4/format.rb +3 -0
  24. data/lib/getch/filesystem/ext4/mount.rb +3 -0
  25. data/lib/getch/filesystem/ext4/partition.rb +9 -6
  26. data/lib/getch/filesystem/ext4/void.rb +8 -7
  27. data/lib/getch/filesystem/ext4.rb +2 -0
  28. data/lib/getch/filesystem/lvm/config.rb +7 -22
  29. data/lib/getch/filesystem/lvm/deps.rb +6 -4
  30. data/lib/getch/filesystem/lvm/device.rb +2 -0
  31. data/lib/getch/filesystem/lvm/encrypt/config.rb +12 -9
  32. data/lib/getch/filesystem/lvm/encrypt/deps.rb +6 -3
  33. data/lib/getch/filesystem/lvm/encrypt/device.rb +4 -2
  34. data/lib/getch/filesystem/lvm/encrypt/format.rb +4 -0
  35. data/lib/getch/filesystem/lvm/encrypt/mount.rb +3 -0
  36. data/lib/getch/filesystem/lvm/encrypt/partition.rb +7 -7
  37. data/lib/getch/filesystem/lvm/encrypt/void.rb +20 -19
  38. data/lib/getch/filesystem/lvm/encrypt.rb +2 -0
  39. data/lib/getch/filesystem/lvm/format.rb +3 -0
  40. data/lib/getch/filesystem/lvm/mount.rb +3 -0
  41. data/lib/getch/filesystem/lvm/partition.rb +8 -5
  42. data/lib/getch/filesystem/lvm/void.rb +7 -6
  43. data/lib/getch/filesystem/lvm.rb +2 -0
  44. data/lib/getch/filesystem/mount.rb +19 -12
  45. data/lib/getch/filesystem/partition.rb +16 -8
  46. data/lib/getch/filesystem/zfs/config.rb +9 -23
  47. data/lib/getch/filesystem/zfs/deps.rb +22 -57
  48. data/lib/getch/filesystem/zfs/device.rb +3 -1
  49. data/lib/getch/filesystem/zfs/encrypt/config.rb +10 -26
  50. data/lib/getch/filesystem/zfs/encrypt/deps.rb +25 -60
  51. data/lib/getch/filesystem/zfs/encrypt/device.rb +3 -1
  52. data/lib/getch/filesystem/zfs/encrypt/format.rb +12 -8
  53. data/lib/getch/filesystem/zfs/encrypt/mount.rb +13 -8
  54. data/lib/getch/filesystem/zfs/encrypt/partition.rb +18 -15
  55. data/lib/getch/filesystem/zfs/encrypt/void.rb +23 -22
  56. data/lib/getch/filesystem/zfs/encrypt.rb +2 -0
  57. data/lib/getch/filesystem/zfs/format.rb +9 -5
  58. data/lib/getch/filesystem/zfs/mount.rb +9 -7
  59. data/lib/getch/filesystem/zfs/partition.rb +15 -12
  60. data/lib/getch/filesystem/zfs/void.rb +20 -20
  61. data/lib/getch/filesystem/zfs.rb +2 -0
  62. data/lib/getch/filesystem.rb +2 -0
  63. data/lib/getch/gentoo/boot.rb +21 -72
  64. data/lib/getch/gentoo/bootloader.rb +68 -0
  65. data/lib/getch/gentoo/chroot.rb +26 -33
  66. data/lib/getch/gentoo/config.rb +30 -26
  67. data/lib/getch/gentoo/sources.rb +55 -66
  68. data/lib/getch/gentoo/stage.rb +12 -12
  69. data/lib/getch/gentoo/use.rb +3 -7
  70. data/lib/getch/gentoo/use_flag.rb +77 -51
  71. data/lib/getch/gentoo.rb +22 -8
  72. data/lib/getch/guard.rb +50 -43
  73. data/lib/getch/helpers.rb +155 -143
  74. data/lib/getch/log.rb +7 -5
  75. data/lib/getch/options.rb +16 -14
  76. data/lib/getch/states.rb +10 -3
  77. data/lib/getch/version.rb +1 -1
  78. data/lib/getch/void/boot.rb +18 -14
  79. data/lib/getch/void/chroot.rb +20 -19
  80. data/lib/getch/void/config.rb +20 -17
  81. data/lib/getch/void/stage.rb +13 -14
  82. data/lib/getch/void.rb +7 -1
  83. data/lib/getch.rb +13 -5
  84. data.tar.gz.sig +0 -0
  85. metadata +6 -5
  86. metadata.gz.sig +0 -0
  87. data/lib/getch/filesystem/.mount.rb.swp +0 -0
  88. data/lib/getch/filesystem/zfs/encrypt/.mount.rb.swp +0 -0
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cmdline'
4
+
1
5
  module Getch
2
6
  module Gentoo
3
7
  class Sources
@@ -7,18 +11,38 @@ module Getch
7
11
  @filesystem = @class_fs::Deps.new
8
12
  end
9
13
 
10
- def build_others
11
- cryptsetup
12
- virtualbox_guest
13
- qemu_guest
14
- install_wifi
15
- install_audio
16
- flash_mod
14
+ def bask
15
+ puts ' ==> Hardening kernel...'
16
+ #Getch::Bask.new('10_kspp.config').cp
17
+ Getch::Bask.new('11-kspp-gcc.config').cp
18
+ Getch::Bask.new('12-kspp-x86_64.config').cp
19
+ #Getch::Bask.new('20-clipos.config').cp
20
+ #Getch::Bask.new('30-grsecurity.config').cp
21
+ #Getch::Bask.new('40-kconfig-hardened.config').cp
22
+ Getch::Bask.new('50-blacklist.config').cp
23
+ Getch::Bask.new('51-blacklist-madaidans.config').cp
17
24
  end
18
25
 
19
- def build_kspp
20
- puts "Adding KSPP to the kernel source"
21
- bask("-b -a systemd")
26
+ def configs
27
+ gen_cmdline
28
+ grub_mkconfig unless Helpers.efi?
29
+ end
30
+
31
+ def gen_cmdline
32
+ cmdline = CmdLine::Kernel.new(workdir: "#{MOUNTPOINT}/etc/kernel")
33
+ cmdline.main
34
+ end
35
+
36
+ def grub_mkconfig
37
+ file = "#{MOUNTPOINT}/etc/kernel/install.d/90-mkconfig.install"
38
+ content = <<~SHELL
39
+ #!/usr/bin/env sh
40
+ set -o errexit
41
+ grub-mkconfig -o /boot/grub/grub.cfg
42
+ exit 0
43
+ SHELL
44
+ File.write file, content
45
+ File.chmod 0755, file
22
46
  end
23
47
 
24
48
  def make
@@ -31,90 +55,55 @@ module Getch
31
55
  end
32
56
  end
33
57
 
34
- def firewall
35
- bask("-a iptables")
36
- Getch::Emerge.new("net-firewall/iptables").pkg!
58
+ def load_modules
59
+ install_wifi
60
+ flash_mod
37
61
  end
38
62
 
39
63
  private
40
64
 
41
65
  def make_kernel
42
- puts "Compiling kernel sources"
43
- cmd = "make -j$(nproc) && make modules_install && make install"
44
- Getch::Make.new(cmd).run!
66
+ puts 'Compiling kernel sources'
67
+ Getch::Emerge.new('sys-kernel/gentoo-kernel').pkg!
45
68
  is_kernel = Dir.glob("#{MOUNTPOINT}/boot/vmlinuz-*")
46
- raise "No kernel installed, compiling source fail..." if is_kernel == []
47
- end
48
-
49
- def cryptsetup
50
- return unless Getch::OPTIONS[:encrypt]
51
- make_conf = "#{MOUNTPOINT}/etc/portage/make.conf"
52
-
53
- puts "Adding support for cryptsetup."
54
- bask("-a cryptsetup")
55
- Getch::Chroot.new("euse -E cryptsetup").run! unless Helpers::grep?(make_conf, /cryptsetup/)
56
- Getch::Emerge.new("sys-fs/cryptsetup").pkg!
57
- end
58
-
59
- def virtualbox_guest
60
- systemd=`systemd-detect-virt`.chomp
61
- return if ! ismatch?('vmwgfx') || systemd.match(/none/)
62
- bask("-a virtualbox-guest")
63
- Getch::Emerge.new("app-emulation/virtualbox-guest-additions").pkg!
64
- end
65
-
66
- def qemu_guest
67
- bask("-a kvm-host") if ismatch?('kvm')
68
- bask("-a kvm-guest") if ismatch?('virtio')
69
+ raise 'No kernel installed, compiling source fail...' if is_kernel == []
69
70
  end
70
71
 
71
72
  def ismatch?(arg)
72
73
  @lsmod.match?(/#{arg}/)
73
74
  end
74
75
 
75
- def bask(cmd)
76
- Getch::Bask.new(cmd).run!
77
- end
78
-
79
76
  def install_wifi
80
- return if ! ismatch?('cfg80211')
81
- bask("-a wifi")
82
- wifi_drivers
83
- Getch::Emerge.new("net-wireless/iw wpa_supplicant net-wireless/iwd").pkg!
84
- end
77
+ return unless ismatch?('cfg80211')
85
78
 
86
- def install_audio
87
- return if ! ismatch?('snd_pcm')
88
- bask("-a sound")
79
+ wifi_drivers
80
+ Getch::Emerge.new('net-wireless/iwd').pkg!
89
81
  end
90
82
 
91
83
  def wifi_drivers
92
84
  conf = "#{MOUNTPOINT}/etc/modules-load.d/wifi.conf"
93
- File.delete(conf) if File.exists? conf
94
-
95
- if ismatch?('ath9k')
96
- bask("-a ath9k-driver")
97
- end
85
+ File.delete(conf) if File.exist? conf
98
86
 
99
- module_load("iwlmvm", conf)
100
- module_load("ath9k", conf)
87
+ module_load('iwlmvm', conf)
88
+ module_load('ath9k', conf)
101
89
  end
102
90
 
103
91
  def flash_mod
104
92
  conf = "#{MOUNTPOINT}/etc/modules-load.d/usb.conf"
105
- File.delete(conf) if File.exists? conf
106
-
107
- module_load("ehci_pci", conf)
108
- module_load("rtsx_pci_sdmmc", conf)
109
- module_load("sdhci_pci", conf)
110
- module_load("uas", conf)
111
- module_load("uhci_hcd", conf)
112
- module_load("xhci_pci", conf)
93
+ File.delete(conf) if File.exist? conf
94
+
95
+ module_load('ehci_pci', conf)
96
+ module_load('rtsx_pci_sdmmc', conf)
97
+ module_load('sdhci_pci', conf)
98
+ module_load('uas', conf)
99
+ module_load('uhci_hcd', conf)
100
+ module_load('xhci_pci', conf)
113
101
  end
114
102
 
115
103
  def module_load(name, file)
116
104
  return unless name
117
105
  return unless ismatch?(name)
106
+
118
107
  File.write(file, "#{name}\n", mode: 'a')
119
108
  end
120
109
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'open-uri'
2
4
  require 'open3'
3
5
 
@@ -5,7 +7,7 @@ module Getch
5
7
  module Gentoo
6
8
  class Stage
7
9
  def initialize
8
- @mirror = "https://mirrors.soeasyto.com/distfiles.gentoo.org"
10
+ @mirror = 'https://mirrors.soeasyto.com/distfiles.gentoo.org'
9
11
  @release = release
10
12
  @stage_file="stage3-amd64-systemd-#{@release}.tar.xz"
11
13
  end
@@ -28,16 +30,16 @@ module Getch
28
30
  Dir.chdir(MOUNTPOINT)
29
31
  return if File.exist?(@stage_file)
30
32
  puts "Download the last #{@stage_file}, please wait..."
31
- Helpers::get_file_online(@mirror + "/releases/amd64/autobuilds/" + file, @stage_file)
33
+ Helpers.get_file_online(@mirror + '/releases/amd64/autobuilds/' + file, @stage_file)
32
34
  end
33
35
 
34
36
  def control_files
35
- puts "Download the DIGESTS"
36
- Helpers::get_file_online(@mirror + "/releases/amd64/autobuilds/" + file + ".DIGESTS", "#{@stage_file}.DIGESTS")
37
- puts "Download the DIGESTS.asc"
38
- Helpers::get_file_online(@mirror + "/releases/amd64/autobuilds/" + file + ".DIGESTS.asc", "#{@stage_file}.DIGESTS.asc")
37
+ puts 'Download the DIGESTS'
38
+ Helpers.get_file_online(@mirror + '/releases/amd64/autobuilds/' + file + '.DIGESTS', "#{@stage_file}.DIGESTS")
39
+ puts 'Download the DIGESTS.asc'
40
+ Helpers.get_file_online(@mirror + '/releases/amd64/autobuilds/' + file + '.DIGESTS.asc', "#{@stage_file}.DIGESTS.asc")
39
41
  puts "Download the CONTENTS.gz"
40
- Helpers::get_file_online(@mirror + "/releases/amd64/autobuilds/" + file + ".CONTENTS.gz", "#{@stage_file}.CONTENTS.gz")
42
+ Helpers.get_file_online(@mirror + '/releases/amd64/autobuilds/' + file + '.CONTENTS.gz', "#{@stage_file}.CONTENTS.gz")
41
43
  end
42
44
 
43
45
  def checksum
@@ -45,7 +47,7 @@ module Getch
45
47
  command = "awk '/SHA512 HASH/{getline;print}' #{@stage_file}.DIGESTS.asc | sha512sum --check"
46
48
  _, stderr, status = Open3.capture3(command)
47
49
  if status.success? then
48
- puts "Checksum is ok"
50
+ puts 'Checksum is ok'
49
51
  decompress
50
52
  cleaning
51
53
  else
@@ -54,7 +56,7 @@ module Getch
54
56
  end
55
57
  end
56
58
 
57
- private
59
+ private
58
60
 
59
61
  # https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Stage
60
62
  def decompress
@@ -64,9 +66,7 @@ module Getch
64
66
  end
65
67
 
66
68
  def cleaning
67
- Dir.glob("stage3-amd64-systemd*").each do |f|
68
- File.delete(f)
69
- end
69
+ Dir.glob('stage3-amd64-systemd*').each { |f| File.delete(f) }
70
70
  end
71
71
  end
72
72
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Getch
2
4
  module Gentoo
3
5
  class Use
@@ -27,13 +29,7 @@ module Getch
27
29
 
28
30
  def write_global
29
31
  list = []
30
-
31
- @flags.each { |f|
32
- unless Helpers::grep?(@make, /#{f}/)
33
- list << f
34
- end
35
- }
36
-
32
+ @flags.each { |f| list << f unless Helpers.grep?(@make, /#{f}/) }
37
33
  use = list.join(' ')
38
34
  line = "USE=\"${USE} #{use}\"\n"
39
35
  File.write(@make, line, mode: 'a')
@@ -1,63 +1,89 @@
1
- # lib/use_flag.rb
1
+ # frozen_string_literal: true
2
2
 
3
- module Getch::Gentoo
4
- class UseFlag
5
- def initialize
6
- @efi = Helpers::efi?
7
- end
3
+ module Getch
4
+ module Gentoo
5
+ class UseFlag
6
+ def initialize
7
+ @efi = Helpers.efi?
8
+ end
8
9
 
9
- def apply
10
- systemd
11
- kmod
12
- grub
13
- zfs
14
- lvm
15
- cryptsetup
16
- end
10
+ def apply
11
+ systemd
12
+ pam
13
+ kernel
14
+ kmod
15
+ grub
16
+ zfs
17
+ lvm
18
+ cryptsetup
19
+ end
17
20
 
18
- private
21
+ private
19
22
 
20
- def systemd
21
- flags = []
22
- use = Getch::Gentoo::Use.new('sys-apps/systemd')
23
- flags << 'dns-over-tls'
24
- flags << 'gnuefi' if @efi
25
- use.add(flags)
26
- end
23
+ def systemd
24
+ flags = []
25
+ use = Getch::Gentoo::Use.new('sys-apps/systemd')
26
+ flags << 'dns-over-tls'
27
+ flags << 'gnuefi' if @efi
28
+ use.add(flags)
29
+ end
27
30
 
28
- def kmod
29
- use = Getch::Gentoo::Use.new('sys-apps/kmod')
30
- use.add('zstd', 'lzma')
31
- end
31
+ def pam
32
+ flags = []
33
+ use = Getch::Gentoo::Use.new('sys-auth/pambase')
34
+ flags << '-passwdqc'
35
+ flags << 'pwquality'
36
+ flags << 'sha512'
37
+ use.add(flags)
38
+ end
32
39
 
33
- def grub
34
- return if @efi
35
- flags = []
36
- use = Getch::Gentoo::Use.new('sys-boot/grub')
37
- flags << '-grub_platforms_efi-64'
38
- flags << 'libzfs' if Getch::OPTIONS[:fs] == 'zfs'
39
- flags << 'device-mapper' if Getch::OPTIONS[:fs] == 'lvm'
40
- use.add(flags)
41
- end
40
+ def kernel
41
+ use = Getch::Gentoo::Use.new('sys-kernel/gentoo-kernel')
42
+ use.add('hardened')
43
+ end
42
44
 
43
- def zfs
44
- return unless Getch::OPTIONS[:fs] == 'zfs'
45
- use = Getch::Gentoo::Use.new('sys-fs/zfs-kmod')
46
- use.add('rootfs')
47
- use = Getch::Gentoo::Use.new('sys-fs/zfs')
48
- use.add('rootfs')
49
- end
45
+ def kmod
46
+ use = Getch::Gentoo::Use.new('sys-apps/kmod')
47
+ use.add('zstd', 'lzma')
48
+ end
50
49
 
51
- def lvm
52
- return unless Getch::OPTIONS[:fs] == 'lvm'
53
- use = Getch::Gentoo::Use.new
54
- use.add_global('lvm', 'device-mapper')
55
- end
50
+ def grub
51
+ return if @efi
52
+
53
+ flags = []
54
+ use = Getch::Gentoo::Use.new('sys-boot/grub')
55
+ flags << '-grub_platforms_efi-64'
56
+ flags << 'libzfs' if Getch::OPTIONS[:fs] == 'zfs'
57
+ flags << 'device-mapper' if Getch::OPTIONS[:fs] == 'lvm'
58
+ use.add(flags)
59
+ end
60
+
61
+ def zfs
62
+ return unless Getch::OPTIONS[:fs] == 'zfs'
63
+
64
+ use = Getch::Gentoo::Use.new('sys-fs/zfs-kmod')
65
+ use.add('rootfs')
66
+ use = Getch::Gentoo::Use.new('sys-fs/zfs')
67
+ use.add('rootfs')
68
+
69
+ # https://wiki.gentoo.org/wiki/Project:Distribution_Kernel
70
+ use = Getch::Gentoo::Use.new
71
+ use.add_global('dist-kernel')
72
+ end
73
+
74
+ def lvm
75
+ return unless Getch::OPTIONS[:fs] == 'lvm'
76
+
77
+ use = Getch::Gentoo::Use.new
78
+ use.add_global('lvm', 'device-mapper')
79
+ end
80
+
81
+ def cryptsetup
82
+ return unless Getch::OPTIONS[:encrypt]
56
83
 
57
- def cryptsetup
58
- return unless Getch::OPTIONS[:encrypt]
59
- use = Getch::Gentoo::Use.new
60
- use.add_global('cryptsetup')
84
+ use = Getch::Gentoo::Use.new
85
+ use.add_global('cryptsetup')
86
+ end
61
87
  end
62
88
  end
63
89
  end
data/lib/getch/gentoo.rb CHANGED
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'gentoo/stage'
2
4
  require_relative 'gentoo/config'
3
5
  require_relative 'gentoo/chroot'
6
+ require_relative 'gentoo/bootloader'
4
7
  require_relative 'gentoo/sources'
5
8
  require_relative 'gentoo/boot'
6
9
  require_relative 'gentoo/use'
@@ -10,11 +13,12 @@ module Getch
10
13
  module Gentoo
11
14
  class Main
12
15
  def initialize
13
- @state = Getch::States.new()
16
+ @state = Getch::States.new
14
17
  end
15
18
 
16
19
  def stage3
17
20
  return if STATES[:gentoo_base]
21
+
18
22
  stage = Getch::Gentoo::Stage.new
19
23
  stage.get_stage3
20
24
  stage.control_files
@@ -24,6 +28,7 @@ module Getch
24
28
 
25
29
  def config
26
30
  return if STATES[:gentoo_config]
31
+
27
32
  config = Getch::Gentoo::Config.new
28
33
  config.portage
29
34
  config.portage_fs
@@ -36,6 +41,8 @@ module Getch
36
41
  end
37
42
 
38
43
  def chroot
44
+ return if STATES[:gentoo_update]
45
+
39
46
  chroot = Getch::Gentoo::Chroot.new
40
47
  chroot.update
41
48
  chroot.cpuflags
@@ -45,20 +52,27 @@ module Getch
45
52
  flags.apply
46
53
 
47
54
  chroot.world
48
- return if STATES[:gentoo_kernel]
49
- chroot.kernel
50
- chroot.kernel_deps
55
+ chroot.kernel_license
51
56
  chroot.install_pkgs
52
- chroot.kernel_link
57
+ @state.update
58
+ end
59
+
60
+ def bootloader
61
+ return if STATES[:gentoo_bootloader]
62
+
63
+ bootloader = Getch::Gentoo::Bootloader.new
64
+ bootloader.start
65
+ @state.bootloader
53
66
  end
54
67
 
55
68
  def kernel
56
69
  return if STATES[:gentoo_kernel]
70
+
57
71
  source = Getch::Gentoo::Sources.new
58
- source.build_kspp
59
- source.build_others
60
- source.firewall
72
+ source.bask
73
+ source.configs
61
74
  source.make
75
+ source.load_modules
62
76
  @state.kernel
63
77
  end
64
78
 
data/lib/getch/guard.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class InvalidDisk < StandardError
2
4
  end
3
5
 
@@ -10,55 +12,60 @@ end
10
12
  class InvalidKeymap < StandardError
11
13
  end
12
14
 
13
- module Getch::Guard
14
- def self.disk(name)
15
- raise InvalidDisk, "No disk." unless name
16
- raise InvalidDisk, "Bad device name #{name}." unless name.match(/^sd[a-z]{1}$/)
17
- raise InvalidDisk, "Disk /dev/#{name} no found." unless File.exist? "/dev/#{name}"
18
- name
19
- rescue InvalidDisk => e
20
- puts "#{e.class} => #{e}"
21
- exit 1
22
- end
15
+ module Getch
16
+ module Guard
17
+ def self.disk(name)
18
+ raise InvalidDisk, 'No disk.' unless name
19
+ raise InvalidDisk, "Bad device name #{name}." unless name.match(/^sd[a-z]{1}$/)
20
+ raise InvalidDisk, "Disk /dev/#{name} no found." unless File.exist? "/dev/#{name}"
23
21
 
24
- def self.format(name)
25
- raise InvalidFormat, "No format specified." unless name
26
- raise InvalidFormat, "Format #{name} not yet available." if name.match(/btrfs/)
27
- raise InvalidFormat, "Format #{name} not supported." unless name.match(/zfs|lvm|ext4/)
28
- name
29
- rescue InvalidFormat => e
30
- puts "#{e.class} => #{e}"
31
- exit 1
32
- end
22
+ name
23
+ rescue InvalidDisk => e
24
+ puts "#{e.class} => #{e}"
25
+ exit 1
26
+ end
33
27
 
34
- def self.zone(name)
35
- raise InvalidZone, "No zoneinfo specified." unless name
36
- raise InvalidZone, "Directory /usr/share/zoneinfo/ no found on this system..." unless Dir.exist? "/usr/share/zoneinfo/"
37
- raise InvalidZone, "Zoneinfo #{name} is no found in /usr/share/zoneinfo/." unless File.exist? "/usr/share/zoneinfo/#{name}"
38
- name
39
- rescue InvalidZone => e
40
- puts "#{e.class} => #{e}"
41
- exit 1
42
- end
28
+ def self.format(name)
29
+ raise InvalidFormat, 'No format specified.' unless name
30
+ raise InvalidFormat, "Format #{name} not yet available." if name.match(/btrfs/)
31
+ raise InvalidFormat, "Format #{name} not supported." unless name.match(/zfs|lvm|ext4/)
43
32
 
44
- def self.keymap(name)
45
- raise InvalidKeymap, "No keymap specified." unless name
46
- key = []
33
+ name
34
+ rescue InvalidFormat => e
35
+ puts "#{e.class} => #{e}"
36
+ exit 1
37
+ end
47
38
 
48
- if Dir.exist? '/usr/share/keymaps'
49
- key = Dir.glob("/usr/share/keymaps/**/#{name}.map.gz")
50
- elsif Dir.exist? '/usr/share/kbd/keymaps'
51
- key = Dir.glob("/usr/share/kbd/keymaps/**/#{name}.map.gz")
52
- else
53
- raise InvalidKeymap, "No directory found for keymap."
39
+ def self.zone(name)
40
+ raise InvalidZone, 'No zoneinfo specified.' unless name
41
+ raise InvalidZone, 'Directory /usr/share/zoneinfo/ no found on this system...' unless Dir.exist? '/usr/share/zoneinfo/'
42
+ raise InvalidZone, "Zoneinfo #{name} is no found in /usr/share/zoneinfo/." unless File.exist? "/usr/share/zoneinfo/#{name}"
43
+
44
+ name
45
+ rescue InvalidZone => e
46
+ puts "#{e.class} => #{e}"
47
+ exit 1
54
48
  end
55
49
 
56
- if key == []
57
- raise InvalidKeymap, "Keymap #{name} no found."
50
+ def self.keymap(name)
51
+ raise InvalidKeymap, 'No keymap specified.' unless name
52
+
53
+ key = []
54
+
55
+ if Dir.exist? '/usr/share/keymaps'
56
+ key = Dir.glob("/usr/share/keymaps/**/#{name}.map.gz")
57
+ elsif Dir.exist? '/usr/share/kbd/keymaps'
58
+ key = Dir.glob("/usr/share/kbd/keymaps/**/#{name}.map.gz")
59
+ else
60
+ raise InvalidKeymap, 'No directory found for keymap.'
61
+ end
62
+
63
+ raise InvalidKeymap, "Keymap #{name} no found." if key == []
64
+
65
+ name
66
+ rescue InvalidKeymap => e
67
+ puts "#{e.class} => #{e}"
68
+ exit 1
58
69
  end
59
- name
60
- rescue InvalidKeymap => e
61
- puts "#{e.class} => #{e}"
62
- exit 1
63
70
  end
64
71
  end