From f135e7cf36113eca7c5baed184527ac24337a459 Mon Sep 17 00:00:00 2001 From: "rleigh@debian.org" Date: Wed, 8 May 2013 23:27:02 +0100 Subject: functions: Add resolve_device function This is generalising the root-specific functionality in init. --- scripts/functions | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'scripts/functions') diff --git a/scripts/functions b/scripts/functions index 81946d0..2122be6 100644 --- a/scripts/functions +++ b/scripts/functions @@ -457,3 +457,43 @@ read_fstab_entry() { return $found } + +# Resolve device node from a name. This expands any LABEL or UUID. +# $1=name +# Resolved name is echoed. +resolve_device() { + DEV="$1" + + case $DEV in + LABEL=*) + DEV="${DEV#LABEL=}" + + # support any / in LABEL= path (escape to \x2f) + case "${DEV}" in + */*) + if command -v sed >/dev/null 2>&1; then + DEV="$(echo ${DEV} | sed 's,/,\\x2f,g')" + else + if [ "${DEV}" != "${DEV#/}" ]; then + DEV="\x2f${DEV#/}" + fi + if [ "${DEV}" != "${DEV%/}" ]; then + DEV="${DEV%/}\x2f" + fi + IFS='/' + newroot= + for s in $DEV; do + newroot="${newroot:+${newroot}\\x2f}${s}" + done + unset IFS + DEV="${newroot}" + fi + esac + DEV="/dev/disk/by-label/${DEV}" + ;; + UUID=*) + DEV="/dev/disk/by-uuid/${DEV#UUID=}" + ;; + esac + echo "$DEV" +} -- cgit v1.2.3