initial
This commit is contained in:
120
uninstall.sh
Normal file
120
uninstall.sh
Normal file
@@ -0,0 +1,120 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ModelGrid Uninstaller Script
|
||||
# Completely removes ModelGrid from the system
|
||||
|
||||
# Check if running as root
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo "Please run as root (sudo modelgrid uninstall or 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_REPO=yes|no - whether to remove the repository
|
||||
|
||||
# If not set through CLI, use defaults
|
||||
REMOVE_CONFIG=${REMOVE_CONFIG:-"no"}
|
||||
REMOVE_REPO=${REMOVE_REPO:-"no"}
|
||||
|
||||
echo "ModelGrid Uninstaller"
|
||||
echo "====================="
|
||||
echo "This will completely remove ModelGrid 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/modelgrid.service" ]; then
|
||||
echo "Stopping ModelGrid service..."
|
||||
systemctl stop modelgrid.service 2>/dev/null
|
||||
|
||||
echo "Disabling ModelGrid service..."
|
||||
systemctl disable modelgrid.service 2>/dev/null
|
||||
|
||||
echo "Removing systemd service file..."
|
||||
rm -f /etc/systemd/system/modelgrid.service
|
||||
|
||||
echo "Reloading systemd daemon..."
|
||||
systemctl daemon-reload
|
||||
fi
|
||||
|
||||
# Step 2: Remove global symlink
|
||||
if [ -L "/usr/local/bin/modelgrid" ]; then
|
||||
echo "Removing global symlink..."
|
||||
rm -f /usr/local/bin/modelgrid
|
||||
fi
|
||||
|
||||
if [ -L "/usr/bin/modelgrid" ]; then
|
||||
echo "Removing global symlink..."
|
||||
rm -f /usr/bin/modelgrid
|
||||
fi
|
||||
|
||||
# Step 3: Remove installation directory
|
||||
if [ -d "/opt/modelgrid" ]; then
|
||||
echo "Removing installation directory..."
|
||||
rm -rf /opt/modelgrid
|
||||
fi
|
||||
|
||||
# Step 4: Remove configuration if requested
|
||||
if [ "$REMOVE_CONFIG" = "yes" ]; then
|
||||
echo "Removing configuration files..."
|
||||
rm -rf /etc/modelgrid
|
||||
else
|
||||
# If not called through CLI, ask user
|
||||
if [ -z "$MODELGRID_CLI_CALL" ]; then
|
||||
read -p "Do you want to remove the ModelGrid configuration files? (y/N) " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo "Removing configuration files..."
|
||||
rm -rf /etc/modelgrid
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Step 5: Remove repository if requested
|
||||
if [ "$REMOVE_REPO" = "yes" ]; then
|
||||
if [ -d "$SCRIPT_DIR/.git" ]; then
|
||||
echo "Removing ModelGrid repository directory..."
|
||||
|
||||
# Get parent directory to remove it after the script exits
|
||||
PARENT_DIR=$(dirname "$SCRIPT_DIR")
|
||||
REPO_NAME=$(basename "$SCRIPT_DIR")
|
||||
|
||||
# Create a temporary cleanup script
|
||||
CLEANUP_SCRIPT=$(mktemp)
|
||||
echo "#!/bin/bash" > "$CLEANUP_SCRIPT"
|
||||
echo "sleep 1" >> "$CLEANUP_SCRIPT"
|
||||
echo "rm -rf \"$SCRIPT_DIR\"" >> "$CLEANUP_SCRIPT"
|
||||
echo "echo \"ModelGrid repository has been removed.\"" >> "$CLEANUP_SCRIPT"
|
||||
chmod +x "$CLEANUP_SCRIPT"
|
||||
|
||||
# Run the cleanup script in the background
|
||||
nohup "$CLEANUP_SCRIPT" > /dev/null 2>&1 &
|
||||
|
||||
echo "ModelGrid repository will be removed after uninstaller exits."
|
||||
else
|
||||
echo "No git repository found."
|
||||
fi
|
||||
else
|
||||
# If not requested, just display info
|
||||
if [ -d "$SCRIPT_DIR/.git" ]; then
|
||||
echo
|
||||
echo "ModelGrid repository at $SCRIPT_DIR will remain intact."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check for npm global installation
|
||||
NODE_PATH=$(which node 2>/dev/null)
|
||||
if [ -n "$NODE_PATH" ]; then
|
||||
NPM_PATH=$(dirname "$NODE_PATH")/npm
|
||||
if [ -x "$NPM_PATH" ]; then
|
||||
echo
|
||||
echo "If you installed ModelGrid via npm, you may want to uninstall it with:"
|
||||
echo " npm uninstall -g @modelgrid.com/modelgrid"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "ModelGrid has been uninstalled from your system."
|
||||
Reference in New Issue
Block a user