From 43fbc68ed8143527389e92afc1d6910d55d983ab Mon Sep 17 00:00:00 2001 From: szorfein Date: Fri, 11 Oct 2024 07:59:09 +0000 Subject: [PATCH 1/8] add option boot-size #6 --- lib/getch.rb | 6 +++--- lib/getch/device.rb | 2 ++ lib/getch/options.rb | 5 +++++ lib/sgdisk.rb | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/getch.rb b/lib/getch.rb index b96a496..f84657b 100644 --- a/lib/getch.rb +++ b/lib/getch.rb @@ -16,7 +16,6 @@ require_relative 'getch/version' module Getch - OPTIONS = { boot_disk: false, disk: false, @@ -35,7 +34,8 @@ module Getch username: false, verbose: false, vg_name: 'vg4', - zfs_name: 'pool' + zfs_name: 'pool', + boot_size: 260 } STATES = { @@ -49,7 +49,7 @@ module Getch terraform: false, bootloader: false, services: false, - finalize: false, + finalize: false } MOUNTPOINT = '/mnt/getch' diff --git a/lib/getch/device.rb b/lib/getch/device.rb index 9b4c1ae..2756734 100644 --- a/lib/getch/device.rb +++ b/lib/getch/device.rb @@ -52,6 +52,8 @@ def zcache(dev) private def load_devs + raise ArgumentError, 'No disk for root, use --disk DISK.' unless OPTIONS[:disk] + if File.exist? @file DEVS.merge! YAML.load_file @file else diff --git a/lib/getch/options.rb b/lib/getch/options.rb index 74baea3..a6e7a59 100644 --- a/lib/getch/options.rb +++ b/lib/getch/options.rb @@ -66,6 +66,11 @@ def parse(argv) OPTIONS[:home_disk] = Getch::Guard.disk(home) end + opts.on('--boot-size SIZE', Numeric, + 'Specifie the boot size in mebibyte (mib), default use 256.') do |size| + OPTIONS[:boot_size] = size + end + opts.on('--lvm', 'System will use LVM, do not work with ZFS.') do OPTIONS[:lvm] = true diff --git a/lib/sgdisk.rb b/lib/sgdisk.rb index ba197c8..a63704b 100644 --- a/lib/sgdisk.rb +++ b/lib/sgdisk.rb @@ -42,7 +42,7 @@ def make_efi def make_boot @boot || return - partition @boot, @boot_code, '0:+256MiB' + partition @boot, @boot_code, "0:+#{OPTIONS[:boot_size]}MiB" end def make_swap From e01b0d7a9d749e0b8b41f1dd6e3902d56e9930ba Mon Sep 17 00:00:00 2001 From: szorfein Date: Fri, 11 Oct 2024 12:30:21 +0000 Subject: [PATCH 2/8] add option swap-size and root-size #6 --- CHANGELOG.md | 6 ++++++ lib/getch.rb | 6 ++++-- lib/getch/helpers.rb | 4 ++-- lib/getch/options.rb | 10 ++++++++++ lib/lvm2.rb | 21 +++++++++++++-------- lib/sgdisk.rb | 4 ++-- 6 files changed, 37 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33d9ea8..741aaff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +* Add a new option `--boot-size SIZE`, like requested in + [#6](https://github.com/szorfein/getch/issues/6), actually, it's only used on a +/boot partition, not /efi. +* Add a new option `--root-size SIZE`. +* Add a new option `--swap-size SIZE`. + ## 0.7.3, release 2024-10 Add a Workflow to build gem on Github diff --git a/lib/getch.rb b/lib/getch.rb index f84657b..c99d60d 100644 --- a/lib/getch.rb +++ b/lib/getch.rb @@ -33,9 +33,11 @@ module Getch timezone: 'UTC', username: false, verbose: false, - vg_name: 'vg4', + vg_name: 'vg0', zfs_name: 'pool', - boot_size: 260 + boot_size: 260, + swap_size: Getch::Helpers.get_memory, + root_size: 16 } STATES = { diff --git a/lib/getch/helpers.rb b/lib/getch/helpers.rb index 0b17ab3..ee81927 100644 --- a/lib/getch/helpers.rb +++ b/lib/getch/helpers.rb @@ -109,9 +109,9 @@ def self.get_memory t = l.split(' ') if l =~ /memtotal/i t && mem = t[1] end - mem || Log.new.fatal('get_memory - failed to get memory') + mem_to_mb = mem.to_i / 1024 || Log.new.fatal('get_memory - failed to get memory') - mem += 'K' + mem_to_mb.to_s end # get the sector size of a disk diff --git a/lib/getch/options.rb b/lib/getch/options.rb index a6e7a59..8130d35 100644 --- a/lib/getch/options.rb +++ b/lib/getch/options.rb @@ -71,6 +71,16 @@ def parse(argv) OPTIONS[:boot_size] = size end + opts.on('--swap-size SIZE', Numeric, + "Specifie the swap size in megabyte (mb), default use your current memory #{Getch::OPTIONS[:swap_size]}.") do |size| + OPTIONS[:swap_size] = size + end + + opts.on('--root-size SIZE', Numeric, + 'Specifie the root size in gigabyte (G), default use 16 (used only on lvm when --separate-home was not specified.') do |size| + OPTIONS[:root_size] = size + end + opts.on('--lvm', 'System will use LVM, do not work with ZFS.') do OPTIONS[:lvm] = true diff --git a/lib/lvm2.rb b/lib/lvm2.rb index ca03381..888c42a 100644 --- a/lib/lvm2.rb +++ b/lib/lvm2.rb @@ -3,12 +3,13 @@ require 'getch/command' module Lvm2 + # Configure system with lvm class Root def initialize(devs, options) @cache = options[:cache_disk] ||= nil @root = devs[:root] ||= nil @home = options[:home_disk] ||= nil - @vg = options[:vg_name] ||= 'vg1' + @vg = options[:vg_name] ||= 'vg0' end def x @@ -28,14 +29,14 @@ def load_datas end def pv_create - devs = [ @path_root ] + devs = [@path_root] @cache && devs << @path_cache @home && devs << @path_home devs.each { |d| d && add_pv(d) } end def vg_create - devs = [ @path_root ] + devs = [@path_root] @cache && devs << @path_cache @home && devs << @path_home add_vg devs @@ -56,7 +57,7 @@ def enable_lvs private def add_pv(dev) - File.exist? dev || @log.fatal("add_pv - no #{dev} exist.") + File.exist?(dev) || @log.fatal("add_pv - no #{dev} exist.") Getch::Command.new('pvcreate', '-f', dev) end @@ -66,15 +67,18 @@ def add_vg(*devs) end def add_swap(dev = nil) - mem = Getch::Helpers.get_memory + mem = "#{Getch::OPTIONS[:swap_size]}M" lvcreate('-L', mem, '-n', 'swap', @vg, dev) end # if home is available, we use the whole space. def add_lv_root - @home ? - @root.match?(/[0-9]/) ? add_root : add_root(nil, @path_root) : - @root.match?(/[0-9]/) ? add_root('16G') : add_root('16G', @path_root) + size = "#{OPTIONS[:root_size]}G" # in gigabyte + if @home + @root.match?(/[0-9]/) ? add_root : add_root(nil, @path_root) + else + @root.match?(/[0-9]/) ? add_root(size) : add_root(size, @path_root) + end end def add_root(size = nil, dev = nil) @@ -97,6 +101,7 @@ def lvchange_y(name) end end + # Configure hybrid system (encrypt + lvm) class Hybrid < Root def initialize(devs, options) super diff --git a/lib/sgdisk.rb b/lib/sgdisk.rb index a63704b..903a929 100644 --- a/lib/sgdisk.rb +++ b/lib/sgdisk.rb @@ -42,13 +42,13 @@ def make_efi def make_boot @boot || return - partition @boot, @boot_code, "0:+#{OPTIONS[:boot_size]}MiB" + partition @boot, @boot_code, "0:+#{Getch::OPTIONS[:boot_size]}MiB" end def make_swap @swap || return - mem = Getch::Helpers.get_memory + mem = "#{Getch::OPTIONS[:swap_size]}M" partition @swap, @swap_code, "0:+#{mem}" end From dc89845a9363eee14b9953b5c086830c2e379ef1 Mon Sep 17 00:00:00 2001 From: szorfein Date: Fri, 11 Oct 2024 13:55:06 +0000 Subject: [PATCH 3/8] also configure zfs #6 --- README.md | 4 ++++ lib/fstab/root.rb | 2 +- lib/fstab/zfs.rb | 11 ++++++++--- lib/lvm2.rb | 2 +- lib/sgdisk.rb | 6 +++--- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 13e92a2..3405847 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,10 @@ Encrypt with ext4 and create a new user `ninja`: # getch --format ext4 --encrypt --username ninja +Change size of root in Gb, swap in Mb with lvm. + + # getch --disk vda -o void --lvm --root-size 10 --swap-size 4096 + With ZFS, if used with `--encrypt`, it use the native ZFS encryption: # getch --format zfs diff --git a/lib/fstab/root.rb b/lib/fstab/root.rb index 299cae9..4a79ea2 100644 --- a/lib/fstab/root.rb +++ b/lib/fstab/root.rb @@ -37,7 +37,7 @@ def write_efi @efi || return uuid = gen_uuid @efi - line = "UUID=#{uuid} /efi vfat defaults,nosuid,nodev 0 0" + line = "UUID=#{uuid} /efi vfat defaults,nosuid,nodev 0 2" echo_a @conf, line end diff --git a/lib/fstab/zfs.rb b/lib/fstab/zfs.rb index 1631be1..326c203 100644 --- a/lib/fstab/zfs.rb +++ b/lib/fstab/zfs.rb @@ -1,4 +1,7 @@ +# frozen_string_literal: true + module Fstab + # Generating fstab for zfs filesystem class Zfs < Root def initialize(devs, options) super @@ -14,9 +17,11 @@ def generate def write_swap uuid = gen_uuid @swap - @encrypt ? - line = "/dev/mapper/swap-luks none swap sw 0 0" : - line = "UUID=#{uuid} swap swap rw,noatime,discard 0 0" + line = if @encrypt + '/dev/mapper/swap-luks none swap sw 0 0' + else + "UUID=#{uuid} swap swap rw,noatime,discard 0 0" + end echo_a @conf, line end end diff --git a/lib/lvm2.rb b/lib/lvm2.rb index 888c42a..45b8baf 100644 --- a/lib/lvm2.rb +++ b/lib/lvm2.rb @@ -73,7 +73,7 @@ def add_swap(dev = nil) # if home is available, we use the whole space. def add_lv_root - size = "#{OPTIONS[:root_size]}G" # in gigabyte + size = "#{Getch::OPTIONS[:root_size]}G" # in gigabyte if @home @root.match?(/[0-9]/) ? add_root : add_root(nil, @path_root) else diff --git a/lib/sgdisk.rb b/lib/sgdisk.rb index 903a929..6977e55 100644 --- a/lib/sgdisk.rb +++ b/lib/sgdisk.rb @@ -98,7 +98,7 @@ def end_sector(dev) disk = dev[/^[a-z]+/] cmd = Getch::Command.new("sgdisk -E /dev/#{disk}") end_position = cmd.res.to_i - ( end_position - ( end_position + 1 ) % 2048 ) + (end_position - (end_position + 1) % 2048) end end @@ -135,11 +135,11 @@ def load_codes def make_boot @boot || return - partition @boot, @boot_code, '0:+2G' + partition @boot, @boot_code, "0:+#{Getch::OPTIONS[:boot_size]}MiB" end def make_swap - mem = Getch::Helpers.get_memory + mem = "#{Getch::OPTIONS[:swap_size]}M" partition @swap, @swap_code, "0:+#{mem}" add_zlog add_zcache From 9155a6949c9067613cc2bff1a4dfdc28ec85cbac Mon Sep 17 00:00:00 2001 From: szorfein Date: Fri, 11 Oct 2024 15:07:52 +0000 Subject: [PATCH 4/8] add binary option --- CHANGELOG.md | 2 ++ lib/getch.rb | 3 ++- lib/getch/config/portage.rb | 14 +++++++++++++- lib/getch/options.rb | 4 ++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33d9ea8..da7bdd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +* Support [Gentoo binary](https://www.gentoo.org/news/2023/12/29/Gentoo-binary.html), use `--binary`, it make the install of Gentoo faster (like Void :)) + ## 0.7.3, release 2024-10 Add a Workflow to build gem on Github diff --git a/lib/getch.rb b/lib/getch.rb index b96a496..9096b38 100644 --- a/lib/getch.rb +++ b/lib/getch.rb @@ -35,7 +35,8 @@ module Getch username: false, verbose: false, vg_name: 'vg4', - zfs_name: 'pool' + zfs_name: 'pool', + binary: false } STATES = { diff --git a/lib/getch/config/portage.rb b/lib/getch/config/portage.rb index ed82274..a7fb0ba 100644 --- a/lib/getch/config/portage.rb +++ b/lib/getch/config/portage.rb @@ -30,6 +30,7 @@ def portage_dir mkdir "#{@dest}/package.accept_keywords", 0744 mkdir "#{@dest}/package.unmask", 0744 mkdir "#{@dest}/package.license", 0744 + mkdir "#{@dest}/binrepos.conf", 0744 if OPTIONS[:binary] touch "#{@dest}/package.use/zzz_via_autounmask" touch "#{@dest}/package.accept_keywords/zzz_via_autounmask" @@ -46,17 +47,28 @@ def gentoo_repo # -fomit-frame-pointer reduce code compiled # but have repercussions on the debugging of applications def cpu_conf - change = 'COMMON_FLAGS="-march=native -O2 -pipe -fomit-frame-pointer"' + change = if OPTIONS[:binary] + 'COMMON_FLAGS="-O2 -pipe -march=x86-64 -mtune=generic"' + else + 'COMMON_FLAGS="-march=native -O2 -pipe -fomit-frame-pointer"' + end sed "#{@dest}/make.conf", /^COMMON_FLAGS/, change end # https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Stage#MAKEOPTS + # Gentoo binary + # https://wiki.gentoo.org/wiki/Binary_package_guide + # https://wiki.gentoo.org/wiki/Gentoo_Binary_Host_Quickstart def make_conf nproc = `nproc`.chomp echo_a "#{@dest}/make.conf", 'ACCEPT_KEYWORDS="amd64"' echo_a "#{@dest}/make.conf", 'INPUT_DEVICES="libinput"' echo_a "#{@dest}/make.conf", "MAKEOPTS=\"-j#{nproc} -l#{nproc}\"" + return unless OPTIONS[:binary] + + echo_a "#{@dest}/make.conf", 'EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --getbinpkg"' + echo_a "#{@dest}/make.conf", 'FEATURES="getbinpkg binpkg-request-signature' end # https://www.gentoo.org/downloads/mirrors/ diff --git a/lib/getch/options.rb b/lib/getch/options.rb index 74baea3..c5e7502 100644 --- a/lib/getch/options.rb +++ b/lib/getch/options.rb @@ -80,6 +80,10 @@ def parse(argv) OPTIONS[:musl] = true end + opts.on('--binary', 'Prefer to use binary packages instead of compile them (Gentoo).') do + OPTIONS[:binary] = true + end + opts.on('--verbose', 'Write more messages to the standard output.') do OPTIONS[:verbose] = true end From 744de3cf4f4eda033500fdb99cc3e73b3a35241b Mon Sep 17 00:00:00 2001 From: szorfein Date: Fri, 11 Oct 2024 19:12:24 +0000 Subject: [PATCH 5/8] respect-use --- CHANGELOG.md | 2 +- lib/getch/config/portage.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da7bdd1..2d2b706 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -* Support [Gentoo binary](https://www.gentoo.org/news/2023/12/29/Gentoo-binary.html), use `--binary`, it make the install of Gentoo faster (like Void :)) +* Support [Gentoo binary](https://www.gentoo.org/news/2023/12/29/Gentoo-binary.html), use `--binary`, it make the install of Gentoo faster for small system. ## 0.7.3, release 2024-10 Add a Workflow to build gem on Github diff --git a/lib/getch/config/portage.rb b/lib/getch/config/portage.rb index a7fb0ba..b0231de 100644 --- a/lib/getch/config/portage.rb +++ b/lib/getch/config/portage.rb @@ -67,8 +67,8 @@ def make_conf echo_a "#{@dest}/make.conf", "MAKEOPTS=\"-j#{nproc} -l#{nproc}\"" return unless OPTIONS[:binary] - echo_a "#{@dest}/make.conf", 'EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --getbinpkg"' - echo_a "#{@dest}/make.conf", 'FEATURES="getbinpkg binpkg-request-signature' + echo_a "#{@dest}/make.conf", 'EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --getbinpkg --binpkg-respect-use=y"' + echo_a "#{@dest}/make.conf", 'FEATURES="getbinpkg binpkg-request-signature"' end # https://www.gentoo.org/downloads/mirrors/ From 631b4ff01014365bae9010e7824c783463748387 Mon Sep 17 00:00:00 2001 From: szorfein Date: Sat, 12 Oct 2024 09:05:35 +0000 Subject: [PATCH 6/8] gentoo gpg and changed-use --- README.md | 2 +- lib/getch/command.rb | 17 ++++++++++++----- lib/getch/gentoo/update.rb | 17 ++++++++++++++--- lib/nito.rb | 4 ++++ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 13e92a2..62873c2 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ -A CLI tool to install Gentoo or Void Linux with default: +A CLI tool to install [Gentoo](https://www.gentoo.org/) (by compiling or in [binary](https://www.gentoo.org/news/2023/12/29/Gentoo-binary.html)) or [Void](https://voidlinux.org/) Linux with default: + DNS over HTTPS (with [Quad9](https://www.quad9.net/)). + Vim | Nano installed. + Iptables installed (not configured). diff --git a/lib/getch/command.rb b/lib/getch/command.rb index e9985db..b463404 100644 --- a/lib/getch/command.rb +++ b/lib/getch/command.rb @@ -2,6 +2,7 @@ require 'open3' require 'nito' +require 'stdlib' module Getch class Command @@ -20,7 +21,7 @@ def to_s protected def x - @log.info 'Exec: ' + @cmd + @log.info "Exec: #{@cmd}" cmd = build_cmd Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr| @@ -112,7 +113,7 @@ def initialize(*args) def x msg system('chroot', OPTIONS[:mountpoint], '/bin/bash', '-c', other_args) - $?.success? && return + $CHILD_STATUS.success? && return @log.fatal "Running #{@cmd}" end @@ -137,11 +138,17 @@ def msg @log.info "Installing #{@cmd}...\n" end + # Gentoo binary should not use --changed-use + # https://wiki.gentoo.org/wiki/Binary_package_guide def other_args case OPTIONS[:os] - when 'gentoo' then "source /etc/profile && emerge --changed-use #{@cmd}" - when 'void' then "/usr/bin/xbps-install -y #{@cmd}" - end + when 'gentoo' + if OPTIONS[:binary] + "source /etc/profile && emerge #{@cmd}" + else + "source /etc/profile && emerge --changed-use #{@cmd}" + end + when 'void' then "/usr/bin/xbps-install -y #{@cmd}" end end end end diff --git a/lib/getch/gentoo/update.rb b/lib/getch/gentoo/update.rb index e7e612b..facdcf4 100644 --- a/lib/getch/gentoo/update.rb +++ b/lib/getch/gentoo/update.rb @@ -4,17 +4,20 @@ module Getch module Gentoo + # update system gentoo class Update include NiTo def initialize @log = Log.new + @dest = "#{OPTIONS[:mountpoint]}/etc/portage" x end protected def x + gpg sync add_musl_repo if OPTIONS[:musl] update @@ -22,8 +25,17 @@ def x private + # https://wiki.gentoo.org/wiki/Gentoo_Binary_Host_Quickstart#Package_signature_verification + # Fix permissions error on gnupg directory + def gpg + return unless OPTIONS[:binary] + + mv "#{@dest}/gnupg" "#{@dest}/gnupg.bak" + ChrootOutput.new('getuto') + end + def sync - gentoo_conf = "#{OPTIONS[:mountpoint]}/etc/portage/repos.conf/gentoo.conf" + gentoo_conf = "#{@dest}/repos.conf/gentoo.conf" @log.info "Synchronize index, please waiting...\n" ChrootOutput.new('emaint sync --auto') sed gentoo_conf, /^sync-type/, 'sync-type = rsync' @@ -31,8 +43,7 @@ def sync def add_musl_repo Install.new('dev-vcs/git') - - file = "#{OPTIONS[:mountpoint]}/etc/portage/repos.conf/musl.conf" + file = "#{@dest}/repos.conf/musl.conf" content = <<~CONF [musl] location = /var/db/repos/musl diff --git a/lib/nito.rb b/lib/nito.rb index e0d636c..3a88f55 100644 --- a/lib/nito.rb +++ b/lib/nito.rb @@ -67,6 +67,10 @@ def cp(src, dest) FileUtils.cp src, dest end + def mv(src, dest) + FileUtils.mv src, dest + end + # create a void file def touch(file) File.write(file, '') unless File.exist? file From 006ba16a16e3eaee6bb843d0e9cb9b8eebd2fdfc Mon Sep 17 00:00:00 2001 From: szorfein Date: Sat, 12 Oct 2024 18:36:26 +0000 Subject: [PATCH 7/8] look ok --- lib/getch/command.rb | 2 +- lib/getch/config/portage.rb | 2 +- lib/getch/gentoo/bootloader.rb | 8 ++++++-- lib/getch/gentoo/sources.rb | 7 +++++-- lib/getch/gentoo/update.rb | 4 ++-- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/getch/command.rb b/lib/getch/command.rb index b463404..7b33391 100644 --- a/lib/getch/command.rb +++ b/lib/getch/command.rb @@ -2,7 +2,7 @@ require 'open3' require 'nito' -require 'stdlib' +require 'English' module Getch class Command diff --git a/lib/getch/config/portage.rb b/lib/getch/config/portage.rb index b0231de..ece7f4e 100644 --- a/lib/getch/config/portage.rb +++ b/lib/getch/config/portage.rb @@ -67,7 +67,7 @@ def make_conf echo_a "#{@dest}/make.conf", "MAKEOPTS=\"-j#{nproc} -l#{nproc}\"" return unless OPTIONS[:binary] - echo_a "#{@dest}/make.conf", 'EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --getbinpkg --binpkg-respect-use=y"' + echo_a "#{@dest}/make.conf", 'EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --getbinpkg --with-bdeps=y --binpkg-respect-use=y"' echo_a "#{@dest}/make.conf", 'FEATURES="getbinpkg binpkg-request-signature"' end diff --git a/lib/getch/gentoo/bootloader.rb b/lib/getch/gentoo/bootloader.rb index 49c1875..3016eee 100644 --- a/lib/getch/gentoo/bootloader.rb +++ b/lib/getch/gentoo/bootloader.rb @@ -26,8 +26,12 @@ def install bootctl end - # ChrootOutput.new('emerge --config sys-kernel/gentoo-kernel') - ChrootOutput.new('emerge --config sys-kernel/gentoo-kernel-bin') # should also reload grub-mkconfig + # should also reload grub-mkconfig + if OPTIONS[:binary] + ChrootOutput.new('emerge --config sys-kernel/gentoo-kernel-bin') + else + ChrootOutput.new('emerge --config sys-kernel/gentoo-kernel') + end end def bootctl diff --git a/lib/getch/gentoo/sources.rb b/lib/getch/gentoo/sources.rb index c37bbc4..52dce93 100644 --- a/lib/getch/gentoo/sources.rb +++ b/lib/getch/gentoo/sources.rb @@ -73,8 +73,11 @@ def use_flags def make Install.new('sys-kernel/installkernel') - # Install.new 'sys-kernel/gentoo-kernel' - Install.new 'sys-kernel/gentoo-kernel-bin' + if OPTIONS[:binary] + Install.new 'sys-kernel/gentoo-kernel-bin' + else + Install.new 'sys-kernel/gentoo-kernel' + end end def load_modules diff --git a/lib/getch/gentoo/update.rb b/lib/getch/gentoo/update.rb index facdcf4..7520996 100644 --- a/lib/getch/gentoo/update.rb +++ b/lib/getch/gentoo/update.rb @@ -17,10 +17,10 @@ def initialize protected def x - gpg sync add_musl_repo if OPTIONS[:musl] update + gpg end private @@ -30,7 +30,7 @@ def x def gpg return unless OPTIONS[:binary] - mv "#{@dest}/gnupg" "#{@dest}/gnupg.bak" + mv "#{@dest}/gnupg", "#{@dest}/gnupg.bak" ChrootOutput.new('getuto') end From 71717497d06989b496cc27dc18619f3fefeac8cf Mon Sep 17 00:00:00 2001 From: szorfein Date: Tue, 15 Oct 2024 08:09:00 +0000 Subject: [PATCH 8/8] upd readme, code linting --- CHANGELOG.md | 1 + README.md | 29 +++++++++++++++-------------- lib/getch.rb | 4 +++- lib/getch/config/keymap.rb | 2 +- lib/getch/config/timezone.rb | 2 +- lib/getch/gentoo/finalize.rb | 1 + lib/getch/gentoo/pre_config.rb | 3 ++- lib/getch/gentoo/services.rb | 1 + lib/getch/gentoo/tarball.rb | 23 ++++++++++++++--------- lib/getch/gentoo/terraform.rb | 1 + lib/getch/gentoo/use.rb | 1 + lib/getch/version.rb | 2 +- lib/getch/void/bootloader.rb | 5 ++--- lib/getch/void/finalize.rb | 1 + lib/getch/void/post_config.rb | 1 + lib/getch/void/pre_config.rb | 1 + lib/getch/void/services.rb | 1 + lib/getch/void/update.rb | 1 + 18 files changed, 49 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aea3349..3fa248b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +## 0.11.0, release 2024-10 * Add a new option `--boot-size SIZE`, like requested in [#6](https://github.com/szorfein/getch/issues/6), actually, it's only used on a /boot partition, not /efi. diff --git a/README.md b/README.md index 88d5eec..6be88c2 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Filesystem supported (with or without encryption) + ZFS Boot Manager: -+ **Gentoo**: `BIOS`, `crypted disk` and `musl` will use `Grub2` and `systemd-boot` for `UEFI`. ++ **Gentoo**: Grub2 except on systemd without encryption. + **Void**: use only Grub2. The ISO images i was able to test and that works: @@ -47,7 +47,7 @@ The ISO images i was able to test and that works: You can also use your current `linux` host, just pay attention to the disk that will be used. ## Dependencies -Getch is build without external libs, so it only require `ruby >= 2.5`. +Getch is build without external libs, so it only require `ruby >= 2.6`. On a live image of Void, you need to install `xbps-install -S ruby xz gptfdisk openssl`. @@ -73,40 +73,41 @@ Just ensure than the script is run with a root account. After an install by Getch, take a look on the [wiki](https://github.com/szorfein/getch/wiki). ## Examples -For a french user: +For a french user on Gentoo: - # getch --zoneinfo "Europe/Paris" --language fr_FR --keymap fr + # getch --disk sda --zoneinfo "Europe/Paris" --language fr_FR --keymap fr -Install Gentoo on LVM and use a different root disk `/dev/sdc` +Install Gentoo on LVM and use a different root disk `/dev/vdc` - # getch --format ext4 --lvm --disk sdc + # getch --disk vdc --format ext4 --lvm -Encrypt your disk with LVM with a french keymap +Encrypt your disk with LVM with a french keymap and in binary mode: - # getch --format ext4 --lvm --encrypt --keymap fr + # getch --disk sda --format ext4 --lvm --encrypt --keymap fr --binary Encrypt with ext4 and create a new user `ninja`: - # getch --format ext4 --encrypt --username ninja + # getch --disk vda --format ext4 --encrypt --username ninja -Change size of root in Gb, swap in Mb with lvm. +Change size of root in Gb (default 16 on lvm), swap in Mb (default use your +current total ram) with lvm. - # getch --disk vda -o void --lvm --root-size 10 --swap-size 4096 + # getch --disk sda -o void --lvm --root-size 10 --swap-size 4096 With ZFS, if used with `--encrypt`, it use the native ZFS encryption: - # getch --format zfs + # getch --disk vda --format zfs With `Void Linux` and `Musl` enable: - # getch --os void --encrypt -k fr --musl + # getch --disk sda --os void --encrypt -k fr --musl ## Troubleshooting #### Old VG for LVM If a old volume group exist, `getch` may fail to partition your disk. You have to clean up your device before proceed with `vgremove` and `pvremove`. An short example how doing this with a volume group named `vg0`: - # vgdisplay | grep vg0 + # vgdisplay | grep vg # vgremove -f vg0 # pvremove -f /dev/sdb diff --git a/lib/getch.rb b/lib/getch.rb index e46a51a..043fd13 100644 --- a/lib/getch.rb +++ b/lib/getch.rb @@ -69,8 +69,9 @@ def resume STATES[:partition] && return @log.fatal 'No disk, use at least getch with -d DISK' unless OPTIONS[:disk] + os_cap = OPTIONS[:os].capitalize - puts "\nBuild " + OPTIONS[:os].capitalize + " Linux with the following args:\n" + puts "\nBuild #{os_cap} Linux with the following args:\n" puts puts "\tLang: #{OPTIONS[:language]}" puts "\tTimezone: #{OPTIONS[:timezone]}" @@ -80,6 +81,7 @@ def resume puts "\tUsername: #{OPTIONS[:username]}" puts "\tEncrypt: #{OPTIONS[:encrypt]}" puts "\tMusl: #{OPTIONS[:musl]}" + puts "\tBinary mode: #{OPTIONS[:binary]}" puts puts "\tseparate-boot disk: #{OPTIONS[:boot_disk]}" puts "\tseparate-cache disk: #{OPTIONS[:cache_disk]}" diff --git a/lib/getch/config/keymap.rb b/lib/getch/config/keymap.rb index 5ad9c8c..d85780f 100644 --- a/lib/getch/config/keymap.rb +++ b/lib/getch/config/keymap.rb @@ -70,7 +70,7 @@ def search_dir @log.fatal('OPTIONS[:os] not supported yet.') end - File.exist? "#{OPTIONS[:mountpoint]}#{@keymaps_dir}" || + File.exist?("#{OPTIONS[:mountpoint]}#{@keymaps_dir}") || @log.fatal("No dir keymaps #{@keymaps_dir} found.") end end diff --git a/lib/getch/config/timezone.rb b/lib/getch/config/timezone.rb index 0fcf87e..468b210 100644 --- a/lib/getch/config/timezone.rb +++ b/lib/getch/config/timezone.rb @@ -44,7 +44,7 @@ def for_systemd return unless Helpers.systemd? src = "/usr/share/zoneinfo/#{OPTIONS[:timezone]}" - dest = "/etc/localtime" + dest = '/etc/localtime' Getch::Chroot.new('ln', '-sf', src, dest) end end diff --git a/lib/getch/gentoo/finalize.rb b/lib/getch/gentoo/finalize.rb index 61d63ec..f811aab 100644 --- a/lib/getch/gentoo/finalize.rb +++ b/lib/getch/gentoo/finalize.rb @@ -2,6 +2,7 @@ module Getch module Gentoo + # last steps class Finalize def initialize x diff --git a/lib/getch/gentoo/pre_config.rb b/lib/getch/gentoo/pre_config.rb index a546602..0600185 100644 --- a/lib/getch/gentoo/pre_config.rb +++ b/lib/getch/gentoo/pre_config.rb @@ -4,6 +4,7 @@ module Getch module Gentoo + # configure before installting the system class PreConfig include NiTo @@ -30,7 +31,7 @@ def github def check_ip(host) ip = `ping -c1 #{host}`.match(/\([0-9]*.[0-9]*.[0-9]*.[0-9]*\)/) - ip[0].tr('()','') + ip[0].tr('()', '') end end end diff --git a/lib/getch/gentoo/services.rb b/lib/getch/gentoo/services.rb index 87120fe..dbb63af 100644 --- a/lib/getch/gentoo/services.rb +++ b/lib/getch/gentoo/services.rb @@ -2,6 +2,7 @@ module Getch module Gentoo + # install|enable services for the next boot class Services def initialize x diff --git a/lib/getch/gentoo/tarball.rb b/lib/getch/gentoo/tarball.rb index 0f35a6b..a5dab6d 100644 --- a/lib/getch/gentoo/tarball.rb +++ b/lib/getch/gentoo/tarball.rb @@ -5,14 +5,17 @@ module Getch module Gentoo + # Download the last archive rootfs class Tarball def initialize @log = Log.new @mirror = 'https://mirror.rackspace.com/gentoo' @release = release - @stage_file = OPTIONS[:musl] ? - "stage3-amd64-musl-#{@release}.tar.xz" : - "stage3-amd64-systemd-#{@release}.tar.xz" + @stage_file = if OPTIONS[:musl] + "stage3-amd64-musl-#{@release}.tar.xz" + else + "stage3-amd64-systemd-#{@release}.tar.xz" + end end def x @@ -25,9 +28,11 @@ def x protected def stage3 - OPTIONS[:musl] ? - @mirror + '/releases/amd64/autobuilds/latest-stage3-amd64-musl.txt' : - @mirror + '/releases/amd64/autobuilds/latest-stage3-amd64-systemd.txt' + if OPTIONS[:musl] + "#{@mirror}/releases/amd64/autobuilds/latest-stage3-amd64-musl.txt" + else + "#{@mirror}/releases/amd64/autobuilds/latest-stage3-amd64-systemd.txt" + end end # release check line like bellow and return 20231126T163200Z: @@ -51,11 +56,11 @@ def get_stage3 return if File.exist? @stage_file @log.info "wget #{@stage_file}, please wait...\n" - Helpers.get_file_online(@mirror + '/releases/amd64/autobuilds/' + file, @stage_file) + Helpers.get_file_online("#{@mirror}/releases/amd64/autobuilds/#{file}", @stage_file) end def control_files - @log.info "Download other files..." + @log.info 'Download other files...' ['DIGESTS', 'asc', 'CONTENTS.gz'].each do |f| Helpers.get_file_online("#{@mirror}/releases/amd64/autobuilds/#{file}.#{f}", "#{@stage_file}.#{f}") end @@ -66,7 +71,7 @@ def checksum @log.info 'Checking SHA512 checksum...' command = "awk '/SHA512 HASH/{getline;print}' #{@stage_file}.DIGESTS | sha512sum --check" _, stderr, status = Open3.capture3(command) - if status.success? then + if status.success? @log.result_ok else cleaning diff --git a/lib/getch/gentoo/terraform.rb b/lib/getch/gentoo/terraform.rb index 68e1b70..08ebfa7 100644 --- a/lib/getch/gentoo/terraform.rb +++ b/lib/getch/gentoo/terraform.rb @@ -1,5 +1,6 @@ module Getch module Gentoo + # install required/usefull packages class Terraform def initialize x diff --git a/lib/getch/gentoo/use.rb b/lib/getch/gentoo/use.rb index 3469e79..b56a951 100644 --- a/lib/getch/gentoo/use.rb +++ b/lib/getch/gentoo/use.rb @@ -4,6 +4,7 @@ module Getch module Gentoo + # Utility to configure use flag on Gentoo class Use include NiTo diff --git a/lib/getch/version.rb b/lib/getch/version.rb index db80f9c..215a5ee 100644 --- a/lib/getch/version.rb +++ b/lib/getch/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Getch - VERSION = '0.7.3' + VERSION = '0.11.0' end diff --git a/lib/getch/void/bootloader.rb b/lib/getch/void/bootloader.rb index a64daee..690d766 100644 --- a/lib/getch/void/bootloader.rb +++ b/lib/getch/void/bootloader.rb @@ -2,11 +2,10 @@ module Getch module Void + # install grub class Bootloader def dependencies - Helpers.efi? ? - Install.new('grub-x86_64-efi') : - Install.new('grub') + Helpers.efi? ? Install.new('grub-x86_64-efi') : Install.new('grub') end def install diff --git a/lib/getch/void/finalize.rb b/lib/getch/void/finalize.rb index 88f55b6..d1f6ac5 100644 --- a/lib/getch/void/finalize.rb +++ b/lib/getch/void/finalize.rb @@ -2,6 +2,7 @@ module Getch module Void + # last steps class Finalize def initialize x diff --git a/lib/getch/void/post_config.rb b/lib/getch/void/post_config.rb index 6b40ff2..f707b84 100644 --- a/lib/getch/void/post_config.rb +++ b/lib/getch/void/post_config.rb @@ -2,6 +2,7 @@ module Getch module Void + # config after installing the rootfs class PostConfig def initialize x diff --git a/lib/getch/void/pre_config.rb b/lib/getch/void/pre_config.rb index f31b4b8..0a2aefb 100644 --- a/lib/getch/void/pre_config.rb +++ b/lib/getch/void/pre_config.rb @@ -2,6 +2,7 @@ module Getch module Void + # config before installing the system class PreConfig def initialize x diff --git a/lib/getch/void/services.rb b/lib/getch/void/services.rb index da20a34..49084ab 100644 --- a/lib/getch/void/services.rb +++ b/lib/getch/void/services.rb @@ -2,6 +2,7 @@ module Getch module Void + # install/enable services class Services def initialize x diff --git a/lib/getch/void/update.rb b/lib/getch/void/update.rb index 61b0b2b..74a8ef4 100644 --- a/lib/getch/void/update.rb +++ b/lib/getch/void/update.rb @@ -2,6 +2,7 @@ module Getch module Void + # system update class Update def initialize @log = Log.new