Files
scylladb/unified/uninstall.sh
Avi Kivity cf72c31617 treewide: improve bash error reporting
bash error handling and reporting is atrocious. Without -e it will
just ignore errors. With -e it will stop on errors, but not report
where the error happened (apart from exiting itself with an error code).

Improve that with the `trap ERR` command. Note that this won't be invoked
on intentional error exit with `exit 1`.

We apply this on every bash script that contains -e or that it appears
trivial to set it in. Non-trivial scripts without -e are left unmodified,
since they might intentionally invoke failing scripts.

Closes scylladb/scylladb#22747
2025-02-10 18:28:52 +03:00

83 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
#
# Copyright (C) 2020-present ScyllaDB
#
#
# SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
#
set -e
trap 'echo "error $? in $0 line $LINENO"' ERR
if [ -z "$BASH_VERSION" ]; then
echo "Unsupported shell, please run this script on bash."
exit 1
fi
# change directory to the package's root directory
cd "$(dirname "$0")"
# just used for keep same code style with install.sh
root=/
prefix=`realpath -m "$(dirname "$0")"`
if [ ! -f "$prefix/SCYLLA-OFFLINE-FILE" ]; then
echo "Does not found installed Scylla image at $prefix."
exit 1
fi
if [ -f "$prefix/SCYLLA-NONROOT-FILE" ]; then
nonroot=true
else
nonroot=false
fi
rprefix=$(realpath -m "$root/$prefix")
if ! $nonroot; then
# detect sysconfdir
if [ -f /etc/default/scylla-server ]; then
sysconfdir=/etc/default
else
sysconfdir=/etc/sysconfig
fi
retc="$root/etc"
rsysconfdir="$root/$sysconfdir"
rusr="$root/usr"
rsystemd="$rusr/lib/systemd/system"
rdoc="$rprefix/share/doc"
rdata="$root/var/lib/scylla"
rhkdata="$root/var/lib/scylla-housekeeping"
else
sysconfdir=/etc/sysconfig
retc="$rprefix/etc"
rsysconfdir="$rprefix/$sysconfdir"
rsystemd="$HOME/.config/systemd/user"
rdoc="$rprefix/share/doc"
rdata="$rprefix"
fi
rm -fv "$rsystemd"/{scylla-*.service,scylla-*.timer,scylla-*.slice}
if ! $nonroot; then
rm -rfv "$retc"/systemd/system/scylla-*.service.d
rm -fv "$retc"/bash_completion.d/nodetool-completion
rm -fv "$retc"/supervisord.d/scylla-*.ini
rm -fv "$rusr"/lib/sysctl.d/99-scylla-*.conf
rm -fv "$rusr"/bin/{scylla,iotune,scyllatop}
rm -fv "$rusr"/sbin/{scylla_*setup,node_exporter_install,node_health_check,scylla_ec2_check,scylla_kernel_check}
find "$rusr"/lib/scylla -type l -exec rm -fv {} \;
else
rm -rfv "$rsystemd"/scylla-*.service.d
fi
rm -rfv "$rprefix"
if ! $nonroot; then
systemctl daemon-reload
else
systemctl --user daemon-reload
fi
echo "Scylla uninstall completed."