From e2382e7ed838747052355527c87be6763c581ba2 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sat, 11 Aug 2012 19:19:21 -0400 Subject: functions: support quoted UUID/PARTUUID in crypttab Abstract the unquoting logic from parse_envfile into unquote() and reuse it for our crypttab unlock logic. Signed-off-by: Dave Reisner --- functions | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/functions b/functions index e6b9af3..eb08ba6 100644 --- a/functions +++ b/functions @@ -72,9 +72,19 @@ unset TZ # sanitize the locale settings unset "${localevars[@]}" +unquote() { + local -r quotes=$'[\'"]' + + if [[ ${1:0:1} = $quotes && ${1:(-1)} = "${1:0:1}" ]]; then + printf '%s' "${1:1:(-1)}" + else + printf '%s' "$1" + fi +} + parse_envfile() { local file=$1 validkeys=("${@:2}") ret=0 lineno=0 key= val= - local -r quotes=$'[\'"]' comments=$'[;#]*' + local -r comments=$'[;#]*' if [[ -z $file ]]; then printf "error: no environment file specified\n" @@ -101,8 +111,7 @@ parse_envfile() { [[ -z $key || ${key:0:1} = $comments ]] && continue # trim whitespace, strip matching quotes - val=$(echo "$val" | { read -r val; echo "$val"; }) - [[ ${val:0:1} = $quotes && ${val:(-1)} = "${val:0:1}" ]] && val=${val:1:(-1)} + val=$(echo "$val" | { read -r val; unquote "$val"; }) if [[ -z $val ]]; then printf "error: found key \`%s' without value on line %s of %s\n" \ @@ -478,10 +487,10 @@ do_unlock_systemd() { # lazily convert tags to udev symlinks case $device in UUID=*) - device=/dev/disk/by-uuid/${device#UUID=} + device=/dev/disk/by-uuid/$(unquote "${device#UUID=}") ;; PARTUUID=*) - device=/dev/disk/by-partuuid/${device#PARTUUID=} + device=/dev/disk/by-partuuid/$(unquote "${device#PARTUUID=}") ;; esac -- cgit v1.2.3