getch 0.0.3 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/CHANGELOG.md +46 -0
  5. data/README.md +25 -2
  6. data/bin/setup.sh +25 -11
  7. data/getch.gemspec +5 -0
  8. data/lib/getch.rb +32 -30
  9. data/lib/getch/command.rb +156 -0
  10. data/lib/getch/filesystem.rb +7 -0
  11. data/lib/getch/filesystem/ext4.rb +13 -0
  12. data/lib/getch/filesystem/ext4/config.rb +59 -0
  13. data/lib/getch/filesystem/ext4/deps.rb +22 -0
  14. data/lib/getch/filesystem/ext4/device.rb +16 -0
  15. data/lib/getch/filesystem/ext4/encrypt.rb +15 -0
  16. data/lib/getch/filesystem/ext4/encrypt/config.rb +62 -0
  17. data/lib/getch/filesystem/ext4/encrypt/deps.rb +37 -0
  18. data/lib/getch/filesystem/ext4/encrypt/device.rb +20 -0
  19. data/lib/getch/filesystem/ext4/encrypt/format.rb +26 -0
  20. data/lib/getch/filesystem/ext4/encrypt/mount.rb +64 -0
  21. data/lib/getch/filesystem/ext4/encrypt/partition.rb +95 -0
  22. data/lib/getch/filesystem/ext4/format.rb +30 -0
  23. data/lib/getch/filesystem/ext4/mount.rb +62 -0
  24. data/lib/getch/filesystem/ext4/partition.rb +75 -0
  25. data/lib/getch/filesystem/lvm.rb +13 -0
  26. data/lib/getch/filesystem/lvm/config.rb +62 -0
  27. data/lib/getch/filesystem/lvm/deps.rb +57 -0
  28. data/lib/getch/filesystem/lvm/device.rb +19 -0
  29. data/lib/getch/filesystem/lvm/format.rb +25 -0
  30. data/lib/getch/filesystem/lvm/mount.rb +62 -0
  31. data/lib/getch/filesystem/lvm/partition.rb +81 -0
  32. data/lib/getch/gentoo.rb +23 -1
  33. data/lib/getch/gentoo/boot.rb +94 -0
  34. data/lib/getch/gentoo/chroot.rb +39 -7
  35. data/lib/getch/gentoo/config.rb +17 -7
  36. data/lib/getch/gentoo/sources.rb +90 -0
  37. data/lib/getch/gentoo/stage.rb +2 -2
  38. data/lib/getch/helpers.rb +17 -0
  39. data/lib/getch/log.rb +54 -0
  40. data/lib/getch/options.rb +13 -4
  41. data/lib/getch/states.rb +5 -0
  42. data/lib/getch/version.rb +1 -1
  43. metadata +34 -6
  44. metadata.gz.sig +0 -0
  45. data/lib/getch/disk.rb +0 -77
  46. data/lib/getch/mount.rb +0 -43
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 769727fcda94cc7d18928f9ae8dc107756073179877b2b47fcc75c03f5483dc2
4
- data.tar.gz: 471c26161637a5d94ebd8c77708a4ae93bdfbc8f443ff1f120b60b4986f1f637
3
+ metadata.gz: 4d697434a5e8a44edb8027582ece052145c440247524597afe5ad28118115154
4
+ data.tar.gz: 42eb9e224e6581752f28d6997a9e10feb0e65c432e0dd80bc87236d7e597d828
5
5
  SHA512:
6
- metadata.gz: dbe1bc854c99ae26e7a8dd4d62325224b9949909bcde2bb389830183bc91878847148b3995e8b8928e0481e3fc86233b359989b758bf7a915254a18f5a66940c
7
- data.tar.gz: 3335a022ab70eecbae37c21026c3739751718f9dd38d4410137a15de26c32f8c7d0d7d658b609c29f03976233f54a33130971c7c9cff5291249c8a525e21e7a8
6
+ metadata.gz: 2e17128164b81b58d59f296e360197a2b9fbb33fd2b1cbd58128b1b04885eef4480d067c5588d40802c889e5a80861b63c37454b685bdb6263e9806b2e99b208
7
+ data.tar.gz: f8eee6f6b37fb036a05003d109672615cc7439dcc5277f2d4604d58e66b2407fa648bdccb850269545f2aef5441777a0d936842326cecb7410b05dfb6dbcee64
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -0,0 +1,46 @@
1
+ * Adding LVM via the option fs, `--fs lvm`.
2
+ * Systemd-boot use the value of PARTUUID without initramfs.
3
+ * Include lib logger.
4
+
5
+ ## 0.0.7, release 2020-09-22
6
+ * Correct fstab.
7
+ * Repair GRUB/fstab for BIOS system, add secure cmdline.
8
+ * Create a swap volume equal to the memory installed.
9
+ * Add vim and sudo
10
+
11
+ ## 0.0.6, release 2020-09-19
12
+ * Add support for QEMU guest with KVM and Virtio driver
13
+ * Kernel compilation, initialize a config file with `make localyesconfig`.
14
+ * More modular codes to start with encryption and other filesystems.
15
+ * Add the new option --verbose to display output of compilation, etc...
16
+
17
+ ## 0.0.5, release 2020-09-17
18
+ * Generate a hostname
19
+ * Configure systemd-boot for UEFI system
20
+
21
+ ## 0.0.4, release 2020-09-16
22
+ * Boot on a BIOS system with VirtualBox
23
+ * Install Grub
24
+ * Create user
25
+ * Create passwd for root and user
26
+ * Check lsmod to install deps (like wpa_supplicant) and patch the kernel
27
+
28
+ ## 0.0.3, release 2020-09-14
29
+ * Add dhcpcd, gentoo-sources, linux-firmware
30
+ * Kernel build by using https://github.com/szorfein/garden
31
+ * Populate /etc/portage (/etc/portage/package.{use,unmask,accept_keywords}/zzz_via_autounmask)
32
+ * Download all the lastest ebuild via emerge-webrsync
33
+ * Update gentoo via emerge -uDN @world
34
+
35
+ ## 0.0.2, release 2020-09-12
36
+ * Getch genere a file /tmp/install_gentoo to avoid to remake same task over and over
37
+ * Support for ext4
38
+ * Mount partition on /mnt/gentoo during the install
39
+ * Download, verify the checksum and decompress the last stage3-amd64-systemd
40
+
41
+ ## 0.0.1, release 2020-09-10
42
+ * Partition disk (at least 15G required) with sgdisk (create /boot, /, /home, and swap)
43
+ * Support for one disk with -d|--disk
44
+ * Add few options for the CLI
45
+ * Add bin/setup.sh to install ruby when boot on a ISO file
46
+ * Init project
data/README.md CHANGED
@@ -1,6 +1,18 @@
1
1
  # Getch
2
2
  A CLI tool to install Gentoo.
3
3
 
4
+ ## Description
5
+ Actually, Getch support only the [AMD64 handbook](https://wiki.gentoo.org/wiki/Handbook:AMD64) and only with the last `stage3-amd64-systemd`.
6
+ It also require a disk (only one for now) with a minimum of 20G.
7
+
8
+ Filesystem supported by Getch are: (the list will evolve...)
9
+ + ext4 with GRUB2 for BIOS based system and systemd-boot for UEFI systems.
10
+
11
+ I would also add disk encryption soon.
12
+
13
+ The ISO images i was able to test and that works:
14
+ + [Archlinux](https://www.archlinux.org/download/)
15
+
4
16
  ## Install
5
17
  Getch is cryptographically signed, so add my public key (if you haven’t already) as a trusted certificate.
6
18
  With `gem` installed:
@@ -11,7 +23,7 @@ With `gem` installed:
11
23
 
12
24
  When you boot from an `iso`, you can install `ruby`, `getch` and correct your `PATH=` directly with the `bin/setup.sh`:
13
25
 
14
- # curl https://raw.githubusercontent.com/szorfein/getch/master/bin/setup.sh | sh
26
+ # sh <(curl -L https://raw.githubusercontent.com/szorfein/getch/master/bin/setup.sh)
15
27
  # source ~/.zshrc # or ~/.bashrc
16
28
 
17
29
  ## Usage
@@ -21,4 +33,15 @@ When you boot from an `iso`, you can install `ruby`, `getch` and correct your `P
21
33
  ## Examples
22
34
  For a french user:
23
35
 
24
- # getch --username ninja --zoneinfo Europe/Paris --language fr_FR --keyboard fr
36
+ # getch --username ninja --zoneinfo "Europe/Paris" --language fr_FR --keyboard fr
37
+
38
+ After an install by Getch, take a look on the [wiki](https://github.com/szorfein/getch/wiki).
39
+
40
+ Install Gentoo on LVM:
41
+
42
+ # getch --format lvm --disk sda
43
+
44
+ ## Issues
45
+ If need more support for your hardware (network, sound card, ...), you can submit a [new issue](https://github.com/szorfein/getch/issues/new) and post the output of the following command:
46
+ + lspci
47
+ + lsmod
@@ -26,7 +26,7 @@ search_ruby() {
26
26
  else
27
27
  echo "Install ruby"
28
28
  if hash pacman 2>/dev/null ; then
29
- pacman -Syy libyaml ruby ruby-irb ruby-reline rubygems
29
+ pacman -Syy --noconfirm libyaml ruby ruby-irb ruby-reline rubygems
30
30
  elif hash emerge 2>/dev/null ; then
31
31
  emerge -av dev-lang/ruby
32
32
  elif hash apt-get 2>/dev/null ; then
@@ -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
- gem install getch
43
- getch -h
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
- cd /tmp
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
 
@@ -7,6 +7,11 @@ Gem::Specification.new do |s|
7
7
  s.authors = ["szorfein"]
8
8
  s.email = ["szorfein@protonmail.com"]
9
9
  s.homepage = 'https://github.com/szorfein/getch'
10
+ s.metadata = {
11
+ "changelog_uri" => "https://github.com/szorfein/getch/blob/master/CHANGELOG.md",
12
+ "bug_tracker_uri" => "https://github.com/szorfein/getch/issues",
13
+ "wiki_uri" => "https://github.com/szorfein/getch"
14
+ }
10
15
  s.license = "MIT"
11
16
  s.required_ruby_version = '>=2.5'
12
17
 
@@ -1,20 +1,23 @@
1
1
  require_relative 'getch/options'
2
- require_relative 'getch/disk'
3
2
  require_relative 'getch/states'
4
- require_relative 'getch/mount'
5
3
  require_relative 'getch/gentoo'
4
+ require_relative 'getch/filesystem'
5
+ require_relative 'getch/command'
6
6
  require_relative 'getch/helpers'
7
+ require_relative 'getch/log'
7
8
 
8
9
  module Getch
9
10
 
10
11
  DEFAULT_OPTIONS = {
11
12
  language: 'en_US',
12
- location: 'US/Eastern',
13
+ zoneinfo: 'US/Eastern',
13
14
  keyboard: 'us',
14
15
  disk: 'sda',
15
16
  fs: 'ext4',
16
- username: nil
17
- }.freeze
17
+ username: nil,
18
+ encrypt: false,
19
+ verbose: false
20
+ }
18
21
 
19
22
  STATES = {
20
23
  :partition => false,
@@ -22,20 +25,25 @@ module Getch
22
25
  :mount => false,
23
26
  :gentoo_base => false,
24
27
  :gentoo_config => false,
25
- :gentoo_update => false
28
+ :gentoo_update => false,
29
+ :gentoo_kernel => false
26
30
  }
27
31
 
28
32
  MOUNTPOINT = "/mnt/gentoo".freeze
29
- #MOUNTPOINT = "/home/daggoth/lol".freeze
33
+ OPTIONS_FS = {
34
+ 'ext4' => DEFAULT_OPTIONS[:encrypt] ? Getch::FileSystem::Ext4::Encrypt : Getch::FileSystem::Ext4,
35
+ 'lvm' => DEFAULT_OPTIONS[:encrypt] ? Getch::FileSystem::Lvm::Encrypt : Getch::FileSystem::Lvm
36
+ }.freeze
30
37
 
31
38
  def self.resume_options(opts)
32
39
  puts "\nBuild Gentoo with the following args:\n"
33
- puts "lang: #{opts.language}"
34
- puts "zoneinfo: #{opts.zoneinfo}"
35
- puts "keyboard: #{opts.keyboard}"
36
- puts "disk: #{opts.disk}"
37
- puts "fs: #{opts.fs}"
38
- puts "username: #{opts.username}"
40
+ puts "lang: #{DEFAULT_OPTIONS[:language]}"
41
+ puts "zoneinfo: #{DEFAULT_OPTIONS[:zoneinfo]}"
42
+ puts "keyboard: #{DEFAULT_OPTIONS[:keyboard]}"
43
+ puts "disk: #{DEFAULT_OPTIONS[:disk]}"
44
+ puts "fs: #{DEFAULT_OPTIONS[:fs]}"
45
+ puts "username: #{DEFAULT_OPTIONS[:username]}"
46
+ puts "encrypt: #{DEFAULT_OPTIONS[:encrypt]}"
39
47
  puts
40
48
  print "Continue? (n,y) "
41
49
  case gets.chomp
@@ -46,43 +54,37 @@ module Getch
46
54
  end
47
55
  end
48
56
 
49
- def self.format(disk, fs)
57
+ def self.format(disk, fs, user)
50
58
  return if STATES[:format] and STATES[:partition]
59
+ log = Log.new
51
60
  puts
52
61
  print "Partition and format disk #{disk}, this will erase all data, continue? (n,y) "
53
62
  case gets.chomp
54
63
  when /^y|^Y/
55
- disk = Getch::Disk.new(disk, fs)
56
- disk.cleaning
57
- disk.partition
58
- disk.format
64
+ log.info("Partition start")
65
+ OPTIONS_FS[fs]::Partition.new
66
+ OPTIONS_FS[fs]::Format.new
59
67
  else
60
68
  exit 1
61
69
  end
62
70
  end
63
71
 
64
- def self.mount(disk, user)
65
- return if STATES[:mount]
66
- mount = Getch::Mount.new(disk, user)
67
- mount.swap
68
- mount.root
69
- mount.boot
70
- mount.home
71
- end
72
-
73
72
  def self.init_gentoo(options)
74
73
  gentoo = Getch::Gentoo
75
74
  gentoo.stage3
76
75
  gentoo.config(options)
77
76
  gentoo.chroot
77
+ gentoo.kernel
78
+ gentoo.boot(options)
78
79
  end
79
80
 
80
81
  def self.main(argv)
81
82
  options = Options.new(argv)
83
+ DEFAULT_OPTIONS.freeze
82
84
  resume_options(options)
83
- Getch::States.new() # Update States
84
- format(options.disk, options.fs)
85
- mount(options.disk, options.username)
85
+ Getch::States.new # Update States
86
+ format(options.disk, options.fs, options.username)
87
+ OPTIONS_FS[DEFAULT_OPTIONS[:fs]]::Mount.new.run
86
88
  init_gentoo(options)
87
89
  end
88
90
  end
@@ -0,0 +1,156 @@
1
+ require 'open3'
2
+
3
+ module Getch
4
+ class Command
5
+ def initialize(cmd)
6
+ @cmd = cmd
7
+ @block_size = 1024
8
+ @log = Getch::Log.new
9
+ end
10
+
11
+ def run!
12
+ @log.info "Running command: " + @cmd.gsub(/\"/, '')
13
+
14
+ Open3.popen3(@cmd) do |stdin, stdout, stderr, wait_thr|
15
+ stdin.close_write
16
+ code = wait_thr.value
17
+
18
+ # only stderr
19
+ begin
20
+ @log.error stderr.readline until stderr.eof.nil?
21
+ rescue EOFError
22
+ end
23
+
24
+ begin
25
+ files = [stdout, stderr]
26
+
27
+ until all_eof(files) do
28
+ ready = IO.select(files)
29
+
30
+ if ready
31
+ readable = ready[0]
32
+ # writable = ready[1]
33
+ # exceptions = ready[2]
34
+
35
+ display_lines(readable)
36
+ end
37
+ end
38
+ rescue IOError => e
39
+ puts "IOError: #{e}"
40
+ end
41
+
42
+ unless code.success?
43
+ @log.fatal "Running #{@cmd}"
44
+ exit 1
45
+ end
46
+
47
+ @log.debug "Done - #{@cmd} - #{code}"
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ # Returns true if all files are EOF
54
+ def all_eof(files)
55
+ files.find { |f| !f.eof }.nil?
56
+ end
57
+
58
+ def display_lines(block)
59
+ block.each do |f|
60
+ begin
61
+ data = f.read_nonblock(@block_size)
62
+ puts data if DEFAULT_OPTIONS[:verbose]
63
+ rescue EOFError
64
+ puts ""
65
+ rescue => e
66
+ puts "Fatal - #{e}"
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ # Use system, the only ruby method to display stdout with colors !
73
+ class Emerge
74
+ def initialize(cmd)
75
+ @gentoo = MOUNTPOINT
76
+ @cmd = cmd
77
+ @log = Getch::Log.new
78
+ end
79
+
80
+ def run!
81
+ @log.info "Running emerge: #{@cmd}"
82
+ system("chroot", @gentoo, "/bin/bash", "-c", "source /etc/profile && #{@cmd}")
83
+ read_exit
84
+ end
85
+
86
+ def pkg!
87
+ @log.info "Running emerge pkg: #{@cmd}"
88
+ system("chroot", @gentoo, "/bin/bash", "-c", "source /etc/profile && emerge --changed-use #{@cmd}")
89
+ read_exit
90
+ end
91
+
92
+ private
93
+
94
+ def read_exit
95
+ if $?.exitstatus > 0
96
+ @log.fatal "Running #{@cmd}"
97
+ else
98
+ @log.info "Done #{@cmd}"
99
+ end
100
+ end
101
+ end
102
+
103
+ class Make
104
+ def initialize(cmd)
105
+ @gentoo = MOUNTPOINT
106
+ @cmd = cmd
107
+ @log = Getch::Log.new
108
+ end
109
+
110
+ def run!
111
+ @log.info "Running Make: #{@cmd}"
112
+ cmd = "chroot #{@gentoo} /bin/bash -c \"source /etc/profile \
113
+ && env-update \
114
+ && cd /usr/src/linux \
115
+ && #{@cmd}\""
116
+ Open3.popen2e(cmd) do |stdin, stdout_err, wait_thr|
117
+ while line = stdout_err.gets
118
+ puts line
119
+ end
120
+
121
+ exit_status = wait_thr.value
122
+ unless exit_status.success?
123
+ @log.fatal "Running #{cmd}"
124
+ exit 1
125
+ end
126
+ end
127
+ end
128
+ end
129
+
130
+ class Garden
131
+ def initialize(cmd)
132
+ @gentoo = MOUNTPOINT
133
+ @cmd = cmd
134
+ @log = Getch::Log.new
135
+ end
136
+
137
+ def run!
138
+ @log.info "Running Garden: #{@cmd}"
139
+ cmd = "chroot #{@gentoo} /bin/bash -c \"source /etc/profile \
140
+ && env-update \
141
+ && cd /root/garden-master \
142
+ && ./kernel.sh #{@cmd} -k /usr/src/linux\""
143
+ Open3.popen2e(cmd) do |stdin, stdout_err, wait_thr|
144
+ while line = stdout_err.gets
145
+ puts line
146
+ end
147
+
148
+ exit_status = wait_thr.value
149
+ unless exit_status.success?
150
+ @log.fatal "Running #{cmd}"
151
+ exit 1
152
+ end
153
+ end
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,7 @@
1
+ module Getch
2
+ module FileSystem
3
+ end
4
+ end
5
+
6
+ require_relative 'filesystem/ext4'
7
+ require_relative 'filesystem/lvm'