getch 0.0.2 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 551c234f0650bb73f209c06becaedefe429bb5c14b6c65debc49c4f4f60b86f7
4
- data.tar.gz: 5f1259b54738dfd0e43787a509c7c327888698c8af43be498bec0f86646ad0bf
3
+ metadata.gz: eb6075f7c63fb0a9b3d9cae63e24aae84cb3c90947985aa54ba48bc0dd284dcc
4
+ data.tar.gz: 26ad192fed5685f42e62d400706d6127c3d28a0fc5ce67296da6ef758955de25
5
5
  SHA512:
6
- metadata.gz: de7fcca94c7461638bdf0c9ef691d8299eb52b090394c605e819473dada25e2a15125ce67bd7bc3aca27276b6fad1d422634ffd34ee3f04e69d2975b88b632c2
7
- data.tar.gz: 3115a72e891651b61020c42c2ccf0cd3d1134192116df7c9bd9baad5b26d5e98db233ae63c8d627e7655f40b69336c35d355fc4d41a2aabc9525e8fbfffd00dc
6
+ metadata.gz: fe321ca0175f95f07c68026269830932609ba2fe5a1757efb7228bc26a069c4f5c322b21c534d05077c98a4dddfb0ed33bb2aa2fb30b1bc2df234e25b47acb56
7
+ data.tar.gz: 5b3540c9a1f07162bfbb3e4772f78c0b74b9525ec74fed7ce71c507da5f58befc85e6f8198abc595b49fa767abc77349f56b0ab9790d56730c45771365268fb0
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -0,0 +1,41 @@
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
+
6
+ ## 0.0.6, release 2020-09-19
7
+ * Add support for QEMU guest with KVM and Virtio driver
8
+ * Kernel compilation, initialize a config file with `make localyesconfig`.
9
+ * More modular codes to start with encryption and other filesystems.
10
+ * Add the new option --verbose to display output of compilation, etc...
11
+
12
+ ## 0.0.5, release 2020-09-17
13
+ * Generate a hostname
14
+ * Configure systemd-boot for UEFI system
15
+
16
+ ## 0.0.4, release 2020-09-16
17
+ * Boot on a BIOS system with VirtualBox
18
+ * Install Grub
19
+ * Create user
20
+ * Create passwd for root and user
21
+ * Check lsmod to install deps (like wpa_supplicant) and patch the kernel
22
+
23
+ ## 0.0.3, release 2020-09-14
24
+ * Add dhcpcd, gentoo-sources, linux-firmware
25
+ * Kernel build by using https://github.com/szorfein/garden
26
+ * Populate /etc/portage (/etc/portage/package.{use,unmask,accept_keywords}/zzz_via_autounmask)
27
+ * Download all the lastest ebuild via emerge-webrsync
28
+ * Update gentoo via emerge -uDN @world
29
+
30
+ ## 0.0.2, release 2020-09-12
31
+ * Getch genere a file /tmp/install_gentoo to avoid to remake same task over and over
32
+ * Support for ext4
33
+ * Mount partition on /mnt/gentoo during the install
34
+ * Download, verify the checksum and decompress the last stage3-amd64-systemd
35
+
36
+ ## 0.0.1, release 2020-09-10
37
+ * Partition disk (at least 15G required) with sgdisk (create /boot, /, /home, and swap)
38
+ * Support for one disk with -d|--disk
39
+ * Add few options for the CLI
40
+ * Add bin/setup.sh to install ruby when boot on a ISO file
41
+ * 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:
@@ -21,4 +33,11 @@ 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
+ ## Issues
41
+ 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:
42
+ + lspci
43
+ + lsmod
@@ -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,33 +1,47 @@
1
1
  require_relative 'getch/options'
2
- require_relative 'getch/disk'
3
2
  require_relative 'getch/states'
3
+ require_relative 'getch/gentoo'
4
+ require_relative 'getch/filesystem'
5
+ require_relative 'getch/command'
6
+ require_relative 'getch/helpers'
4
7
 
5
8
  module Getch
6
9
 
7
10
  DEFAULT_OPTIONS = {
8
11
  language: 'en_US',
9
- location: 'US/Eastern',
12
+ zoneinfo: 'US/Eastern',
10
13
  keyboard: 'us',
11
14
  disk: 'sda',
12
15
  fs: 'ext4',
13
- username: nil
16
+ username: nil,
17
+ encrypt: false,
18
+ verbose: false
14
19
  }
15
20
 
16
21
  STATES = {
17
22
  :partition => false,
18
23
  :format => false,
19
24
  :mount => false,
20
- :gentoo_base => false
25
+ :gentoo_base => false,
26
+ :gentoo_config => false,
27
+ :gentoo_update => false,
28
+ :gentoo_kernel => false
21
29
  }
22
30
 
31
+ MOUNTPOINT = "/mnt/gentoo".freeze
32
+ OPTIONS_FS = {
33
+ 'ext4' => DEFAULT_OPTIONS[:encrypt] ? Getch::FileSystem::Ext4::Encrypt : Getch::FileSystem::Ext4
34
+ }.freeze
35
+
23
36
  def self.resume_options(opts)
24
37
  puts "\nBuild Gentoo with the following args:\n"
25
- puts "lang: #{opts.language}"
26
- puts "zoneinfo: #{opts.zoneinfo}"
27
- puts "keyboard: #{opts.keyboard}"
28
- puts "disk: #{opts.disk}"
29
- puts "fs: #{opts.fs}"
30
- puts "username: #{opts.username}"
38
+ puts "lang: #{DEFAULT_OPTIONS[:language]}"
39
+ puts "zoneinfo: #{DEFAULT_OPTIONS[:zoneinfo]}"
40
+ puts "keyboard: #{DEFAULT_OPTIONS[:keyboard]}"
41
+ puts "disk: #{DEFAULT_OPTIONS[:disk]}"
42
+ puts "fs: #{DEFAULT_OPTIONS[:fs]}"
43
+ puts "username: #{DEFAULT_OPTIONS[:username]}"
44
+ puts "encrypt: #{DEFAULT_OPTIONS[:encrypt]}"
31
45
  puts
32
46
  print "Continue? (n,y) "
33
47
  case gets.chomp
@@ -38,25 +52,35 @@ module Getch
38
52
  end
39
53
  end
40
54
 
41
- def self.format(disk, fs)
55
+ def self.format(disk, fs, user)
42
56
  return if STATES[:format] and STATES[:partition]
43
57
  puts
44
58
  print "Partition and format disk #{disk}, this will erase all data, continue? (n,y) "
45
59
  case gets.chomp
46
60
  when /^y|^Y/
47
- disk = Getch::Disk.new(disk, fs)
48
- disk.cleaning
49
- disk.partition
50
- disk.format
61
+ OPTIONS_FS[fs]::Partition.new
62
+ OPTIONS_FS[fs]::Format.new
51
63
  else
52
64
  exit 1
53
65
  end
54
66
  end
55
67
 
68
+ def self.init_gentoo(options)
69
+ gentoo = Getch::Gentoo
70
+ gentoo.stage3
71
+ gentoo.config(options)
72
+ gentoo.chroot
73
+ gentoo.kernel
74
+ gentoo.boot(options)
75
+ end
76
+
56
77
  def self.main(argv)
57
- options = Options.new(DEFAULT_OPTIONS, argv)
78
+ options = Options.new(argv)
79
+ DEFAULT_OPTIONS.freeze
58
80
  resume_options(options)
59
- Getch::States.new() # Update States
60
- format(options.disk, options.fs)
81
+ Getch::States.new # Update States
82
+ format(options.disk, options.fs, options.username)
83
+ OPTIONS_FS[DEFAULT_OPTIONS[:fs]]::Mount.new.run
84
+ init_gentoo(options)
61
85
  end
62
86
  end
@@ -0,0 +1,55 @@
1
+ require 'open3'
2
+
3
+ module Getch
4
+ class Command
5
+ def initialize(cmd)
6
+ @cmd = cmd
7
+ @block_size = 512
8
+ end
9
+
10
+ def run!
11
+ puts "Running command: " + @cmd.gsub(/\"/, '')
12
+
13
+ Open3.popen3(@cmd) do |stdin, stdout, stderr|
14
+ stdin.close_write
15
+
16
+ begin
17
+ files = [stdout, stderr]
18
+
19
+ until all_eof(files) do
20
+ ready = IO.select(files)
21
+
22
+ if ready
23
+ readable = ready[0]
24
+ # writable = ready[1]
25
+ # exceptions = ready[2]
26
+
27
+ readable.each do |f|
28
+ fileno = f.fileno
29
+
30
+ begin
31
+ data = f.read_nonblock(@block_size)
32
+
33
+ # Do something with the data...
34
+ puts "#{data}" if DEFAULT_OPTIONS[:verbose]
35
+ rescue EOFError
36
+ puts "fileno: #{fileno} EOF"
37
+ end
38
+ end
39
+ end
40
+ end
41
+ rescue IOError => e
42
+ puts "IOError: #{e}"
43
+ end
44
+ end
45
+ puts "Done"
46
+ end
47
+
48
+ private
49
+
50
+ # Returns true if all files are EOF
51
+ def all_eof(files)
52
+ files.find { |f| !f.eof }.nil?
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,6 @@
1
+ module Getch
2
+ module FileSystem
3
+ end
4
+ end
5
+
6
+ require_relative 'filesystem/ext4'
@@ -0,0 +1,13 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Ext4
4
+ end
5
+ end
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