summaryrefslogtreecommitdiffstats
path: root/src/yum/test/test_common.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/yum/test/test_common.sh')
-rw-r--r--src/yum/test/test_common.sh80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/yum/test/test_common.sh b/src/yum/test/test_common.sh
new file mode 100644
index 0000000..25d931f
--- /dev/null
+++ b/src/yum/test/test_common.sh
@@ -0,0 +1,80 @@
+#!/bin/bash
+
+if [ -z $CLASS_NAME ]; then
+ echo "variable CLASS_NAME must be defined"
+ exit 1
+fi
+
+
+url="http://localhost:5988/root/cimv2"
+op="${url}:${cls}"
+
+fedora_release=`sed 's/Fedora release\s*\([0-9]\+\).*/\1/' \
+ /etc/fedora-release`
+
+function make_nevra() {
+ # accepts arguments: name, epoch, ver, rel, arch
+ # in this order
+ printf "%s-%s:%s-%s.%s" $@
+}
+
+function make_rpm_name() {
+ local name epoch ver rel arch;
+ if [ $# -ge 5 ]; then
+ read name epoch ver rel arch <<< "$@"
+ else
+ read name ver rel arch <<< "$@"
+ fi
+ [ $# -gt 5 ] && arch=`echo $arch | cut -d \ -f 1`
+ if [ -n "$epoch" -a "$epoch" != 0 ]; then
+ epoch="${epoch}:"
+ else
+ epoch=""
+ fi
+ printf "%s-%s%s-%s.%s.rpm" "$name" "$epoch" "$ver" "$rel" "$arch"
+}
+
+function is_installed() {
+ rpm -q "$1" >/dev/null
+}
+
+function is_installed_nevra() {
+ local name epoch ver rel arch;
+ read name epoch ver rel arch <<< "$@"
+
+ rpm -qi name | sed -n 's/^\(Name\|Epoch\|Version\|Release\|Architecture\)\s*:\s*\(.*\)/\1 \2/p' | \
+ while read l; do
+ read k v <<< "$l"
+ read ${k,,} <<< "$v"
+ [ $k == "version" ] && [ -z "$epoch" ] && echo "0" # print epoch
+ echo $v
+ done | set --
+ [ $epoch == $2 ] && [ $ver == $3 ] && [ $rel == $4 ] && [ $arch == $5 ]
+}
+
+function install_pkg() {
+ if [ $# == 1 ]; then
+ sudo yum -y install $1 || exit 1
+ else
+ local rpm_name=`make_rpm_name "$@"`
+ if ! [ -f "$rpm_name" ]; then
+ if [ -f "$dir/$rpm_name" ]; then
+ rpm_name="$dir/$rpm_name"
+ fi
+ fi
+ if ! [ -e "$rpm_name" ]; then
+ sudo yum -y install "$1"
+ else
+ sudo rpm -i "$rpm_name"
+ fi
+ fi
+}
+
+function remove() {
+ sudo rpm --allmatches -e "$1"
+}
+
+function wbemerr() {
+ wbemcli "$@" |& sed 's:<br\s*/\?>:\n:g'
+}
+