Skip to content

Commit

Permalink
Fix uninstall option in installer script (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyc-splunk authored Mar 24, 2021
1 parent f2d0c18 commit 5169d0e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
48 changes: 33 additions & 15 deletions internal/buildscripts/packaging/installer/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ EOH
}

fluent_plugin_installed() {
local name="1"
local name="$1"

td-agent-gem list "$name" --exact | grep -q "$name"
}
Expand Down Expand Up @@ -444,26 +444,44 @@ install() {
uninstall() {
case "$distro" in
ubuntu|debian)
for agent in splunk-otel-collector td-agent; do
if command -v $agent >/dev/null 2>&1; then
apt-get remove $agent 2>&1
echo "Successfully removed $agent"
else
echo "Unable to locate $agent"
for agent in otelcol td-agent; do
if command -v $agent 2>&1 >/dev/null; then
pkg="$agent"
if [ "$agent" = "otelcol" ]; then
pkg="splunk-otel-collector"
fi
if dpkg -s $pkg 2>&1 >/dev/null; then
apt-get remove -y $pkg 2>&1
echo "Successfully removed the $pkg package"
else
agent_path="$( command -v agent )"
echo "$agent_path exists but the $pkg package is not installed" >&2
echo "$agent_path needs to be manually removed/uninstalled" >&2
exit 1
fi
fi
done
;;
amzn|centos|ol|rhel)
for agent in splunk-otel-collector td-agent; do
if command -v $agent >/dev/null 2>&1; then
if command -v yum >/dev/null 2>&1; then
yum remove $agent 2>&1
for agent in otelcol td-agent; do
if command -v $agent 2>&1 >/dev/null; then
pkg="$agent"
if [ "$agent" = "otelcol" ]; then
pkg="splunk-otel-collector"
fi
if rpm -q $pkg 2>&1 >/dev/null; then
if command -v yum >/dev/null 2>&1; then
yum remove -y $pkg 2>&1
else
dnf remove -y $pkg 2>&1
fi
echo "Successfully removed the $pkg package"
else
dnf remove $agent 2>&1
agent_path="$( command -v agent )"
echo "$agent_path exists but the $pkg package is not installed" >&2
echo "$agent_path needs to be manually removed/uninstalled" >&2
exit 1
fi
echo "Successfully removed $agent"
else
echo "Unable to locate $agent"
fi
done
;;
Expand Down
1 change: 1 addition & 0 deletions internal/buildscripts/packaging/tests/installer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def test_installer(distro, version, memory_option):
else:
assert container.exec_run("systemctl status td-agent").exit_code != 0

run_container_cmd(container, "sh -x /test/install.sh --uninstall")
finally:
run_container_cmd(container, "journalctl -u td-agent --no-pager")
if container.exec_run("test -f /var/log/td-agent/td-agent.log").exit_code == 0:
Expand Down

0 comments on commit 5169d0e

Please sign in to comment.