From 67957577fc72e772a556eced037b8df8ebaf5bbd Mon Sep 17 00:00:00 2001 From: Chase Qi Date: Mon, 12 Nov 2018 17:45:31 +0800 Subject: sh-test-lib: add remove_pkgs() Change-Id: I4f45cf42cb8c96687168126631e0525d32121aa0 Signed-off-by: Chase Qi --- automated/lib/sh-test-lib | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/automated/lib/sh-test-lib b/automated/lib/sh-test-lib index bf72984..c71a884 100755 --- a/automated/lib/sh-test-lib +++ b/automated/lib/sh-test-lib @@ -234,6 +234,31 @@ install_deps() { fi } +remove_pkgs() { + pkgs="$1" + [ -z "${pkgs}" ] && error_msg "Usage: remove_pkgs pkgs" + ! check_root && error_msg "remove_pkgs() requires root permission." + info_msg "Removing ${pkgs} ..." + dist_name + case "${dist}" in + debian|ubuntu) + # shellcheck disable=SC2086 + DEBIAN_FRONTEND=noninteractive apt-get -y purge ${pkgs} + ;; + centos) + # shellcheck disable=SC2086 + yum -y remove ${pkgs} + ;; + fedora) + # shellcheck disable=SC2086 + dnf -y remove ${pkgs} + ;; + *) + warn_msg "Unsupported distro: ${dist}! Package uninstallation skipped." + ;; + esac +} + # Return the exit code of the first command when using pipe. pipe0_status() { [ "$#" -ne 2 ] && error_msg "Usage: pipe0_status cmd1 cmd2" -- cgit v1.2.3