summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorWilliam A. Kennington III <william@wkennington.com>2014-04-30 18:45:44 -0500
committerWilliam A. Kennington III <william@wkennington.com>2014-08-28 13:35:35 -0700
commit99b4792554859b57b6263a807f9335edceb7a4b0 (patch)
treed2fa60a4c7163f40c31d2383bbcdd593af9548c3 /nixos
parent1f460e00efb99a1450f5b5806d68ff6633641ad8 (diff)
downloadnixlib-99b4792554859b57b6263a807f9335edceb7a4b0.tar
nixlib-99b4792554859b57b6263a807f9335edceb7a4b0.tar.gz
nixlib-99b4792554859b57b6263a807f9335edceb7a4b0.tar.bz2
nixlib-99b4792554859b57b6263a807f9335edceb7a4b0.tar.lz
nixlib-99b4792554859b57b6263a807f9335edceb7a4b0.tar.xz
nixlib-99b4792554859b57b6263a807f9335edceb7a4b0.tar.zst
nixlib-99b4792554859b57b6263a807f9335edceb7a4b0.zip
nixos/grub: Refactor perl script to remove the Switch module
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/system/boot/loader/grub/install-grub.pl48
1 files changed, 26 insertions, 22 deletions
diff --git a/nixos/modules/system/boot/loader/grub/install-grub.pl b/nixos/modules/system/boot/loader/grub/install-grub.pl
index 64151a282f16..fd298333cc4a 100644
--- a/nixos/modules/system/boot/loader/grub/install-grub.pl
+++ b/nixos/modules/system/boot/loader/grub/install-grub.pl
@@ -8,7 +8,6 @@ use File::stat;
 use File::Copy;
 use POSIX;
 use Cwd;
-use Switch;
 
 my $defaultConfig = $ARGV[1] or die;
 
@@ -78,9 +77,13 @@ sub GrubFs {
     my $fs = GetFs($dir);
     my $path = "/" . substr($dir, length($fs->mount));
     my $search = "";
+
     if ($grubVersion > 1) {
+        # ZFS is completely separate logic as zpools are always identified by a label
+        # or custom UUID
         if ($fs->type eq "zfs") {
             my $sid = index($fs->device, "/");
+
             if ($sid < 0) {
                 $search = "--label " . $fs->device;
                 $path = "/@" . $path;
@@ -89,32 +92,33 @@ sub GrubFs {
                 $path = "/" . substr($fs->device, $sid) . "/@" . $path;
             }
         } else {
-            my $idCmd = "\$(blkid -o export " . $fs->device . ") 2>/dev/null; echo"
-            switch ($fsIdentifier) {
-                case "uuid" {
-                    $search = "--fs-uuid " . `$idCmd \$UUID`;
-                }
-                case "label" {
-                    $search = "--label " . `$idCmd \$LABEL`;
+            my $idCmd = "\$(blkid -o export " . $fs->device . ") 2>/dev/null; echo";
+
+            if ($fsIdentifier eq "uuid") {
+                $search = "--fs-uuid " . `$idCmd \$UUID`;
+            } elsif ($fsIdentifier eq "label") {
+                $search = "--label " . `$idCmd \$LABEL`;
+            } elsif ($fsIdentifier eq "provided") {
+                my $lbl = "/dev/disk/by-label/";
+
+                # If the provided dev is identifying the partition using a label or uuid,
+                # we should get the label / uuid and do a proper search
+                if (index($fs->device, $lbl) == 0) {
+                    $search = "--label " . substr($fs->device, length($lbl));
                 }
-                case "provided" {
-                    my $lbl = "/dev/disk/by-label/";
-                    if (index($fs->device, $lbl) == 0) {
-                        $search = "--label " . substr($fs->device, length($lbl));
-                    }
-                    my $uuid = "/dev/disk/by-uuid/";
-                    if (index($fs->device, $uuid) == 0) {
-                        $search = "--fs-uuid " . substr($fs->device, length($uuid));
-                    }
-                }
-                else {
-                    die "invalid fs identifier type\n";
+                my $uuid = "/dev/disk/by-uuid/";
+                if (index($fs->device, $uuid) == 0) {
+                    $search = "--fs-uuid " . substr($fs->device, length($uuid));
                 }
+            } else {
+                die "invalid fs identifier type\n";
             }
+
+            # BTRFS is a special case in that we need to fix the referrenced path based on subvolumes
             if ($fs->type eq "btrfs") {
-                $subvol = `mount | sed -n 's,^@{[$fs->device]} on .*subvol=\([^,)]*\).*\$,\1,p'`
+                my $subvol = `mount | sed -n 's,^@{[$fs->device]} on .*subvol=\([^,)]*\).*\$,\1,p'`;
                 if ($subvol eq "") {
-                    $subvol = `btrfs subvol get-default @{[$fs->mount]} | sed -n 's,^.*path \([^ ]*\) .*\$,\1,p'`
+                    $subvol = `btrfs subvol get-default @{[$fs->mount]} | sed -n 's,^.*path \([^ ]*\) .*\$,\1,p'`;
                 }
                 $path = "/$subvol";
             }