]> code.delx.au - monosys/commitdiff
multiboot: Allow rewriting grub config without sudo.
authorGreg Darke <greg@tsukasa.net.au>
Thu, 19 May 2022 05:53:43 +0000 (15:53 +1000)
committerJames Bunton <jamesbunton@delx.net.au>
Fri, 27 May 2022 12:08:39 +0000 (22:08 +1000)
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

index 22d73f5e3b13908e203be88a218fadaf95bc29d9..0ea027c0379a9890033d63f6be57648014b6ea1a 100755 (executable)
@@ -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 {