#!/bin/bash # # Script to uninstall MyTimeline plugin from snap-installed Gramps # # This script removes the MyTimeline plugin files from the Gramps snap plugin directory # set -euo pipefail # Exit on error, undefined vars, pipe failures # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Plugin files to remove PLUGIN_FILES=("MyTimeline.gpr.py" "MyTimeline.py") # Target directory for snap-installed Gramps PLUGIN_DEST_DIR="$HOME/snap/gramps/current/.local/share/gramps/gramps60/plugins" # Alternative locations to try ALTERNATIVE_DIRS=( "$HOME/snap/gramps/current/.local/share/gramps/gramps60/plugins" "$HOME/snap/gramps/current/.gramps/gramps60/plugins" "$HOME/snap/gramps/current/.gramps/plugins" "$HOME/snap/gramps/common/.local/share/gramps/gramps60/plugins" "$HOME/.local/share/gramps/gramps60/plugins" "$HOME/.gramps/gramps60/plugins" ) echo "==========================================" echo "MyTimeline Plugin Uninstaller for Snap Gramps" echo "==========================================" echo "" # Function to find the correct plugin directory find_plugin_dir() { # Try the primary location first if [ -d "$PLUGIN_DEST_DIR" ]; then echo "$PLUGIN_DEST_DIR" return 0 fi # Try alternative locations for dir in "${ALTERNATIVE_DIRS[@]}"; do if [ -d "$dir" ]; then echo "$dir" return 0 fi done return 1 } # Find the target directory echo "Locating Gramps plugin directory..." TARGET_DIR=$(find_plugin_dir) if [ -z "$TARGET_DIR" ]; then echo -e "${YELLOW}Warning: Plugin directory not found.${NC}" echo "The plugin may already be uninstalled or Gramps may not be installed via snap." echo "" echo -e "${BLUE}Note:${NC} If you installed the plugin manually, you may need to remove it manually." echo "Common locations to check:" for dir in "${ALTERNATIVE_DIRS[@]}"; do echo " - $dir" done exit 0 fi echo -e "${GREEN}✓${NC} Target directory: $TARGET_DIR" echo "" # Check if plugin files exist FILES_FOUND=0 FILES_REMOVED=0 for file in "${PLUGIN_FILES[@]}"; do if [ -f "$TARGET_DIR/$file" ]; then FILES_FOUND=$((FILES_FOUND + 1)) fi done if [ $FILES_FOUND -eq 0 ]; then echo -e "${YELLOW}No plugin files found. The plugin may already be uninstalled.${NC}" exit 0 fi echo "Found $FILES_FOUND plugin file(s)." echo "" # Remove plugin files echo "Removing plugin files..." for file in "${PLUGIN_FILES[@]}"; do if [ -f "$TARGET_DIR/$file" ]; then if ! rm "$TARGET_DIR/$file"; then echo -e "${RED}Error: Failed to remove $file${NC}" echo "Check file permissions." exit 1 fi echo -e "${GREEN}✓${NC} Removed: $file" FILES_REMOVED=$((FILES_REMOVED + 1)) fi done # Remove backup directories created by the installer BACKUP_DIRS_REMOVED=0 echo "" echo "Searching for backup directories..." for backup_dir in "$TARGET_DIR"/mytimeline_backup_*; do if [ -d "$backup_dir" ]; then echo "Found backup directory: $(basename "$backup_dir")" rm -rf "$backup_dir" echo -e "${GREEN}✓${NC} Removed backup directory: $(basename "$backup_dir")" BACKUP_DIRS_REMOVED=$((BACKUP_DIRS_REMOVED + 1)) fi done # Also check for any plugin files in subdirectories that might be loaded echo "" echo "Checking for plugin files in subdirectories..." SUBDIR_FILES_REMOVED=0 for subdir in "$TARGET_DIR"/*; do if [ -d "$subdir" ]; then for file in "${PLUGIN_FILES[@]}"; do if [ -f "$subdir/$file" ]; then echo -e "${YELLOW}Warning: Found $file in subdirectory: $(basename "$subdir")${NC}" rm -f "$subdir/$file" echo -e "${GREEN}✓${NC} Removed: $(basename "$subdir")/$file" SUBDIR_FILES_REMOVED=$((SUBDIR_FILES_REMOVED + 1)) fi done fi done TOTAL_REMOVED=$((FILES_REMOVED + BACKUP_DIRS_REMOVED + SUBDIR_FILES_REMOVED)) echo "" echo "==========================================" if [ $TOTAL_REMOVED -gt 0 ]; then echo -e "${GREEN}Uninstallation completed successfully!${NC}" echo "==========================================" echo "" echo "Removed:" echo " - $FILES_REMOVED plugin file(s) from main directory" if [ $BACKUP_DIRS_REMOVED -gt 0 ]; then echo " - $BACKUP_DIRS_REMOVED backup directory/directories" fi if [ $SUBDIR_FILES_REMOVED -gt 0 ]; then echo " - $SUBDIR_FILES_REMOVED plugin file(s) from subdirectories" fi echo "" echo "Location: $TARGET_DIR" echo "" echo "Next steps:" echo " 1. Restart Gramps if it's currently running" echo " 2. The plugin should no longer appear in the Plugins menu" else echo -e "${YELLOW}No files or directories were removed.${NC}" echo "==========================================" fi echo ""