aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-08-11 23:19:21 (GMT)
committerDave Reisner <dreisner@archlinux.org>2012-08-11 23:19:21 (GMT)
commite2382e7ed838747052355527c87be6763c581ba2 (patch)
tree72b9b860ee6ee47dd81152a5de89b46adbb59e71
parenta969f05ed3ead0f422c14dd750197f201f7ebb15 (diff)
downloadinitscripts-e2382e7ed838747052355527c87be6763c581ba2.tar.xz
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 <dreisner@archlinux.org>
-rw-r--r--functions19
1 files 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