From d6e17e9392e75d78136ab39921fa59bd1fb857d3 Mon Sep 17 00:00:00 2001 From: Greg Darke Date: Thu, 19 May 2022 15:53:43 +1000 Subject: [PATCH] multiboot: Allow rewriting grub config without sudo. Allow the `MULTIBOOT_MNT` environment to be passed in. My usage of this variable is as follows: ```shell $ MULTIBOOT_MNT="$(findmnt -n -o target LABEL=multiboot)" ./multiboot-setup grubcfg ``` This allows simple updates of the grub config, while taking advantage of the auto mounter provided by Gnome. --- hacks/multiboot-setup | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hacks/multiboot-setup b/hacks/multiboot-setup index 22d73f5..0ea027c 100755 --- a/hacks/multiboot-setup +++ b/hacks/multiboot-setup @@ -3,7 +3,7 @@ set -eu PARTITION_LABEL="multiboot" -MULTIBOOT_MNT="/mnt/multiboot" +MULTIBOOT_MNT="${MULTIBOOT_MNT:-/mnt/multiboot}" function cmd_format { if [ ! -b "${1:-}" ]; then @@ -58,7 +58,12 @@ function install_grub_efi { } function install_grub_cfg { - print_grub_cfg | sudo tee "${MULTIBOOT_MNT}/grub/grub.cfg" > /dev/null + if [[ -w "${MULTIBOOT_MNT}/grub/" ]]; then + # We already have write access, no need to use sudo + print_grub_cfg > "${MULTIBOOT_MNT}/grub/grub.cfg" + else + print_grub_cfg | sudo tee "${MULTIBOOT_MNT}/grub/grub.cfg" > /dev/null + fi } function cmd_mount { -- 2.39.2