summaryrefslogtreecommitdiff
path: root/automated/lib
diff options
context:
space:
mode:
Diffstat (limited to 'automated/lib')
-rwxr-xr-xautomated/lib/sh-test-lib19
1 files changed, 19 insertions, 0 deletions
diff --git a/automated/lib/sh-test-lib b/automated/lib/sh-test-lib
index e4f4b8a..b0fa164 100755
--- a/automated/lib/sh-test-lib
+++ b/automated/lib/sh-test-lib
@@ -178,3 +178,22 @@ validate_check_sum() {
return 1
fi
}
+
+convert_to_mb() {
+ [ "$#" -ne 2 ] && error_msg "Usage: convert_to_mb value units"
+ if ! echo "$1" | egrep -q "^[0-9.]+$"; then
+ error_msg "The first argument isn't a number"
+ fi
+ local value="$1"
+ local units="$2"
+
+ case "${units}" in
+ KB|kb) value=$(echo "${value}" | awk '{print $1/1024}') ;;
+ MB|mb) ;;
+ GB|gb) value=$(echo "${value}" | awk '{print $1*1024}') ;;
+ TB|tb) value=$(echo "${value}" | awk '{print $1*1024*1024}') ;;
+ *) error_msg "Unsupported units" ;;
+ esac
+
+ echo "${value}"
+}