Files
simulation/scripts/uninstall.sh
2026-02-09 04:52:32 +00:00

151 lines
4.3 KiB
Bash
Executable File

#!/bin/bash
# =============================================================================
# UAV-UGV Simulation - Uninstall Script
# =============================================================================
# Removes ArduPilot, ardupilot_gazebo, and project files
# Does NOT remove ROS 2 or Gazebo (system packages)
#
# Usage:
# ./scripts/uninstall.sh # Remove ArduPilot and plugin only
# ./scripts/uninstall.sh --all # Remove everything including project
# =============================================================================
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
ARDUPILOT_HOME="$HOME/ardupilot"
ARDUPILOT_GZ="$HOME/ardupilot_gazebo"
echo -e "${BLUE}==========================================${NC}"
echo -e "${BLUE} UAV-UGV Simulation - Uninstall${NC}"
echo -e "${BLUE}==========================================${NC}"
echo ""
# Parse arguments
REMOVE_ALL=false
FORCE=false
for arg in "$@"; do
case $arg in
--all)
REMOVE_ALL=true
;;
--force|-f)
FORCE=true
;;
--help)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --all Remove everything (ArduPilot, plugin, project, venv)"
echo " --force Skip confirmation prompts"
echo " --help Show this help"
echo ""
echo "Note: ROS 2 and Gazebo are NOT removed (use apt to remove)"
exit 0
;;
esac
done
# Confirmation
if [ "$FORCE" = false ]; then
echo "This will remove:"
echo " - ArduPilot SITL ($ARDUPILOT_HOME)"
echo " - ardupilot_gazebo ($ARDUPILOT_GZ)"
echo " - Python virtual environment ($PROJECT_DIR/venv)"
if [ "$REMOVE_ALL" = true ]; then
echo " - Project directory ($PROJECT_DIR)"
fi
echo ""
echo "ROS 2 and Gazebo will NOT be removed."
echo ""
read -p "Continue? (y/N): " confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
echo "Cancelled."
exit 0
fi
fi
echo ""
# Kill running processes
echo -e "${YELLOW}Stopping running processes...${NC}"
pkill -f "sim_vehicle.py" 2>/dev/null || true
pkill -f "mavproxy" 2>/dev/null || true
pkill -f "arducopter" 2>/dev/null || true
pkill -f "ardurover" 2>/dev/null || true
pkill -f "gz sim" 2>/dev/null || true
pkill -f "gzserver" 2>/dev/null || true
pkill -f "gzclient" 2>/dev/null || true
sleep 1
# Remove ArduPilot
if [ -d "$ARDUPILOT_HOME" ]; then
echo -e "${YELLOW}Removing ArduPilot ($ARDUPILOT_HOME)...${NC}"
rm -rf "$ARDUPILOT_HOME"
echo -e "${GREEN}Removed ArduPilot${NC}"
else
echo "ArduPilot not found at $ARDUPILOT_HOME"
fi
# Remove ardupilot_gazebo
if [ -d "$ARDUPILOT_GZ" ]; then
echo -e "${YELLOW}Removing ardupilot_gazebo ($ARDUPILOT_GZ)...${NC}"
rm -rf "$ARDUPILOT_GZ"
echo -e "${GREEN}Removed ardupilot_gazebo${NC}"
else
echo "ardupilot_gazebo not found at $ARDUPILOT_GZ"
fi
# Remove Python venv
if [ -d "$PROJECT_DIR/venv" ]; then
echo -e "${YELLOW}Removing Python virtual environment...${NC}"
rm -rf "$PROJECT_DIR/venv"
echo -e "${GREEN}Removed venv${NC}"
fi
# Remove generated files
rm -f "$PROJECT_DIR/activate_venv.sh" 2>/dev/null || true
rm -f "$PROJECT_DIR/wsl_env.sh" 2>/dev/null || true
# Remove ArduPilot environment files
rm -f "$HOME/.ardupilot_env" 2>/dev/null || true
# Remove pip user packages
echo -e "${YELLOW}Removing user pip packages (mavproxy, pymavlink)...${NC}"
pip3 uninstall -y mavproxy pymavlink pexpect 2>/dev/null || true
# Remove project directory if --all
if [ "$REMOVE_ALL" = true ]; then
echo -e "${YELLOW}Removing project directory ($PROJECT_DIR)...${NC}"
cd "$HOME"
rm -rf "$PROJECT_DIR"
echo -e "${GREEN}Removed project directory${NC}"
fi
echo ""
echo -e "${GREEN}==========================================${NC}"
echo -e "${GREEN} Uninstall Complete${NC}"
echo -e "${GREEN}==========================================${NC}"
echo ""
echo "Removed:"
echo " - ArduPilot SITL"
echo " - ardupilot_gazebo plugin"
echo " - Python virtual environment"
if [ "$REMOVE_ALL" = true ]; then
echo " - Project directory"
fi
echo ""
echo "NOT removed (use apt if needed):"
echo " - ROS 2: sudo apt remove ros-*"
echo " - Gazebo: sudo apt remove gz-*"
echo ""