diff options
author | Karel Zak | 2007-05-17 20:16:25 +0200 |
---|---|---|
committer | Karel Zak | 2007-05-18 13:09:12 +0200 |
commit | 3f5bda012d51a2935c3f2ce909c9080e4e3217c1 (patch) | |
tree | dec49fc8e463b74b7cdb46574fb5894c09474eac /tests/functions.sh | |
parent | tests: code refactoring -- new ts_udev_loop_support function (diff) | |
download | kernel-qcow2-util-linux-3f5bda012d51a2935c3f2ce909c9080e4e3217c1.tar.gz kernel-qcow2-util-linux-3f5bda012d51a2935c3f2ce909c9080e4e3217c1.tar.xz kernel-qcow2-util-linux-3f5bda012d51a2935c3f2ce909c9080e4e3217c1.zip |
tests: add functions for label, uuid and fstype detection
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'tests/functions.sh')
-rw-r--r-- | tests/functions.sh | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/tests/functions.sh b/tests/functions.sh index 6c0658b1b..7cb374306 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -111,4 +111,53 @@ function ts_udev_loop_support { return 0 } - +function ts_uuid_by_devname { + local DEV="$1" + local UUID="" + if [ -x "$TS_ECMD_BLKID" ]; then + UUID=$($TS_ECMD_BLKID -c /dev/null -w /dev/null -s "UUID" $DEV | sed 's/.*UUID="//g; s/"//g') + elif [ -x "$TS_ECMD_VOLID" ]; then + UUID=$($TS_ECMD_VOLID -u $DEV) + fi + echo $UUID +} + +function ts_label_by_devname { + local DEV="$1" + local TYPE="" + if [ -x "$TS_ECMD_BLKID" ]; then + LABEL=$($TS_ECMD_BLKID -c /dev/null -w /dev/null -s "LABEL" $DEV | sed 's/.*LABEL="//g; s/"//g') + elif [ -x "$TS_ECMD_VOLID" ]; then + LABEL=$($TS_ECMD_VOLID -l $DEV) + fi + echo $LABEL +} + +function ts_fstype_by_devname { + local DEV="$1" + local TYPE="" + if [ -x "$TS_ECMD_BLKID" ]; then + TYPE=$($TS_ECMD_BLKID -c /dev/null -w /dev/null -s "TYPE" $DEV | sed 's/.*TYPE="//g; s/"//g') + elif [ -x "$TS_ECMD_VOLID" ]; then + TYPE=$($TS_ECMD_VOLID -t $DEV) + fi + echo $TYPE +} + +function ts_device_has { + local TAG="$1" + local VAL="$2" + local DEV="$3" + + case $TAG in + "TYPE") vl=$(ts_fstype_by_devname $DEV);; + "LABEL") vl=$(ts_label_by_devname $DEV);; + "UUID") vl=$(ts_uuid_by_devname $DEV);; + *) return 1;; + esac + + if [ "$vl" == "$VAL" ]; then + return 0 + fi + return 1 +} |