Move depencies checking before args parsing

This commit also adds bc(1) to the dependencies
list and fixed some comments.
This commit is contained in:
Alexis Ben Miloud--Josselin 2018-08-02 18:04:28 +02:00
parent cfa1cf2261
commit 93fc44aa06
1 changed files with 11 additions and 11 deletions

View File

@ -1,16 +1,25 @@
#!/bin/sh
# NOTE: kvmstats relies on the hxselect command to parse virsh' xml
# NOTE: kvmstats relies on the hxselect(1) command to parse virsh' xml
# files. On Debian, this command is provided by the 'html-xml-utils'
# package.
set -e -u
usage () {
echo 'usage: kvmstats.sh [-u K|M|G]'
echo 'usage: kvmstats.sh [-a] [-u K|M|G]'
exit 1
}
for DEP in hxselect lvs tempfile bc
do
if [ -z "$(which $DEP)" ]
then
echo "kvmstats.sh: $DEP not found in \$PATH" 1>&2
exit 1
fi
done
POW=$(echo 1024 ^ 3 | bc)
while [ $# -ne 0 ] && echo "$1" | grep -q '^-[[:alnum:]]'
do
@ -42,15 +51,6 @@ done
# since libvirt seems to store memoy in KiB, POW must be lowered by 1
POW=$((POW / 1024))
for DEP in hxselect lvs tempfile
do
if [ -z "$(which $DEP)" ]
then
echo "kvmstats.sh: $DEP not found in \$PATH" 1>&2
exit 1
fi
done
TMPFILE=$(tempfile -s kvmstats)
LVSOUT=$(tempfile -s kvmstats)