]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
refactor: factor out label_uuid_to_dev
authorHarald Hoyer <harald@redhat.com>
Mon, 8 Mar 2021 09:12:54 +0000 (10:12 +0100)
committerHarald Hoyer <harald@hoyer.xyz>
Wed, 10 Mar 2021 18:31:19 +0000 (19:31 +0100)
modules.d/01fips/fips.sh
modules.d/90dmsquash-live/dmsquash-generator.sh
modules.d/90dmsquash-live/parse-dmsquash-live.sh
modules.d/91zipl/parse-zipl.sh
modules.d/95resume/parse-resume.sh
modules.d/95rootfs-block/parse-block.sh
modules.d/95rootfs-block/rootfallback.sh
modules.d/98dracut-systemd/dracut-cmdline.sh
modules.d/98dracut-systemd/rootfs-generator.sh
modules.d/98usrmount/mount-usr.sh
modules.d/99base/dracut-lib.sh

index 53d507e9145e5ba97e8881db000221e3deb410ba..5717e07a0920ac5b5edc86b8416a813482ab63c5 100755 (executable)
@@ -18,18 +18,8 @@ mount_boot()
 
     if [ -n "$boot" ]; then
         case "$boot" in
-        LABEL=*)
-            boot="$(echo $boot | sed 's,/,\\x2f,g')"
-            boot="/dev/disk/by-label/${boot#LABEL=}"
-            ;;
-        UUID=*)
-            boot="/dev/disk/by-uuid/${boot#UUID=}"
-            ;;
-        PARTUUID=*)
-            boot="/dev/disk/by-partuuid/${boot#PARTUUID=}"
-            ;;
-        PARTLABEL=*)
-            boot="/dev/disk/by-partlabel/${boot#PARTLABEL=}"
+        LABEL=* | UUID=* | PARTUUID=* | PARTLABEL=*)
+            boot="$(label_uuid_to_dev "$boot")"
             ;;
         /dev/*)
             ;;
index cce29b9cc2ec76a5debb7145f96ca62eaa44bf87..1a4070443c6bc47115279bb5a5034f0137139a7f 100755 (executable)
@@ -16,28 +16,14 @@ fi
 [ "${liveroot%%:*}" = "live" ] || exit 0
 
 case "$liveroot" in
-    live:LABEL=*|LABEL=*) \
-        root="${root#live:}"
-        root="${root//\//\\x2f}"
-        root="live:/dev/disk/by-label/${root#LABEL=}"
+    live:LABEL=*|LABEL=* | live:UUID=*|UUID=* | live:PARTUUID=*|PARTUUID=* | live:PARTLABEL=*|PARTLABEL=*)
+        root="live:$(label_uuid_to_dev "${root#live:}")"
         rootok=1 ;;
-    live:CDLABEL=*|CDLABEL=*) \
+    live:CDLABEL=*|CDLABEL=*)
         root="${root#live:}"
-        root="${root//\//\\x2f}"
+        root="$(echo "$root" | sed 's,/,\\x2f,g;s, ,\\x20,g')"
         root="live:/dev/disk/by-label/${root#CDLABEL=}"
         rootok=1 ;;
-    live:UUID=*|UUID=*) \
-        root="${root#live:}"
-        root="live:/dev/disk/by-uuid/${root#UUID=}"
-        rootok=1 ;;
-    live:PARTUUID=*|PARTUUID=*) \
-        root="${root#live:}"
-        root="live:/dev/disk/by-partuuid/${root#PARTUUID=}"
-        rootok=1 ;;
-    live:PARTLABEL=*|PARTLABEL=*) \
-        root="${root#live:}"
-        root="live:/dev/disk/by-partlabel/${root#PARTLABEL=}"
-        rootok=1 ;;
     live:/*.[Ii][Ss][Oo]|/*.[Ii][Ss][Oo])
         root="${root#live:}"
         root="liveiso:${root}"
index 4d46a36007ff48f652f2174825baa420873dd433..7b6c7ce257166a4ae8b9f6622b72b9d61a3b06a5 100755 (executable)
@@ -18,28 +18,14 @@ fi
 modprobe -q loop
 
 case "$liveroot" in
-    live:LABEL=*|LABEL=*) \
-        root="${root#live:}"
-        root="${root//\//\\x2f}"
-        root="live:/dev/disk/by-label/${root#LABEL=}"
+    live:LABEL=*|LABEL=* | live:UUID=*|UUID=* | live:PARTUUID=*|PARTUUID=* | live:PARTLABEL=*|PARTLABEL=*)
+        root="live:$(label_uuid_to_dev "${root#live:}")"
         rootok=1 ;;
-    live:CDLABEL=*|CDLABEL=*) \
+    live:CDLABEL=*|CDLABEL=*)
         root="${root#live:}"
-        root="${root//\//\\x2f}"
+        root="$(echo "$root" | sed 's,/,\\x2f,g;s, ,\\x20,g')"
         root="live:/dev/disk/by-label/${root#CDLABEL=}"
         rootok=1 ;;
-    live:UUID=*|UUID=*) \
-        root="${root#live:}"
-        root="live:/dev/disk/by-uuid/${root#UUID=}"
-        rootok=1 ;;
-    live:PARTUUID=*|PARTUUID=*) \
-        root="${root#live:}"
-        root="live:/dev/disk/by-partuuid/${root#PARTUUID=}"
-        rootok=1 ;;
-    live:PARTLABEL=*|PARTLABEL=*) \
-        root="${root#live:}"
-        root="live:/dev/disk/by-partlabel/${root#PARTLABEL=}"
-        rootok=1 ;;
     live:/*.[Ii][Ss][Oo]|/*.[Ii][Ss][Oo])
         root="${root#live:}"
         root="liveiso:${root}"
index ddab0ea96169dcd6d1caef07ce4c9bec6ae7ed46..a2be9f5107ff7146ef01833a56c2ab9c35abadc9 100755 (executable)
@@ -9,12 +9,22 @@ if [ -n "$zipl_arg" ] ; then
     LABEL=*) \
         zipl_env="ENV{ID_FS_LABEL}"
         zipl_val=${zipl_arg#LABEL=}
-        zipl_arg="/dev/disk/by-label/${zipl_val}"
+        zipl_arg="$(label_uuid_to_dev "${zipl_val}")"
         ;;
     UUID=*) \
         zipl_env="ENV{ID_FS_UUID}"
         zipl_val=${zipl_arg#UUID=}
-        zipl_arg="/dev/disk/by-uuid/${zipl_val}"
+        zipl_arg="$(label_uuid_to_dev "${zipl_val}")"
+        ;;
+    PARTLABEL=*) \
+        zipl_env="ENV{ID_FS_PARTLABEL}"
+        zipl_val=${zipl_arg#PARTLABEL=}
+        zipl_arg="$(label_uuid_to_dev "${zipl_val}")"
+        ;;
+    PARTUUID=*) \
+        zipl_env="ENV{ID_FS_PARTUUID}"
+        zipl_val=${zipl_arg#PARTUUID=}
+        zipl_arg="$(label_uuid_to_dev "${zipl_val}")"
         ;;
     /dev/mapper/*) \
         zipl_env="ENV{DM_NAME}"
index a3beb95530b01b1ded6e88067a7eac1e1480b965..e525aa2916ce43976fc949f8b13d56f88795e62c 100755 (executable)
@@ -7,17 +7,8 @@ else
     unset resume
 fi
 
-case "$resume" in
-    LABEL=*) \
-        resume="$(echo $resume | sed 's,/,\\x2f,g')"
-        resume="/dev/disk/by-label/${resume#LABEL=}" ;;
-    UUID=*) \
-        resume="/dev/disk/by-uuid/${resume#UUID=}" ;;
-    PARTUUID=*) \
-        resume="/dev/disk/by-partuuid/${resume#PARTUUID=}" ;;
-    PARTLABEL=*) \
-        resume="/dev/disk/by-partlabel/${resume#PARTLABEL=}" ;;
-esac
+
+resume="$(label_uuid_to_dev "$resume")"
 
 if splash=$(getarg splash=); then
     export splash
index 2905a1e0b5f85ea5a5c8107df4a39dd88ce58149..72c0a9566bcbb971ffbd85f15a099e152df240be 100755 (executable)
@@ -1,29 +1,11 @@
 #!/bin/sh
 
-case "$root" in
-    block:LABEL=*|LABEL=*)
-        root="${root#block:}"
-        root="$(echo $root | sed 's,/,\\x2f,g')"
-        root="block:/dev/disk/by-label/${root#LABEL=}"
-        rootok=1 ;;
-    block:UUID=*|UUID=*)
-        root="${root#block:}"
-        root="${root#UUID=}"
-        root="$(echo $root | tr "[:upper:]" "[:lower:]")"
-        root="block:/dev/disk/by-uuid/${root#UUID=}"
-        rootok=1 ;;
-    block:PARTUUID=*|PARTUUID=*)
-        root="${root#block:}"
-        root="${root#PARTUUID=}"
-        root="$(echo $root | tr "[:upper:]" "[:lower:]")"
-        root="block:/dev/disk/by-partuuid/${root}"
-        rootok=1 ;;
-    block:PARTLABEL=*|PARTLABEL=*)
-        root="${root#block:}"
-        root="block:/dev/disk/by-partlabel/${root#PARTLABEL=}"
+case "${root#block:}" in
+    LABEL=* | UUID=* | PARTUUID=* | PARTLABEL=*)
+        root="block:$(label_uuid_to_dev "$root")"
         rootok=1 ;;
     /dev/*)
-        root="block:${root}"
+        root="block:${root#block:}"
         rootok=1 ;;
 esac
 
index f3bc7795efd2c791ee9c9ffacf348e1cdc9bc942..2fa6ba39b8c7135650d868fddee80751b6cd470b 100755 (executable)
@@ -3,29 +3,7 @@
 type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
 
 for root in $(getargs rootfallback=); do
-    case "$root" in
-        block:LABEL=*|LABEL=*)
-            root="${root#block:}"
-            root="$(echo $root | sed 's,/,\\x2f,g')"
-            root="/dev/disk/by-label/${root#LABEL=}"
-            ;;
-        block:UUID=*|UUID=*)
-            root="${root#block:}"
-            root="${root#UUID=}"
-            root="$(echo $root | tr "[:upper:]" "[:lower:]")"
-            root="/dev/disk/by-uuid/${root#UUID=}"
-            ;;
-        block:PARTUUID=*|PARTUUID=*)
-            root="${root#block:}"
-            root="${root#PARTUUID=}"
-            root="$(echo $root | tr "[:upper:]" "[:lower:]")"
-            root="/dev/disk/by-partuuid/${root}"
-            ;;
-        block:PARTLABEL=*|PARTLABEL=*)
-            root="${root#block:}"
-            root="/dev/disk/by-partlabel/${root#PARTLABEL=}"
-            ;;
-    esac
+    root=$(label_uuid_to_dev "$root")
 
     if ! [ -b "$root" ]; then
         warn "Could not find rootfallback $root"
index 934c5ba0cb9b8880d733563fd65afd12591395b1..ac3f2607579a2a9c91fb8f14bcc4a7f9fbd9f9e9 100755 (executable)
@@ -49,23 +49,9 @@ source_hook cmdline
 
 [ -f /lib/dracut/parse-resume.sh ] && . /lib/dracut/parse-resume.sh
 
-case "${root}${root_unset}" in
-    block:LABEL=*|LABEL=*)
-        root="${root#block:}"
-        root="$(echo $root | sed 's,/,\\x2f,g')"
-        root="block:/dev/disk/by-label/${root#LABEL=}"
-        rootok=1 ;;
-    block:UUID=*|UUID=*)
-        root="${root#block:}"
-        root="block:/dev/disk/by-uuid/${root#UUID=}"
-        rootok=1 ;;
-    block:PARTUUID=*|PARTUUID=*)
-        root="${root#block:}"
-        root="block:/dev/disk/by-partuuid/${root#PARTUUID=}"
-        rootok=1 ;;
-    block:PARTLABEL=*|PARTLABEL=*)
-        root="${root#block:}"
-        root="block:/dev/disk/by-partlabel/${root#PARTLABEL=}"
+case "${root#block:}${root_unset}" in
+    LABEL=* | UUID=* | PARTUUID=* | PARTLABEL=*)
+        root="block:$(label_uuid_to_dev "$root")"
         rootok=1 ;;
     /dev/*)
         root="block:${root}"
index bb376c0f6c77f3ec367d6fc4cc6fb90714caa184..a9fef9c90de6755fdd8671323c5f5bd16e6325d4 100755 (executable)
@@ -91,23 +91,9 @@ generator_fsck_after_pre_mount()
 }
 
 root=$(getarg root=)
-case "$root" in
-    block:LABEL=*|LABEL=*)
-        root="${root#block:}"
-        root="$(echo $root | sed 's,/,\\x2f,g')"
-        root="block:/dev/disk/by-label/${root#LABEL=}"
-        rootok=1 ;;
-    block:UUID=*|UUID=*)
-        root="${root#block:}"
-        root="block:/dev/disk/by-uuid/${root#UUID=}"
-        rootok=1 ;;
-    block:PARTUUID=*|PARTUUID=*)
-        root="${root#block:}"
-        root="block:/dev/disk/by-partuuid/${root#PARTUUID=}"
-        rootok=1 ;;
-    block:PARTLABEL=*|PARTLABEL=*)
-        root="${root#block:}"
-        root="block:/dev/disk/by-partlabel/${root#PARTLABEL=}"
+case "${root#block:}" in
+    LABEL=* | UUID=* | PARTUUID=* | PARTLABEL=*)
+        root="block:$(label_uuid_to_dev "$root")"
         rootok=1 ;;
     /dev/nfs) # ignore legacy /dev/nfs
         ;;
index 1699604c29ee2cbd3cc9bd03c1994dc8da410069..b8da85bfa2afd65a96ba2d42130af7f47a436803 100755 (executable)
@@ -55,16 +55,8 @@ mount_usr()
     while read _dev _mp _fs _opts _freq _passno || [ -n "$_dev" ]; do
         [ "${_dev%%#*}" != "$_dev" ] && continue
         if [ "$_mp" = "/usr" ]; then
-            case "$_dev" in
-                LABEL=*)
-                    _dev="$(echo $_dev | sed 's,/,\\x2f,g')"
-                    _dev="/dev/disk/by-label/${_dev#LABEL=}"
-                    ;;
-                UUID=*)
-                    _dev="${_dev#block:}"
-                    _dev="/dev/disk/by-uuid/${_dev#UUID=}"
-                    ;;
-            esac
+            _dev="$(label_uuid_to_dev "$_dev")"
+
             if strstr "$_opts" "subvol=" && \
                 [ "${root#block:}" -ef $_dev ] && \
                 [ -n "$rflags" ]; then
index c0b3e4aac92a0c36fd6292f35173dd35da1b4cab..b9be2b175cfad5d03c0621f80f737cc2eb0933a0 100755 (executable)
@@ -551,6 +551,25 @@ udevmatch() {
     esac
 }
 
+label_uuid_to_dev() {
+    local _dev
+    _dev="${1#block:}"
+    case "$_dev" in
+        LABEL=*)
+            echo "/dev/disk/by-label/$(echo "${_dev#LABEL=}" | sed 's,/,\\x2f,g;s, ,\\x20,g')"
+            ;;
+        PARTLABEL=*)
+            echo "/dev/disk/by-partlabel/$(echo "${_dev#PARTLABEL=}" | sed 's,/,\\x2f,g;s, ,\\x20,g')"
+            ;;
+        UUID=*)
+            echo "/dev/disk/by-uuid/$(echo "${_dev#UUID=}" | tr "[:upper:]" "[:lower:]")"
+            ;;
+        PARTUUID=*)
+            echo "/dev/disk/by-partuuid/$(echo "${_dev#PARTUUID=}" | tr "[:upper:]" "[:lower:]")"
+            ;;
+    esac
+}
+
 # Prints unique path for potential file inside specified directory.  It consists
 # of specified directory, prefix and number at the end which is incremented
 # until non-existing file is found.