From c6ea86a21e1e3135304bed96bd8302863c2bb70d Mon Sep 17 00:00:00 2001 From: langfingaz Date: Mon, 3 May 2021 16:12:27 +0200 Subject: [PATCH] grub: remember selected menu entry --- pkg/de-p1st-grub/.install | 15 ++++++++ pkg/de-p1st-grub/PKGBUILD | 10 +++--- pkg/de-p1st-grub/README.md | 12 +++++++ pkg/de-p1st-grub/grub.holoscript | 10 ++++++ pkg/de-p1st-installer/de-p1st-installer.sh | 40 ++++++++++++++++++---- pkg/de-p1st-installer/lib/block-device.sh | 13 ++++++- pkg/de-p1st-mkinitcpio/.install | 17 ++++++--- pkg/de-p1st-mkinitcpio/PKGBUILD | 2 +- pkg/de-p1st-repo/README.md | 2 +- 9 files changed, 103 insertions(+), 18 deletions(-) create mode 100644 pkg/de-p1st-grub/.install create mode 100644 pkg/de-p1st-grub/README.md create mode 100644 pkg/de-p1st-grub/grub.holoscript diff --git a/pkg/de-p1st-grub/.install b/pkg/de-p1st-grub/.install new file mode 100644 index 0000000..b754ef5 --- /dev/null +++ b/pkg/de-p1st-grub/.install @@ -0,0 +1,15 @@ +## arg 1: the new package version +post_install() { + holo apply +} + +## arg 1: the new package version +## arg 2: the old package version +post_upgrade() { + holo apply +} + +## arg 1: the old package version +post_remove() { + holo apply +} diff --git a/pkg/de-p1st-grub/PKGBUILD b/pkg/de-p1st-grub/PKGBUILD index 500d1fc..1b6a4b1 100644 --- a/pkg/de-p1st-grub/PKGBUILD +++ b/pkg/de-p1st-grub/PKGBUILD @@ -2,14 +2,14 @@ _pkgname=grub _reponame=arch pkgname="de-p1st-$_pkgname" -pkgver=0.0.2 -pkgrel=2 +pkgver=0.0.3 +pkgrel=1 pkgdesc="grub with configuration" arch=('any') url="https://codeberg.org/privacy1st/${_reponame}" license=('MIT') groups=() -depends=('grub') +depends=('grub' 'holo') makedepends=('git') optdepends=() provides=() @@ -17,7 +17,7 @@ conflicts=() replaces=() backup=() options=() -install= +install='.install' changelog= source=("git+${url}.git") noextract=() @@ -27,4 +27,6 @@ package() { cd "${_reponame}/pkg/${pkgname}" install -Dm0755 -o0 40_efi_setup "$pkgdir"/etc/grub.d/40_efi_setup + + install -Dm0544 grub.holoscript "$pkgdir"/usr/share/holo/files/"$pkgname"/etc/default/grub.holoscript } diff --git a/pkg/de-p1st-grub/README.md b/pkg/de-p1st-grub/README.md new file mode 100644 index 0000000..79a758f --- /dev/null +++ b/pkg/de-p1st-grub/README.md @@ -0,0 +1,12 @@ +# grub + +## efi setup + +See [/etc/grub.d/40_efi_setup](40_efi_setup) + +## multiple entries + +* disable submenu +* remember last selection + +Archwiki: [GRUB/Tips_and_tricks#Multiple_entries](https://wiki.archlinux.org/title/GRUB/Tips_and_tricks#Multiple_entries) diff --git a/pkg/de-p1st-grub/grub.holoscript b/pkg/de-p1st-grub/grub.holoscript new file mode 100644 index 0000000..717dbf7 --- /dev/null +++ b/pkg/de-p1st-grub/grub.holoscript @@ -0,0 +1,10 @@ +#!/bin/sh +# stdin: default config +# stdout: modified config + +# 1) and 2) remember last selected entry; 3) disable submenu +sed ' + s|^GRUB_DEFAULT=0$|GRUB_DEFAULT=saved|; + s|^#GRUB_SAVEDEFAULT="true"$|#GRUB_SAVEDEFAULT="true"|; + s|^#GRUB_DISABLE_SUBMENU=y$|GRUB_DISABLE_SUBMENU=y|; +' diff --git a/pkg/de-p1st-installer/de-p1st-installer.sh b/pkg/de-p1st-installer/de-p1st-installer.sh index 0eb848c..86d3af7 100755 --- a/pkg/de-p1st-installer/de-p1st-installer.sh +++ b/pkg/de-p1st-installer/de-p1st-installer.sh @@ -294,9 +294,29 @@ function user_and_pwd() { printf "%s:%s" "root" "${ROOT_PWD}" | chpasswd --root /mnt || return $? } -function gen_initramfs(){ +function bootloader() { + # @pre + # TARGET_BLOCK_DEVICE + # LUKS_PART_UUID + + case "${BIOS_TYPE}" in + uefi) + # portable fallback efi name for grub: + # * https://www.rodsbooks.com/efi-bootloaders/installation.html#alternative-naming + # * arch-chroot /mnt cp /boot/EFI/GRUB/grubx64.efi /boot/EFI/BOOT/bootx64.efi + arch-chroot /mnt grub-install --target=x86_64-efi --bootloader-id=GRUB --efi-directory=/boot --removable || return $? + ;; + bios) + arch-chroot /mnt grub-install --target=i386-pc "${TARGET_BLOCK_DEVICE}" || return $? + ;; + *) + echo "Not yet implemented!" + return 1 + ;; + esac + # TODO - true + } function main() { @@ -322,7 +342,7 @@ function main() { # out: BOOT_PART, LUKS_PART partition || return $? # in: BIOS_TYPE, BOOT_PART, LUKS_PART, LUKS_PWD, FS - # out: DATA_PART + # out: LUKS_PART_UUID, DATA_PART format || return $? # Combine default and chosen mount options @@ -338,16 +358,22 @@ function main() { mount "$BOOT_PART" /mnt/boot || return $? # in: BIOS_TYPE, KERNEL, CPU_VENDOR - run_pacstrap || return $? + run_pacstrap || return $? # in: FS - run_genfstab || return $? + run_genfstab || return $? # in: HOSTNAME, FQDN (optional), STATIC_IP (optional), IPV6_CAPABLE (optional) config_hostname_and_hosts || return $? # in: USERNAME, USER_PWD, ROOT_PWD (optional) - user_and_pwd || return $? + user_and_pwd || return $? - gen_initramfs || return $? + mkinitcpio -P || return $? + # in: TARGET_BLOCK_DEVICE, LUKS_PART_UUID + bootloader || return $? + + umount -R /mnt || return $? + cryptsetup luksClose "$(basename "${DATA_PART}")" || return $? + echo "Finished installation without errors!" } main "$@" diff --git a/pkg/de-p1st-installer/lib/block-device.sh b/pkg/de-p1st-installer/lib/block-device.sh index b4933fb..4b0f153 100644 --- a/pkg/de-p1st-installer/lib/block-device.sh +++ b/pkg/de-p1st-installer/lib/block-device.sh @@ -7,6 +7,14 @@ # -n, --noheadings # -x, --sort column +function get_uuid() { + # arg $1: partition + # arg $2: variable name to store UUID + + local -n ptr=$2 || return $? + ptr="$(blkid -o value -s UUID "${1}")" || return $? +} + function get_partitions(){ # arg $1: block-device # @post @@ -14,7 +22,7 @@ function get_partitions(){ # Remove first line of output (which is just the block device $1 itself) # with sed: sed 1d - PARTITIONS="$(lsblk -pln -o name "$1" | sed 1d)" || return $? + PARTITIONS="$(lsblk -pln -o name "${1}" | sed 1d)" || return $? newline_separated_to_array PARTITIONS PARTITIONS || return $? } @@ -110,6 +118,7 @@ function format() { # LUKS_PWD # FS # @post + # LUKS_PART_UUID # DATA_PART (variable set with value /dev/mapper/$(basename "${LUKS_PART}") # boot partition formatted # luks partition formatted and opened at DATA_PART @@ -129,6 +138,8 @@ function format() { --cipher aes-xts-plain64 --key-size 512 --hash sha512 \ --iter-time 10000 --use-random "${LUKS_PART}" || return $? + get_uuid "${LUKS_PART}" LUKS_PART_UUID || return $? + local luks_name luks_name=$(basename "${LUKS_PART}") DATA_PART="/dev/mapper/${luks_name}" diff --git a/pkg/de-p1st-mkinitcpio/.install b/pkg/de-p1st-mkinitcpio/.install index 4e8faec..9e27da1 100644 --- a/pkg/de-p1st-mkinitcpio/.install +++ b/pkg/de-p1st-mkinitcpio/.install @@ -2,14 +2,17 @@ pre_install() { # Check if system is SSE4.2 capable # lscpu is part of util-linux which is a dependency of mkinitcpio - lscpu | grep sse4_2 >/dev/null 2>&1 + if ! lscpu | grep sse4_2 >/dev/null 2>&1; then + echo "Warning: mkinitcpio.conf has module 'crc32c_intel' enabled but this system is not SSE4.2 capable!" + return 1 + fi } ## arg 1: the new package version post_install() { holo apply if ! mkinitcpio -P; then - echo "The previous error can be ignored on initial system installation. One should however execute 'mkinitcpio -P' after the kernel was installed."; + echo "Failed to generate initramfs. Please run 'mkinitcpio -P' manually. (This is normal during initial system installation)."; return 1; fi } @@ -18,11 +21,17 @@ post_install() { ## arg 2: the old package version post_upgrade() { holo apply - mkinitcpio -P + if ! mkinitcpio -P; then + echo "Failed to generate initramfs." + return 1 + fi } ## arg 1: the old package version post_remove() { holo apply - mkinitcpio -P + if ! mkinitcpio -P; then + echo "Failed to generate initramfs." + return 1 + fi } diff --git a/pkg/de-p1st-mkinitcpio/PKGBUILD b/pkg/de-p1st-mkinitcpio/PKGBUILD index 69ae8d3..dff45f6 100644 --- a/pkg/de-p1st-mkinitcpio/PKGBUILD +++ b/pkg/de-p1st-mkinitcpio/PKGBUILD @@ -2,7 +2,7 @@ _pkgname=mkinitcpio _reponame=arch pkgname="de-p1st-$_pkgname" -pkgver=0.0.3 +pkgver=0.0.4 pkgrel=1 pkgdesc="mkinitcpio configuration" arch=('any') diff --git a/pkg/de-p1st-repo/README.md b/pkg/de-p1st-repo/README.md index f87594c..17c9a12 100644 --- a/pkg/de-p1st-repo/README.md +++ b/pkg/de-p1st-repo/README.md @@ -9,7 +9,7 @@ Special thanks to nachoparker for his article: Install `de-p1st-repo` on your local machine as well as on a remote server. -Adjust `/etc/de-p1st-repo/arch-repo.conf` according to your needs. +Adjust [/etc/de-p1st-repo/arch-repo.conf](arch-repo.cfg) according to your needs. Run a webserver on the server to serve static content: