getch 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +64 -24
  5. data/assets/network-stack.conf +63 -0
  6. data/bin/getch +12 -4
  7. data/lib/getch.rb +113 -78
  8. data/lib/getch/command.rb +1 -1
  9. data/lib/getch/config.rb +33 -49
  10. data/lib/getch/config/gentoo.rb +59 -0
  11. data/lib/getch/config/void.rb +49 -0
  12. data/lib/getch/filesystem/.mount.rb.swp +0 -0
  13. data/lib/getch/filesystem/device.rb +5 -5
  14. data/lib/getch/filesystem/ext4.rb +1 -0
  15. data/lib/getch/filesystem/ext4/encrypt.rb +1 -0
  16. data/lib/getch/filesystem/ext4/encrypt/config.rb +2 -2
  17. data/lib/getch/filesystem/ext4/encrypt/format.rb +0 -1
  18. data/lib/getch/filesystem/ext4/encrypt/mount.rb +0 -1
  19. data/lib/getch/filesystem/ext4/encrypt/partition.rb +10 -16
  20. data/lib/getch/filesystem/ext4/encrypt/void.rb +100 -0
  21. data/lib/getch/filesystem/ext4/format.rb +1 -1
  22. data/lib/getch/filesystem/ext4/void.rb +43 -0
  23. data/lib/getch/filesystem/lvm.rb +1 -0
  24. data/lib/getch/filesystem/lvm/encrypt.rb +1 -0
  25. data/lib/getch/filesystem/lvm/encrypt/config.rb +2 -2
  26. data/lib/getch/filesystem/lvm/encrypt/format.rb +1 -2
  27. data/lib/getch/filesystem/lvm/encrypt/mount.rb +1 -2
  28. data/lib/getch/filesystem/lvm/encrypt/partition.rb +10 -7
  29. data/lib/getch/filesystem/lvm/encrypt/void.rb +100 -0
  30. data/lib/getch/filesystem/lvm/format.rb +1 -1
  31. data/lib/getch/filesystem/lvm/void.rb +45 -0
  32. data/lib/getch/filesystem/partition.rb +4 -4
  33. data/lib/getch/filesystem/zfs.rb +1 -0
  34. data/lib/getch/filesystem/zfs/config.rb +3 -3
  35. data/lib/getch/filesystem/zfs/deps.rb +11 -4
  36. data/lib/getch/filesystem/zfs/device.rb +6 -0
  37. data/lib/getch/filesystem/zfs/encrypt.rb +1 -0
  38. data/lib/getch/filesystem/zfs/encrypt/.mount.rb.swp +0 -0
  39. data/lib/getch/filesystem/zfs/encrypt/config.rb +5 -5
  40. data/lib/getch/filesystem/zfs/encrypt/deps.rb +11 -4
  41. data/lib/getch/filesystem/zfs/encrypt/device.rb +6 -0
  42. data/lib/getch/filesystem/zfs/encrypt/format.rb +9 -10
  43. data/lib/getch/filesystem/zfs/encrypt/mount.rb +5 -9
  44. data/lib/getch/filesystem/zfs/encrypt/partition.rb +3 -1
  45. data/lib/getch/filesystem/zfs/encrypt/void.rb +96 -0
  46. data/lib/getch/filesystem/zfs/format.rb +9 -9
  47. data/lib/getch/filesystem/zfs/mount.rb +5 -8
  48. data/lib/getch/filesystem/zfs/partition.rb +2 -1
  49. data/lib/getch/filesystem/zfs/void.rb +81 -0
  50. data/lib/getch/gentoo.rb +12 -15
  51. data/lib/getch/gentoo/boot.rb +7 -4
  52. data/lib/getch/gentoo/config.rb +8 -8
  53. data/lib/getch/gentoo/sources.rb +6 -3
  54. data/lib/getch/gentoo/stage.rb +0 -1
  55. data/lib/getch/gentoo/use_flag.rb +6 -7
  56. data/lib/getch/guard.rb +3 -1
  57. data/lib/getch/helpers.rb +107 -1
  58. data/lib/getch/log.rb +3 -2
  59. data/lib/getch/options.rb +41 -34
  60. data/lib/getch/version.rb +1 -1
  61. data/lib/getch/void.rb +59 -0
  62. data/lib/getch/void/boot.rb +80 -0
  63. data/lib/getch/void/chroot.rb +55 -0
  64. data/lib/getch/void/config.rb +87 -0
  65. data/lib/getch/void/stage.rb +70 -0
  66. metadata +22 -9
  67. metadata.gz.sig +0 -0
  68. data/.gitignore +0 -2
  69. data/CHANGELOG.md +0 -99
  70. data/Rakefile +0 -21
  71. data/bin/setup.sh +0 -90
  72. data/getch.gemspec +0 -25
data/lib/getch/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Getch
2
- VERSION = '0.1.5'.freeze
2
+ VERSION = '0.1.6'.freeze
3
3
  end
data/lib/getch/void.rb ADDED
@@ -0,0 +1,59 @@
1
+ require_relative 'void/stage'
2
+ require_relative 'void/config'
3
+ require_relative 'void/chroot'
4
+ #require_relative 'void/sources'
5
+ require_relative 'void/boot'
6
+
7
+ module Getch
8
+ module Void
9
+ class Main
10
+ def initialize
11
+ @state = Getch::States.new()
12
+ end
13
+
14
+ def root_fs
15
+ return if STATES[:gentoo_base]
16
+ xbps = Getch::Void::RootFS.new
17
+ xbps.search_archive
18
+ xbps.download
19
+ xbps.checksum
20
+ @state.stage3
21
+ end
22
+
23
+ def config
24
+ return if STATES[:gentoo_config]
25
+ config = Getch::Void::Config.new
26
+ config.host
27
+ config.network
28
+ config.system
29
+ config.locale
30
+ @state.config
31
+ end
32
+
33
+ def chroot
34
+ return if STATES[:gentoo_kernel]
35
+ chroot = Getch::Void::Chroot.new
36
+ chroot.update
37
+ chroot.fs
38
+ chroot.extras
39
+ chroot.install_pkgs
40
+ end
41
+
42
+ def kernel
43
+ return if STATES[:gentoo_kernel]
44
+ Getch::Void::Sources.new
45
+ @state.kernel
46
+ end
47
+
48
+ def boot
49
+ boot = Getch::Void::Boot.new
50
+ boot.new_user
51
+ boot.fstab
52
+ boot.dracut
53
+ boot.grub
54
+ boot.initramfs
55
+ boot.finish
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,80 @@
1
+ require 'fileutils'
2
+ require_relative '../helpers'
3
+
4
+ module Getch
5
+ module Void
6
+ class Boot
7
+ include Helpers::Void
8
+
9
+ def initialize
10
+ @efi = Helpers::efi?
11
+ @class_fs = Getch::select_fs
12
+ @fs = @class_fs::Void.new
13
+ @user = OPTIONS[:username]
14
+ @fs.create_key if @class_fs::Void.method_defined? :create_key
15
+ end
16
+
17
+ def new_user
18
+ puts " => Add a password for root."
19
+ chroot "passwd"
20
+ puts
21
+ return unless @user
22
+ print " => Creating a new user #{@user}..."
23
+ puts "\s[OK]"
24
+ command "useradd -m -G users,wheel,audio,video #{@user}"
25
+ puts " => Add a password for #{@user}."
26
+ chroot "passwd #{@user}"
27
+ puts
28
+ end
29
+
30
+ def fstab
31
+ print " => Configuring fstab..."
32
+ @fs.fstab
33
+ puts "\s[OK]"
34
+ @fs.crypttab if @class_fs::Void.method_defined? :crypttab
35
+ end
36
+
37
+ # Test dracut in chroot (version in /lib/modules/5.1.7-1):
38
+ # dracut -H -f --kver 5.1.7-1
39
+ def dracut
40
+ print " => Configuring Dracut..."
41
+ @fs.config_dracut
42
+ @fs.kernel_cmdline_dracut
43
+ puts "\s[OK]"
44
+ end
45
+
46
+ def grub
47
+ disk = OPTIONS[:boot_disk] ||= OPTIONS[:disk]
48
+ print " => Installing Grub on #{disk}..."
49
+ if @efi
50
+ command_output "xbps-install -y grub-x86_64-efi"
51
+ @fs.config_grub if @class_fs::Void.method_defined? :config_grub
52
+ command_output "grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=\"Void\""
53
+ else
54
+ command_output "xbps-install -y grub"
55
+ @fs.config_grub if @class_fs::Void.method_defined? :config_grub
56
+ command_output "grub-install /dev/#{disk}"
57
+ end
58
+ end
59
+
60
+ def initramfs
61
+ puts " => Generating an initramfs..."
62
+ command_output "xbps-reconfigure -fa" # this command also start grub-mkconfig
63
+ end
64
+
65
+ def finish
66
+ puts
67
+ puts "[*!*] Install finished [*!*]"
68
+ puts
69
+ @fs.finish
70
+ puts
71
+ end
72
+
73
+ private
74
+
75
+ def chroot(cmd)
76
+ system("chroot", MOUNTPOINT, "/bin/bash", "-c", cmd)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,55 @@
1
+ require_relative '../helpers'
2
+
3
+ module Getch
4
+ module Void
5
+ class Chroot
6
+ include Helpers::Void
7
+
8
+ def initialize
9
+ @state = Getch::States.new()
10
+ @pkgs = []
11
+ mount
12
+ end
13
+
14
+ # https://docs.voidlinux.org/installation/guides/chroot.html#install-base-system-rootfs-method-only
15
+ def update
16
+ return if STATES[:gentoo_update]
17
+ command_output "/usr/bin/xbps-install -Suy xbps" # y to force (--yes)
18
+ command_output "/usr/bin/xbps-install -uy"
19
+ command_output "/usr/bin/xbps-install -y base-system"
20
+ #command_output "/usr/bin/xbps-remove base-voidstrap"
21
+ @state.update
22
+ end
23
+
24
+ def extras
25
+ @pkgs << "vim"
26
+ @pkgs << "iptables"
27
+ @pkgs << "iwd"
28
+ end
29
+
30
+ def fs
31
+ @pkgs << "lvm2" if OPTIONS[:fs] == 'lvm'
32
+ @pkgs << "zfs" if OPTIONS[:fs] == 'zfs'
33
+ @pkgs << "cryptsetup" if OPTIONS[:encrypt]
34
+ end
35
+
36
+ def install_pkgs
37
+ all_pkgs = @pkgs.join(" ")
38
+ command_output "/usr/bin/xbps-install -y #{all_pkgs}"
39
+ end
40
+
41
+ private
42
+
43
+ def mount
44
+ puts "Populate /proc, /sys and /dev."
45
+ Helpers::exec_or_die("mount --types proc /proc \"#{MOUNTPOINT}/proc\"")
46
+ Helpers::exec_or_die("mount --rbind /sys \"#{MOUNTPOINT}/sys\"")
47
+ Helpers::exec_or_die("mount --make-rslave \"#{MOUNTPOINT}/sys\"")
48
+ Helpers::exec_or_die("mount --rbind /dev \"#{MOUNTPOINT}/dev\"")
49
+ Helpers::exec_or_die("mount --make-rslave \"#{MOUNTPOINT}/dev\"")
50
+ # Maybe add /dev/shm like describe here:
51
+ # https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Base
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,87 @@
1
+ require 'fileutils'
2
+ require 'securerandom'
3
+ require_relative '../helpers'
4
+
5
+ module Getch
6
+ module Void
7
+ class Config
8
+ include Helpers::Void
9
+
10
+ def initialize
11
+ @log = Getch::Log.new
12
+ @network_dir = "#{MOUNTPOINT}/etc"
13
+ @id = SecureRandom.hex(2)
14
+ @hostname = "void-hatch-#{@id}"
15
+ end
16
+
17
+ def host
18
+ print " => Adding hostname #{@hostname}..."
19
+ conf = "#{@network_dir}/hostname"
20
+ File.write(conf, "#{@hostname}\n", mode: 'w', chmod: 0744)
21
+ puts "\s[OK]"
22
+ end
23
+
24
+ def network
25
+ print " => Copying /etc/resolv.conf..."
26
+ src = '/etc/resolv.conf'
27
+ dest = "#{@network_dir}/resolv.conf"
28
+ FileUtils.copy_file(src, dest, preserve = true)
29
+ puts "\s[Ok]"
30
+ end
31
+
32
+ def system
33
+ print " => Updating configs system..."
34
+ control_options
35
+ rc = "#{MOUNTPOINT}/etc/rc.conf"
36
+ add_line(rc, "HARDWARECLOCK=\"UTC\"") if !search(rc, /^HARDWARECLOCK/)
37
+ add_line(rc, "KEYMAP=\"#{OPTIONS[:keymap]}\"") if !search(rc, /^KEYMAP/)
38
+ add_line(rc, "TIMEZONE=\"#{OPTIONS[:zoneinfo]}\"") if !search(rc, /^TIMEZONE/)
39
+ add_line(rc, "HOSTNAME=\"#{@hostname}\"") if !search(rc, /^HOSTNAME/)
40
+ puts "\s[OK]"
41
+ end
42
+
43
+ def locale
44
+ print " => Updating locale system..."
45
+ control_options
46
+ conf = "#{MOUNTPOINT}/etc/locale.conf"
47
+ File.write(conf, "LANG=#{@lang}\n")
48
+ add_line(conf, "LC_COLLATE=C")
49
+ conf = "#{MOUNTPOINT}/etc/default/libc-locales"
50
+ add_line(conf, @utf8)
51
+ puts "\s[OK]"
52
+ command "xbps-reconfigure -f glibc-locales"
53
+ end
54
+
55
+ private
56
+
57
+ def control_options
58
+ search_zone(OPTIONS[:zoneinfo])
59
+ search_utf8(OPTIONS[:language])
60
+ search_key(OPTIONS[:keymap])
61
+ end
62
+
63
+ def search_key(keys)
64
+ @keymap = nil
65
+ Dir.glob("#{MOUNTPOINT}/usr/share/kbd/keymaps/**/#{keys}.map.gz") { |f|
66
+ @keymap = f
67
+ }
68
+ raise ArgumentError, "No keymap #{@keymap} found" if ! @keymap
69
+ end
70
+
71
+ def search_zone(zone)
72
+ unless File.exist? "#{MOUNTPOINT}/usr/share/zoneinfo/#{zone}"
73
+ raise ArgumentError, "Zoneinfo #{zone} doesn\'t exist."
74
+ end
75
+ end
76
+
77
+ def search_utf8(lang)
78
+ @utf8, @lang = nil, nil
79
+ File.open("#{MOUNTPOINT}/etc/default/libc-locales").each { |l|
80
+ @utf8 = $~[0] if l.match(/#{lang}[. ]+[utf\-8 ]+/i)
81
+ @lang = $~[0] if l.match(/#{lang}[. ]+utf\-8/i)
82
+ }
83
+ raise ArgumentError, "Lang #{lang} no found" if !@utf8
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,70 @@
1
+ require 'open-uri'
2
+ require 'open3'
3
+
4
+ module Getch
5
+ module Void
6
+ class RootFS
7
+ def initialize
8
+ @url = "https://alpha.de.repo.voidlinux.org/live/current"
9
+ @file = "sha256sum.sig"
10
+ @xbps = false
11
+ Dir.chdir(MOUNTPOINT)
12
+ end
13
+
14
+ # Search only the glibc x86_64 for now
15
+ def search_archive
16
+ yurl = "#{@url}/#{@file}"
17
+ puts "Open #{yurl}"
18
+ Helpers::get_file_online(yurl, @file)
19
+ File.open(@file).each { |l|
20
+ @xbps = l.tr('()', '').split(" ") if l.match(/void-x86_64-ROOTFS-[\d._]+.tar.xz/)
21
+ }
22
+ end
23
+
24
+ def download
25
+ raise StandardError, "No file found, retry later." if !@xbps
26
+ return if File.exist? @xbps[1]
27
+ puts "Downloading #{@xbps[1]}..."
28
+ Helpers::get_file_online("#{@url}/#{@xbps[1]}", @xbps[1])
29
+ end
30
+
31
+ def checksum
32
+ print ' => Checking SHA256 checksum...'
33
+ # Should contain 2 spaces...
34
+ command = "echo #{@xbps[3]} #{@xbps[1]} | sha256sum --check"
35
+ _, stderr, status = Open3.capture3(command)
36
+ if status.success? then
37
+ puts "\t[OK]"
38
+ decompress
39
+ cleaning
40
+ return
41
+ end
42
+ cleaning
43
+ raise "Problem with the checksum, stderr\n#{stderr}"
44
+ end
45
+
46
+ private
47
+
48
+ def decompress
49
+ print " => Decompressing archive #{@xbps[1]}..."
50
+ cmd = "tar xpf #{@xbps[1]} --xattrs-include=\'*.*\' --numeric-owner"
51
+ _, stderr, status = Open3.capture3(cmd)
52
+ if status.success? then
53
+ puts "\s[OK]"
54
+ return
55
+ end
56
+ cleaning
57
+ raise "Fail to decompress archive #{@xbps[1]} - #{stderr}."
58
+ end
59
+
60
+ def cleaning
61
+ Dir.glob("void-x86_64*.tar.xz").each do |f|
62
+ File.delete(f)
63
+ end
64
+ Dir.glob("sha256*").each do |f|
65
+ File.delete(f)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
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.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - szorfein
@@ -35,7 +35,7 @@ cert_chain:
35
35
  F9Dl4EPzjBJOgQWf+NxzxNuNKI46Lp5Q8AI+xtDUHAPbSswHa40BA6ChFehP+j0L
36
36
  fg==
37
37
  -----END CERTIFICATE-----
38
- date: 2021-06-20 00:00:00.000000000 Z
38
+ date: 2021-06-30 00:00:00.000000000 Z
39
39
  dependencies: []
40
40
  description:
41
41
  email:
@@ -43,19 +43,19 @@ email:
43
43
  executables:
44
44
  - getch
45
45
  extensions: []
46
- extra_rdoc_files: []
46
+ extra_rdoc_files:
47
+ - README.md
47
48
  files:
48
- - ".gitignore"
49
- - CHANGELOG.md
50
49
  - README.md
51
- - Rakefile
50
+ - assets/network-stack.conf
52
51
  - bin/getch
53
- - bin/setup.sh
54
- - getch.gemspec
55
52
  - lib/getch.rb
56
53
  - lib/getch/command.rb
57
54
  - lib/getch/config.rb
55
+ - lib/getch/config/gentoo.rb
56
+ - lib/getch/config/void.rb
58
57
  - lib/getch/filesystem.rb
58
+ - lib/getch/filesystem/.mount.rb.swp
59
59
  - lib/getch/filesystem/clean.rb
60
60
  - lib/getch/filesystem/device.rb
61
61
  - lib/getch/filesystem/ext4.rb
@@ -69,9 +69,11 @@ files:
69
69
  - lib/getch/filesystem/ext4/encrypt/format.rb
70
70
  - lib/getch/filesystem/ext4/encrypt/mount.rb
71
71
  - lib/getch/filesystem/ext4/encrypt/partition.rb
72
+ - lib/getch/filesystem/ext4/encrypt/void.rb
72
73
  - lib/getch/filesystem/ext4/format.rb
73
74
  - lib/getch/filesystem/ext4/mount.rb
74
75
  - lib/getch/filesystem/ext4/partition.rb
76
+ - lib/getch/filesystem/ext4/void.rb
75
77
  - lib/getch/filesystem/lvm.rb
76
78
  - lib/getch/filesystem/lvm/config.rb
77
79
  - lib/getch/filesystem/lvm/deps.rb
@@ -83,9 +85,11 @@ files:
83
85
  - lib/getch/filesystem/lvm/encrypt/format.rb
84
86
  - lib/getch/filesystem/lvm/encrypt/mount.rb
85
87
  - lib/getch/filesystem/lvm/encrypt/partition.rb
88
+ - lib/getch/filesystem/lvm/encrypt/void.rb
86
89
  - lib/getch/filesystem/lvm/format.rb
87
90
  - lib/getch/filesystem/lvm/mount.rb
88
91
  - lib/getch/filesystem/lvm/partition.rb
92
+ - lib/getch/filesystem/lvm/void.rb
89
93
  - lib/getch/filesystem/mount.rb
90
94
  - lib/getch/filesystem/partition.rb
91
95
  - lib/getch/filesystem/zfs.rb
@@ -93,15 +97,18 @@ files:
93
97
  - lib/getch/filesystem/zfs/deps.rb
94
98
  - lib/getch/filesystem/zfs/device.rb
95
99
  - lib/getch/filesystem/zfs/encrypt.rb
100
+ - lib/getch/filesystem/zfs/encrypt/.mount.rb.swp
96
101
  - lib/getch/filesystem/zfs/encrypt/config.rb
97
102
  - lib/getch/filesystem/zfs/encrypt/deps.rb
98
103
  - lib/getch/filesystem/zfs/encrypt/device.rb
99
104
  - lib/getch/filesystem/zfs/encrypt/format.rb
100
105
  - lib/getch/filesystem/zfs/encrypt/mount.rb
101
106
  - lib/getch/filesystem/zfs/encrypt/partition.rb
107
+ - lib/getch/filesystem/zfs/encrypt/void.rb
102
108
  - lib/getch/filesystem/zfs/format.rb
103
109
  - lib/getch/filesystem/zfs/mount.rb
104
110
  - lib/getch/filesystem/zfs/partition.rb
111
+ - lib/getch/filesystem/zfs/void.rb
105
112
  - lib/getch/gentoo.rb
106
113
  - lib/getch/gentoo/boot.rb
107
114
  - lib/getch/gentoo/chroot.rb
@@ -116,10 +123,16 @@ files:
116
123
  - lib/getch/options.rb
117
124
  - lib/getch/states.rb
118
125
  - lib/getch/version.rb
126
+ - lib/getch/void.rb
127
+ - lib/getch/void/boot.rb
128
+ - lib/getch/void/chroot.rb
129
+ - lib/getch/void/config.rb
130
+ - lib/getch/void/stage.rb
119
131
  homepage: https://github.com/szorfein/getch
120
132
  licenses:
121
133
  - MIT
122
134
  metadata:
135
+ source_code_uri: https://github.com/szorfein/getch
123
136
  changelog_uri: https://github.com/szorfein/getch/blob/master/CHANGELOG.md
124
137
  bug_tracker_uri: https://github.com/szorfein/getch/issues
125
138
  wiki_uri: https://github.com/szorfein/getch
@@ -131,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
144
  requirements:
132
145
  - - ">="
133
146
  - !ruby/object:Gem::Version
134
- version: '2.5'
147
+ version: 2.5.0
135
148
  required_rubygems_version: !ruby/object:Gem::Requirement
136
149
  requirements:
137
150
  - - ">="