getch 0.0.1 → 0.0.6

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: ab4a85424380fa152f9d5e764799ab85f44c2bcc09a74f0e8d8ba80278f7b880
4
- data.tar.gz: 586e590f3a66d81382193c4e1d0c8735165c39b6d4ef6eed8846aa620fd03a8b
3
+ metadata.gz: 87ae271211f6081929b72327651ff6e4f18adeca452cf10294d75a114f26db38
4
+ data.tar.gz: eb0ea1a935578351133e4c13dd0ee7e13d1696d6fbcc58bbd441e59d1cacf7de
5
5
  SHA512:
6
- metadata.gz: 2262f40341744f5d9128ae1372c48c3f1d762054cc600ca202f406e8b6d4c4d2912be157d0af08f61bc039b894e7c3825ff87a7a8ef2070e2411eb21f747aba0
7
- data.tar.gz: 854f785d9cee4e03b1e724881483ae3f9f69388ee0079dcf1c2ed057eb0b98d81236948b170fe6cc1b985f991f8ac13316c48417a943f68f67c3a20a9c9dbbaf
6
+ metadata.gz: b32454448824fef83fab42ac34534125b0dc6d0655235f271c97b644105dba75eebf0ca56b1c32e6a8cab019fa638d4e9fc44f20744cafd7ca584a94e05a0f4d
7
+ data.tar.gz: 809fc8dd380821f9bc479b4efee45f7f83cafc3a0a14a441881a3abd1daaeb0da84b20a2f2ff0af9bdee31cc1f247a21a873ef2729144ec2483aec8f165b6adf
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ *.swp
@@ -0,0 +1,36 @@
1
+ ## 0.0.6, release 2020-09-19
2
+ * Add support for QEMU guest #2
3
+ * Kernel compilation, initialize a config file with `make localyesconfig`.
4
+ * More modular codes to start with encryption and other filesystems.
5
+ * Add the new option --verbose to display output of compilation, etc... #2
6
+
7
+ ## 0.0.5, release 2020-09-17
8
+ * Generate a hostname
9
+ * Configure systemd-boot for UEFI system
10
+
11
+ ## 0.0.4, release 2020-09-16
12
+ * Boot on a BIOS system with VirtualBox
13
+ * Install Grub
14
+ * Create user
15
+ * Create passwd for root and user
16
+ * Check lsmod to install deps (like wpa_supplicant) and patch the kernel
17
+
18
+ ## 0.0.3, release 2020-09-14
19
+ * Add dhcpcd, gentoo-sources, linux-firmware
20
+ * Kernel build by using https://github.com/szorfein/garden
21
+ * Populate /etc/portage (/etc/portage/package.{use,unmask,accept_keywords}/zzz_via_autounmask)
22
+ * Download all the lastest ebuild via emerge-webrsync
23
+ * Update gentoo via emerge -uDN @world
24
+
25
+ ## 0.0.2, release 2020-09-12
26
+ * Getch genere a file /tmp/install_gentoo to avoid to remake same task over and over
27
+ * Support for ext4
28
+ * Mount partition on /mnt/gentoo during the install
29
+ * Download, verify the checksum and decompress the last stage3-amd64-systemd
30
+
31
+ ## 0.0.1, release 2020-09-10
32
+ * Partition disk (at least 15G required) with sgdisk (create /boot, /, /home, and swap)
33
+ * Support for one disk with -d|--disk
34
+ * Add few options for the CLI
35
+ * Add bin/setup.sh to install ruby when boot on a ISO file
36
+ * Init project
data/README.md CHANGED
@@ -1,6 +1,43 @@
1
1
  # Getch
2
- A script to install Gentoo.
2
+ A CLI tool to install Gentoo.
3
3
 
4
- # Install
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
+
16
+ ## Install
17
+ Getch is cryptographically signed, so add my public key (if you haven’t already) as a trusted certificate.
18
+ With `gem` installed:
19
+
20
+ $ gem cert --add <(curl -Ls https://raw.githubusercontent.com/szorfein/getch/master/certs/szorfein.pem)
21
+
22
+ $ gem install getch -P HighSecurity
23
+
24
+ When you boot from an `iso`, you can install `ruby`, `getch` and correct your `PATH=` directly with the `bin/setup.sh`:
5
25
 
6
26
  # curl https://raw.githubusercontent.com/szorfein/getch/master/bin/setup.sh | sh
27
+ # source ~/.zshrc # or ~/.bashrc
28
+
29
+ ## Usage
30
+
31
+ $ getch -h
32
+
33
+ ## Examples
34
+ For a french user:
35
+
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
@@ -0,0 +1,21 @@
1
+ # https://github.com/seattlerb/minitest#running-your-tests-
2
+ require "rake/testtask"
3
+ require File.dirname(__FILE__) + "/lib/getch/version"
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << "test"
7
+ t.libs << "lib"
8
+ t.test_files = FileList["test/test_*.rb"]
9
+ end
10
+
11
+ # Usage: rake gem:build
12
+ namespace :gem do
13
+ desc "build the gem"
14
+ task :build do
15
+ Dir["getch*.gem"].each {|f| File.unlink(f) }
16
+ system("gem build getch.gemspec")
17
+ system("gem install getch-#{Getch::VERSION}.gem -P HighSecurity")
18
+ end
19
+ end
20
+
21
+ task :default => :test
data/bin/getch CHANGED
@@ -2,4 +2,8 @@
2
2
 
3
3
  require 'getch'
4
4
 
5
- Getch::main(ARGV)
5
+ def main(argv)
6
+ Getch::main(argv)
7
+ end
8
+
9
+ main(ARGV)
@@ -26,8 +26,7 @@ search_ruby() {
26
26
  else
27
27
  echo "Install ruby"
28
28
  if hash pacman 2>/dev/null ; then
29
- pacman -Syy
30
- pacman -S --needed ruby
29
+ pacman -Syy libyaml ruby ruby-irb ruby-reline rubygems
31
30
  elif hash emerge 2>/dev/null ; then
32
31
  emerge -av dev-lang/ruby
33
32
  elif hash apt-get 2>/dev/null ; then
@@ -39,19 +38,37 @@ search_ruby() {
39
38
  }
40
39
 
41
40
  get_getch() {
42
- cd /tmp
43
- [ -f ./getch.tar.gz ] && rm ./getch.tar.gz
44
- [ -d ./getch-master ] && rm -rf ./getch-master
41
+ if hash gem 2>/dev/null ; then
42
+ gem install getch
43
+ getch -h
44
+ 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
53
+ fi
54
+ }
45
55
 
46
- curl -s -L -o getch.tar.gz https://github.com/szorfein/getch/archive/master.tar.gz
47
- tar xzf getch.tar.gz
56
+ set_shell() {
57
+ your_shell=~/.bashrc
58
+ [ -f ~/.zshrc ] && your_shell=~/.zshrc
59
+
60
+ [ -f "$your_shell" ] && {
61
+ if ! grep -q ".gem/ruby/[0-9.]*/bin" "$your_shell" ; then
62
+ echo "export PATH=\$PATH:$(ruby -e 'puts Gem.user_dir')/bin" >> "$your_shell"
63
+ fi
64
+ . "$your_shell"
65
+ }
48
66
  }
49
67
 
50
68
  main() {
51
- get_getch
52
69
  search_ruby
53
- cd $DIR \
54
- && ruby -I lib bin/getch
70
+ set_shell
71
+ get_getch
55
72
  }
56
73
 
57
74
  main "$@"
@@ -3,10 +3,15 @@ require File.dirname(__FILE__) + "/lib/getch/version"
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "getch"
5
5
  s.version = Getch::VERSION
6
- s.summary = "A script to install Gentoo"
6
+ s.summary = "A CLI tool to install Gentoo"
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
 
@@ -15,7 +20,6 @@ Gem::Specification.new do |s|
15
20
 
16
21
  s.executables = [ 'getch' ]
17
22
 
18
-
19
23
  s.cert_chain = ['certs/szorfein.pem']
20
24
  s.signing_key = File.expand_path("~/.ssh/gem-private_key.pem") if $0 =~ /gem\z/
21
25
  end
@@ -1,5 +1,87 @@
1
+ require_relative 'getch/options'
2
+ require_relative 'getch/states'
3
+ require_relative 'getch/mount'
4
+ require_relative 'getch/gentoo'
5
+ require_relative 'getch/filesystem'
6
+ require_relative 'getch/command'
7
+ require_relative 'getch/helpers'
8
+
1
9
  module Getch
10
+
11
+ DEFAULT_OPTIONS = {
12
+ language: 'en_US',
13
+ zoneinfo: 'US/Eastern',
14
+ keyboard: 'us',
15
+ disk: 'sda',
16
+ fs: 'ext4',
17
+ username: nil,
18
+ verbose: false
19
+ }
20
+
21
+ STATES = {
22
+ :partition => false,
23
+ :format => false,
24
+ :mount => false,
25
+ :gentoo_base => false,
26
+ :gentoo_config => false,
27
+ :gentoo_update => false,
28
+ :gentoo_kernel => false
29
+ }
30
+
31
+ MOUNTPOINT = "/mnt/gentoo".freeze
32
+ OPTIONS_FS = {
33
+ 'ext4' => Getch::FileSystem::Ext4
34
+ }.freeze
35
+
36
+ def self.resume_options(opts)
37
+ puts "\nBuild Gentoo with the following args:\n"
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
45
+ print "Continue? (n,y) "
46
+ case gets.chomp
47
+ when /^y|^Y/
48
+ return
49
+ else
50
+ exit 1
51
+ end
52
+ end
53
+
54
+ def self.format(disk, fs, user)
55
+ return if STATES[:format] and STATES[:partition]
56
+ puts
57
+ print "Partition and format disk #{disk}, this will erase all data, continue? (n,y) "
58
+ case gets.chomp
59
+ when /^y|^Y/
60
+ filesystem = OPTIONS_FS[fs].new(disk)
61
+ filesystem.cleaning
62
+ filesystem.partition
63
+ filesystem.format
64
+ OPTIONS_FS[fs]::Mount.new(disk, user).run
65
+ else
66
+ exit 1
67
+ end
68
+ end
69
+
70
+ def self.init_gentoo(options)
71
+ gentoo = Getch::Gentoo
72
+ gentoo.stage3
73
+ gentoo.config(options)
74
+ gentoo.chroot
75
+ gentoo.kernel
76
+ gentoo.boot(options)
77
+ end
78
+
2
79
  def self.main(argv)
3
- puts "Starting..."
80
+ options = Options.new(argv)
81
+ DEFAULT_OPTIONS.freeze
82
+ resume_options(options)
83
+ Getch::States.new() # Update States
84
+ format(options.disk, options.fs, options.username)
85
+ init_gentoo(options)
4
86
  end
5
87
  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,7 @@
1
+ module Getch
2
+ module FileSystem
3
+ end
4
+ end
5
+
6
+ require_relative 'filesystem/root'
7
+ require_relative 'filesystem/ext4'
@@ -0,0 +1,75 @@
1
+ module Getch
2
+ module FileSystem
3
+ class Ext4 < Getch::FileSystem::Root
4
+ def initialize(disk)
5
+ @disk = disk
6
+ @fs = 'ext4'
7
+ super
8
+ end
9
+
10
+ class Mount < Getch::Mount
11
+ def initialize(disk, user)
12
+ @disk = disk
13
+ @user = user
14
+ super
15
+ end
16
+
17
+ private
18
+
19
+ def gen_vars
20
+ @dev_boot_efi = Helpers::efi? ? "/dev/#{@disk}1" : nil
21
+ @dev_swap = "/dev/#{@disk}2"
22
+ @dev_root = "/dev/#{@disk}3"
23
+ @dev_home = @user ? "/dev/#{@disk}4" : nil
24
+ end
25
+
26
+ def data_fstab
27
+ boot_efi = @dev_boot_efi ? "UUID=#{@uuid_boot_efi} /boot/efi vfat noauto,defaults 0 2" : ''
28
+ swap = @dev_swap ? "UUID=#{@uuid_swap} none swap discard 0 0" : ''
29
+ root = @dev_root ? "UUID=#{@uuid_root} / ext4 defaults 0 1" : ''
30
+ home = @dev_home ? "UUID=#{@uuid_home} /home/#{@user} ext4 defaults 0 2" : ''
31
+
32
+ return [ boot_efi, swap, root, home ]
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ # Follow https://wiki.archlinux.org/index.php/Partitioning
39
+ def partition_efi
40
+ # /boot/efi - EFI system partition - 260MB
41
+ # swap - Linux Swap - size of the ram
42
+ # / - Root
43
+ # /home - Home
44
+ system("sgdisk -n1:1M:+260M -t1:EF00 /dev/#{@disk}") # boot EFI
45
+ system("sgdisk -n2:0:+2G -t2:8200 /dev/#{@disk}") # swap
46
+ system("sgdisk -n3:0:+15G -t3:8304 /dev/#{@disk}") # root
47
+ system("sgdisk -n4:0:0 -t3:8302 /dev/#{@disk}") # home
48
+ end
49
+
50
+ def format_efi
51
+ system("mkfs.fat -F32 /dev/#{@disk}1")
52
+ system("mkswap /dev/#{@disk}2")
53
+ system("mkfs.#{@fs} /dev/#{@disk}3")
54
+ system("mkfs.#{@fs} /dev/#{@disk}4")
55
+ end
56
+
57
+ def partition_bios
58
+ # None - Bios Boot Partition - 1MiB
59
+ # swap - Linux Swap - size of the ram
60
+ # / - Root
61
+ # /home - Home
62
+ system("sgdisk -n1:1MiB:+1MiB -t1:EF02 /dev/#{@disk}")
63
+ system("sgdisk -n2:0:+2G -t2:8200 /dev/#{@disk}")
64
+ system("sgdisk -n3:0:+15G -t3:8304 /dev/#{@disk}")
65
+ system("sgdisk -n4:0:0 -t3:8302 /dev/#{@disk}")
66
+ end
67
+
68
+ def format_bios
69
+ system("mkswap /dev/#{@disk}2")
70
+ system("mkfs.#{@fs} /dev/#{@disk}3")
71
+ system("mkfs.#{@fs} /dev/#{@disk}4")
72
+ end
73
+ end
74
+ end
75
+ end