Files
spark/uninstall.sh
T

140 lines
4.1 KiB
Bash
Raw Normal View History

#!/bin/bash
# SPARK Uninstaller Script
# Completely removes SPARK from the system
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root (sudo ./uninstall.sh)"
exit 1
fi
# This script can be called directly or through the CLI
# When called through the CLI, environment variables are set
# REMOVE_CONFIG=yes|no - whether to remove configuration files
# REMOVE_DATA=yes|no - whether to remove data files
# If not set through CLI, use defaults
REMOVE_CONFIG=${REMOVE_CONFIG:-"no"}
REMOVE_DATA=${REMOVE_DATA:-"no"}
echo "SPARK Uninstaller"
echo "================="
echo "This will completely remove SPARK from your system."
# Find the directory where this script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# Step 1: Stop and disable the systemd service if it exists
if [ -f "/etc/systemd/system/spark.service" ]; then
echo "Stopping SPARK service..."
systemctl stop spark.service 2>/dev/null
echo "Disabling SPARK service..."
systemctl disable spark.service 2>/dev/null
echo "Removing systemd service file..."
rm -f /etc/systemd/system/spark.service
echo "Reloading systemd daemon..."
systemctl daemon-reload
fi
# Also check for legacy smartdaemon_spark service
if [ -f "/etc/systemd/system/smartdaemon_spark.service" ]; then
echo "Stopping legacy smartdaemon_spark service..."
systemctl stop smartdaemon_spark.service 2>/dev/null
echo "Disabling legacy smartdaemon_spark service..."
systemctl disable smartdaemon_spark.service 2>/dev/null
echo "Removing legacy systemd service file..."
rm -f /etc/systemd/system/smartdaemon_spark.service
echo "Reloading systemd daemon..."
systemctl daemon-reload
fi
# Step 2: Remove global symlinks
if [ -L "/usr/local/bin/spark" ]; then
echo "Removing global symlink from /usr/local/bin/spark..."
rm -f /usr/local/bin/spark
fi
if [ -L "/usr/bin/spark" ]; then
echo "Removing global symlink from /usr/bin/spark..."
rm -f /usr/bin/spark
fi
# Step 3: Remove configuration if requested
if [ "$REMOVE_CONFIG" = "yes" ]; then
if [ -d "/etc/spark" ]; then
echo "Removing configuration directory /etc/spark..."
rm -rf /etc/spark
fi
else
if [ -d "/etc/spark" ]; then
echo "Configuration preserved in /etc/spark (use --remove-config to remove)"
fi
fi
# Step 4: Remove data if requested
if [ "$REMOVE_DATA" = "yes" ]; then
if [ -d "/var/lib/spark" ]; then
echo "Removing data directory /var/lib/spark..."
rm -rf /var/lib/spark
fi
if [ -d "/var/log/spark" ]; then
echo "Removing log directory /var/log/spark..."
rm -rf /var/log/spark
fi
else
if [ -d "/var/lib/spark" ] || [ -d "/var/log/spark" ]; then
echo "Data and logs preserved (use --remove-data to remove)"
fi
fi
# Step 5: Remove installation directory
if [ -d "/opt/spark" ]; then
echo "Removing installation directory /opt/spark..."
rm -rf /opt/spark
fi
# Step 6: Clean up Docker containers and images if any
echo "Checking for SPARK-managed Docker resources..."
# List all containers with spark labels
SPARK_CONTAINERS=$(docker ps -aq --filter "label=com.servezone.spark" 2>/dev/null)
if [ -n "$SPARK_CONTAINERS" ]; then
echo "Stopping and removing SPARK-managed containers..."
docker stop $SPARK_CONTAINERS 2>/dev/null
docker rm $SPARK_CONTAINERS 2>/dev/null
fi
echo ""
echo "================================================"
echo " SPARK Uninstallation Complete"
echo "================================================"
echo ""
echo "SPARK has been removed from your system."
if [ "$REMOVE_CONFIG" = "no" ] && [ -d "/etc/spark" ]; then
echo ""
echo "Configuration has been preserved in /etc/spark"
echo "To remove it, run: sudo rm -rf /etc/spark"
fi
if [ "$REMOVE_DATA" = "no" ]; then
if [ -d "/var/lib/spark" ] || [ -d "/var/log/spark" ]; then
echo ""
echo "Data and logs have been preserved in:"
[ -d "/var/lib/spark" ] && echo " - /var/lib/spark"
[ -d "/var/log/spark" ] && echo " - /var/log/spark"
echo "To remove them, run:"
[ -d "/var/lib/spark" ] && echo " sudo rm -rf /var/lib/spark"
[ -d "/var/log/spark" ] && echo " sudo rm -rf /var/log/spark"
fi
fi
echo ""
echo "Thank you for using SPARK!"
echo ""