From 36c20230b89e78780ae3ff6ca9dae52e3799f212 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Fri, 29 Jul 2016 15:27:13 +0200 Subject: [PATCH] optimize the usage of explorers for __filesystem --- .../type/__filesystem/explorer/blkdev_fstype | 38 ------------------- .../type/__filesystem/explorer/blkdev_label | 38 ------------------- .../__filesystem/explorer/blkdev_mountpoint | 38 ------------------- .../explorer/{blkdev_devname => lsblk} | 3 +- cdist/conf/type/__filesystem/gencode-remote | 9 +++-- 5 files changed, 7 insertions(+), 119 deletions(-) delete mode 100644 cdist/conf/type/__filesystem/explorer/blkdev_fstype delete mode 100644 cdist/conf/type/__filesystem/explorer/blkdev_label delete mode 100644 cdist/conf/type/__filesystem/explorer/blkdev_mountpoint rename cdist/conf/type/__filesystem/explorer/{blkdev_devname => lsblk} (86%) diff --git a/cdist/conf/type/__filesystem/explorer/blkdev_fstype b/cdist/conf/type/__filesystem/explorer/blkdev_fstype deleted file mode 100644 index 3f92142f..00000000 --- a/cdist/conf/type/__filesystem/explorer/blkdev_fstype +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh -# -# 2016 - 2016 Daniel Heule (hda at sfs.biz) -# -# This file is part of cdist. -# -# cdist is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# cdist is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with cdist. If not, see . -# - -os=$("$__explorer/os") - -blkdev="$(cat "$__object/parameter/blkdev")" - -case "$os" in - centos|fedora|redhat|suse|gentoo) - if [ ! -x "$(command -v lsblk)" ]; then - echo "lsblk is required for __filesystem type" >&2 - exit 1 - else - echo -n $(lsblk -n -o FSTYPE "$blkdev" 2>/dev/null) - fi - ;; - *) - echo "__filesystem type lacks implementation for os: $os" >&2 - exit 1 - ;; -esac diff --git a/cdist/conf/type/__filesystem/explorer/blkdev_label b/cdist/conf/type/__filesystem/explorer/blkdev_label deleted file mode 100644 index aa227cab..00000000 --- a/cdist/conf/type/__filesystem/explorer/blkdev_label +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh -# -# 2016 - 2016 Daniel Heule (hda at sfs.biz) -# -# This file is part of cdist. -# -# cdist is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# cdist is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with cdist. If not, see . -# - -os=$("$__explorer/os") - -blkdev="$(cat "$__object/parameter/blkdev")" - -case "$os" in - centos|fedora|redhat|suse|gentoo) - if [ ! -x "$(command -v lsblk)" ]; then - echo "lsblk is required for __filesystem type" >&2 - exit 1 - else - echo -n $(lsblk -n -o LABEL "$blkdev" 2>/dev/null) - fi - ;; - *) - echo "__filesystem type lacks implementation for os: $os" >&2 - exit 1 - ;; -esac diff --git a/cdist/conf/type/__filesystem/explorer/blkdev_mountpoint b/cdist/conf/type/__filesystem/explorer/blkdev_mountpoint deleted file mode 100644 index 1cef068c..00000000 --- a/cdist/conf/type/__filesystem/explorer/blkdev_mountpoint +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh -# -# 2016 - 2016 Daniel Heule (hda at sfs.biz) -# -# This file is part of cdist. -# -# cdist is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# cdist is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with cdist. If not, see . -# - -os=$("$__explorer/os") - -blkdev="$(cat "$__object/parameter/blkdev")" - -case "$os" in - centos|fedora|redhat|suse|gentoo) - if [ ! -x "$(command -v lsblk)" ]; then - echo "lsblk is required for __filesystem type" >&2 - exit 1 - else - echo -n $(lsblk -n -o MOUNTPOINT "$blkdev" 2>/dev/null) - fi - ;; - *) - echo "__filesystem type lacks implementation for os: $os" >&2 - exit 1 - ;; -esac diff --git a/cdist/conf/type/__filesystem/explorer/blkdev_devname b/cdist/conf/type/__filesystem/explorer/lsblk similarity index 86% rename from cdist/conf/type/__filesystem/explorer/blkdev_devname rename to cdist/conf/type/__filesystem/explorer/lsblk index 30c8409a..87f95e90 100644 --- a/cdist/conf/type/__filesystem/explorer/blkdev_devname +++ b/cdist/conf/type/__filesystem/explorer/lsblk @@ -28,7 +28,8 @@ case "$os" in echo "lsblk is required for __filesystem type" >&2 exit 1 else - echo -n $(lsblk -n -o NAME "$blkdev" 2>/dev/null) + #echo -n $(lsblk -nd -P -o NAME,FSTYPE,LABEL,MOUNTPOINT "$blkdev" 2>/dev/null) + lsblk -nd -P -o NAME,FSTYPE,LABEL,MOUNTPOINT "$blkdev" 2>/dev/null fi ;; *) diff --git a/cdist/conf/type/__filesystem/gencode-remote b/cdist/conf/type/__filesystem/gencode-remote index 9d134dcc..feb7098d 100644 --- a/cdist/conf/type/__filesystem/gencode-remote +++ b/cdist/conf/type/__filesystem/gencode-remote @@ -34,10 +34,11 @@ else fi -blkdev_devname="$(cat "$__object/explorer/blkdev_devname")" -blkdev_fstype="$(cat "$__object/explorer/blkdev_fstype")" -blkdev_label="$(cat "$__object/explorer/blkdev_label")" -blkdev_mountpoint="$(cat "$__object/explorer/blkdev_mountpoint")" + +blkdev_devname="$(grep -P -o2 'NAME="\K[^"]*' "$__object/explorer/lsblk")" +blkdev_fstype="$(grep -P -o2 'FSTYPE="\K[^"]*' "$__object/explorer/lsblk")" +blkdev_label="$(grep -P -o2 'LABEL="\K[^"]*' "$__object/explorer/lsblk")" +blkdev_mountpoint="$(grep -P -o2 'MOUNTPOINT="\K[^"]*' "$__object/explorer/lsblk")" if [ -z "$blkdev_devname" ]; then echo "Specified device $mydev not found on target system" >&2