getch 0.0.4 → 0.0.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 (51) 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 +40 -5
  5. data/README.md +31 -2
  6. data/bin/setup.sh +25 -11
  7. data/lib/getch.rb +41 -30
  8. data/lib/getch/command.rb +156 -0
  9. data/lib/getch/filesystem.rb +7 -0
  10. data/lib/getch/filesystem/ext4.rb +14 -0
  11. data/lib/getch/filesystem/ext4/config.rb +59 -0
  12. data/lib/getch/filesystem/ext4/deps.rb +22 -0
  13. data/lib/getch/filesystem/ext4/device.rb +16 -0
  14. data/lib/getch/filesystem/ext4/encrypt.rb +15 -0
  15. data/lib/getch/filesystem/ext4/encrypt/config.rb +85 -0
  16. data/lib/getch/filesystem/ext4/encrypt/deps.rb +59 -0
  17. data/lib/getch/filesystem/ext4/encrypt/device.rb +21 -0
  18. data/lib/getch/filesystem/ext4/encrypt/format.rb +32 -0
  19. data/lib/getch/filesystem/ext4/encrypt/mount.rb +64 -0
  20. data/lib/getch/filesystem/ext4/encrypt/partition.rb +116 -0
  21. data/lib/getch/filesystem/ext4/format.rb +30 -0
  22. data/lib/getch/filesystem/ext4/mount.rb +62 -0
  23. data/lib/getch/filesystem/ext4/partition.rb +75 -0
  24. data/lib/getch/filesystem/lvm.rb +14 -0
  25. data/lib/getch/filesystem/lvm/config.rb +63 -0
  26. data/lib/getch/filesystem/lvm/deps.rb +57 -0
  27. data/lib/getch/filesystem/lvm/device.rb +19 -0
  28. data/lib/getch/filesystem/lvm/encrypt.rb +15 -0
  29. data/lib/getch/filesystem/lvm/encrypt/config.rb +74 -0
  30. data/lib/getch/filesystem/lvm/encrypt/deps.rb +63 -0
  31. data/lib/getch/filesystem/lvm/encrypt/device.rb +22 -0
  32. data/lib/getch/filesystem/lvm/encrypt/format.rb +32 -0
  33. data/lib/getch/filesystem/lvm/encrypt/mount.rb +64 -0
  34. data/lib/getch/filesystem/lvm/encrypt/partition.rb +92 -0
  35. data/lib/getch/filesystem/lvm/format.rb +25 -0
  36. data/lib/getch/filesystem/lvm/mount.rb +62 -0
  37. data/lib/getch/filesystem/lvm/partition.rb +81 -0
  38. data/lib/getch/gentoo.rb +4 -2
  39. data/lib/getch/gentoo/boot.rb +46 -11
  40. data/lib/getch/gentoo/chroot.rb +18 -14
  41. data/lib/getch/gentoo/config.rb +24 -9
  42. data/lib/getch/gentoo/sources.rb +54 -29
  43. data/lib/getch/gentoo/stage.rb +2 -2
  44. data/lib/getch/helpers.rb +28 -1
  45. data/lib/getch/log.rb +54 -0
  46. data/lib/getch/options.rb +16 -7
  47. data/lib/getch/version.rb +1 -1
  48. metadata +34 -5
  49. metadata.gz.sig +3 -4
  50. data/lib/getch/disk.rb +0 -77
  51. data/lib/getch/mount.rb +0 -73
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cee5eb8b60c64dd64bd0416ae0306f725b1fd58f58baec8288e6358c9ff79a8a
4
- data.tar.gz: 315db3e29828388088d8cda3c38e5bd7ed5c57d3b9ecb324150c06e47ebd1eba
3
+ metadata.gz: 05f332c1aa466828838d7968874705953bba34c2179426f4931a355d5c13963c
4
+ data.tar.gz: 47fa91c9b9086013db895772f4faece39afe9f4377ad96a53c4b6aee3822f79b
5
5
  SHA512:
6
- metadata.gz: 622547ffd01a03d7a957f489014ae0c27255e868c9135326b4bd8a3e0671dca6319f9f593f3fc33f54f657089cfa5e65a8917a2e6c7201ade89682a5767a3e96
7
- data.tar.gz: bed494285e0ec32397e37aaed1d3836fe700fe11b4c0661f1e7b68039393a2356b1ec6f16207c29988e7ff9656d573833cd5e74ecf91ee1f143639e798cea442
6
+ metadata.gz: 0450bc2fbc6e7b3835802dae660ee878da6890bb2181826057442d3de3c580ff0d68d1348ca1d395c0820ce8d9fa5770fdaaee384e67b2619c0fc37c72190f28
7
+ data.tar.gz: 961a9019de0dc20e67da6042c2c61d2052cff31299f07c796fec71cb1b9a84e3db92cb1df276a5dd8de896faed53c967871e2d959fc3a317a7d2eccb9ba1622c
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,18 +1,53 @@
1
+ ## 0.0.9, release 2020-10-03
2
+ * Add encryption on ext4 and lvm (BIOS,UEFI)
3
+ * Correct KEYMAP="yes" with genkernel
4
+ * Renaming option keyboard with keymap
5
+ * GPG verification for ebuild
6
+
7
+ ## 0.0.8, release 2020-09-30
8
+ * Adding LVM via the option fs, `--fs lvm`.
9
+ * Systemd-boot use the value of PARTUUID without initramfs.
10
+ * Include lib logger.
11
+ * Enhance functions to call program system Emerge, Make, ...
12
+
13
+ ## 0.0.7, release 2020-09-22
14
+ * Correct fstab.
15
+ * Repair GRUB/fstab for BIOS system, add secure cmdline.
16
+ * Create a swap volume equal to the memory installed.
17
+ * Add vim and sudo
18
+
19
+ ## 0.0.6, release 2020-09-19
20
+ * Add support for QEMU guest with KVM and Virtio driver
21
+ * Kernel compilation, initialize a config file with `make localyesconfig`.
22
+ * More modular codes to start with encryption and other filesystems.
23
+ * Add the new option --verbose to display output of compilation, etc...
24
+
25
+ ## 0.0.5, release 2020-09-17
26
+ * Generate a hostname
27
+ * Configure systemd-boot for UEFI system
28
+
29
+ ## 0.0.4, release 2020-09-16
30
+ * Boot on a BIOS system with VirtualBox
31
+ * Install Grub
32
+ * Create user
33
+ * Create passwd for root and user
34
+ * Check lsmod to install deps (like wpa_supplicant) and patch the kernel
35
+
1
36
  ## 0.0.3, release 2020-09-14
2
- * Add commands in the chroot
37
+ * Add dhcpcd, gentoo-sources, linux-firmware
3
38
  * Kernel build by using https://github.com/szorfein/garden
4
- * Add portage fs (like /etc/portage/package.use/zzz_via_autounmask)
5
- * Download all the lastest ebuild
39
+ * Populate /etc/portage (/etc/portage/package.{use,unmask,accept_keywords}/zzz_via_autounmask)
40
+ * Download all the lastest ebuild via emerge-webrsync
6
41
  * Update gentoo via emerge -uDN @world
7
42
 
8
43
  ## 0.0.2, release 2020-09-12
9
44
  * Getch genere a file /tmp/install_gentoo to avoid to remake same task over and over
10
- * Support for fs ext4
45
+ * Support for ext4
11
46
  * Mount partition on /mnt/gentoo during the install
12
47
  * Download, verify the checksum and decompress the last stage3-amd64-systemd
13
48
 
14
49
  ## 0.0.1, release 2020-09-10
15
- * Format disk with sgdisk (should be installed)
50
+ * Partition disk (at least 15G required) with sgdisk (create /boot, /, /home, and swap)
16
51
  * Support for one disk with -d|--disk
17
52
  * Add few options for the CLI
18
53
  * Add bin/setup.sh to install ruby when boot on a ISO file
data/README.md CHANGED
@@ -1,6 +1,19 @@
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
+ BIOS system will use Grub2 and UEFI, systemd-boot. Filesystem supported by Getch are for now:
9
+ + ext4
10
+ + lvm
11
+
12
+ I would also add disk encryption soon.
13
+
14
+ The ISO images i was able to test and that works:
15
+ + [Archlinux](https://www.archlinux.org/download/)
16
+
4
17
  ## Install
5
18
  Getch is cryptographically signed, so add my public key (if you haven’t already) as a trusted certificate.
6
19
  With `gem` installed:
@@ -11,7 +24,7 @@ With `gem` installed:
11
24
 
12
25
  When you boot from an `iso`, you can install `ruby`, `getch` and correct your `PATH=` directly with the `bin/setup.sh`:
13
26
 
14
- # curl https://raw.githubusercontent.com/szorfein/getch/master/bin/setup.sh | sh
27
+ # sh <(curl -L https://raw.githubusercontent.com/szorfein/getch/master/bin/setup.sh)
15
28
  # source ~/.zshrc # or ~/.bashrc
16
29
 
17
30
  ## Usage
@@ -21,4 +34,20 @@ When you boot from an `iso`, you can install `ruby`, `getch` and correct your `P
21
34
  ## Examples
22
35
  For a french user:
23
36
 
24
- # getch --username ninja --zoneinfo "Europe/Paris" --language fr_FR --keyboard fr
37
+ # getch --username ninja --zoneinfo "Europe/Paris" --language fr_FR --keymap fr
38
+
39
+ After an install by Getch, take a look on the [wiki](https://github.com/szorfein/getch/wiki).
40
+
41
+ Install Gentoo on LVM:
42
+
43
+ # getch --format lvm --disk sda
44
+
45
+ ## Troubleshooting
46
+
47
+ #### LVM
48
+ Unless than your older LVM volume group is named `vg0`, `getch` may fail to partition your disk, you have to clean your device before proceed with `vgremove` and `pvremove`.
49
+
50
+ ## Issues
51
+ 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:
52
+ + lspci
53
+ + 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
 
@@ -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
- keyboard: 'us',
13
+ zoneinfo: 'US/Eastern',
14
+ keymap: '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,
@@ -27,16 +30,32 @@ module Getch
27
30
  }
28
31
 
29
32
  MOUNTPOINT = "/mnt/gentoo".freeze
30
- #MOUNTPOINT = "/home/daggoth/lol".freeze
33
+ DEFAULT_FS = {
34
+ true => {
35
+ ext4: Getch::FileSystem::Ext4::Encrypt,
36
+ lvm: Getch::FileSystem::Lvm::Encrypt
37
+ },
38
+ false => {
39
+ ext4: Getch::FileSystem::Ext4,
40
+ lvm: Getch::FileSystem::Lvm
41
+ }
42
+ }.freeze
43
+
44
+ def self.class_fs
45
+ encrypt = DEFAULT_OPTIONS[:encrypt]
46
+ fs = DEFAULT_OPTIONS[:fs].to_sym
47
+ DEFAULT_FS[encrypt][fs]
48
+ end
31
49
 
32
50
  def self.resume_options(opts)
33
51
  puts "\nBuild Gentoo with the following args:\n"
34
- puts "lang: #{opts.language}"
35
- puts "zoneinfo: #{opts.zoneinfo}"
36
- puts "keyboard: #{opts.keyboard}"
37
- puts "disk: #{opts.disk}"
38
- puts "fs: #{opts.fs}"
39
- puts "username: #{opts.username}"
52
+ puts "lang: #{DEFAULT_OPTIONS[:language]}"
53
+ puts "zoneinfo: #{DEFAULT_OPTIONS[:zoneinfo]}"
54
+ puts "keymap: #{DEFAULT_OPTIONS[:keymap]}"
55
+ puts "disk: #{DEFAULT_OPTIONS[:disk]}"
56
+ puts "fs: #{DEFAULT_OPTIONS[:fs]}"
57
+ puts "username: #{DEFAULT_OPTIONS[:username]}"
58
+ puts "encrypt: #{DEFAULT_OPTIONS[:encrypt]}"
40
59
  puts
41
60
  print "Continue? (n,y) "
42
61
  case gets.chomp
@@ -47,30 +66,21 @@ module Getch
47
66
  end
48
67
  end
49
68
 
50
- def self.format(disk, fs)
69
+ def self.format(disk, fs, user)
51
70
  return if STATES[:format] and STATES[:partition]
71
+ log = Log.new
52
72
  puts
53
73
  print "Partition and format disk #{disk}, this will erase all data, continue? (n,y) "
54
74
  case gets.chomp
55
75
  when /^y|^Y/
56
- disk = Getch::Disk.new(disk, fs)
57
- disk.cleaning
58
- disk.partition
59
- disk.format
76
+ log.info("Partition start")
77
+ class_fs::Partition.new
78
+ class_fs::Format.new
60
79
  else
61
80
  exit 1
62
81
  end
63
82
  end
64
83
 
65
- def self.mount(disk, user)
66
- return if STATES[:mount]
67
- mount = Getch::Mount.new(disk, user)
68
- mount.swap
69
- mount.root
70
- mount.boot
71
- mount.home
72
- end
73
-
74
84
  def self.init_gentoo(options)
75
85
  gentoo = Getch::Gentoo
76
86
  gentoo.stage3
@@ -82,10 +92,11 @@ module Getch
82
92
 
83
93
  def self.main(argv)
84
94
  options = Options.new(argv)
95
+ DEFAULT_OPTIONS.freeze
85
96
  resume_options(options)
86
- Getch::States.new() # Update States
87
- format(options.disk, options.fs)
88
- mount(options.disk, options.username)
97
+ Getch::States.new # Update States
98
+ format(options.disk, options.fs, options.username)
99
+ class_fs::Mount.new.run
89
100
  init_gentoo(options)
90
101
  end
91
102
  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.debug 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