summaryrefslogtreecommitdiff
path: root/scripts/functions
diff options
context:
space:
mode:
authorrleigh@debian.org <rleigh@debian.org>2013-05-08 23:27:02 +0100
committerMichael Prokop <mika@debian.org>2014-09-25 08:37:00 +0200
commitf135e7cf36113eca7c5baed184527ac24337a459 (patch)
tree5a8abb89389ae090577d67403c765c2e01bbca30 /scripts/functions
parent8d63dd5e1e53a1a45e7efb6da8dd58d650cec4f3 (diff)
functions: Add resolve_device function
This is generalising the root-specific functionality in init.
Diffstat (limited to 'scripts/functions')
-rw-r--r--scripts/functions40
1 files changed, 40 insertions, 0 deletions
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"
+}