#!/bin/bash

#  ____                      _                 _
# |  _ \  _____      ___ __ | | ___   __ _  __| |___
# | | | |/ _ \ \ /\ / / '_ \| |/ _ \ / _` |/ _` / __|
# | |_| | (_) \ V  V /| | | | | (_) | (_| | (_| \__ \
# |____/ \___/ \_/\_/ |_| |_|_|\___/ \__,_|\__,_|___/
#  / _ \ _ __ __ _  __ _ _ __ (_)_______ _ __
# | | | | '__/ _` |/ _` | '_ \| |_  / _ \ '__|
# | |_| | | | (_| | (_| | | | | |/ /  __/ |
#  \___/|_|  \__, |\__,_|_| |_|_/___\___|_|
#            |___/
#
# Author: Andrianos Papamarkou
#
# This script uninstalls the Downloads Organizer


# Define repository URL
REPO_URL="https://github.com/apapamarkou/downloads-organizer.git"

# Temporary project directory
TEMP_DIR="$HOME/downloads-organizer"

# Step 1: Clone the project from GitHub (to use the uninstall.sh script)
echo "Cloning Downloads Organizer repository for uninstallation..."
git clone "$REPO_URL" "$TEMP_DIR"

# Check if clone was successful
if [ ! -d "$TEMP_DIR" ]; then
  echo "Error: Failed to clone the repository."
  exit 1
fi

# Step 2: cd into the project directory
cd "$TEMP_DIR" || { echo "Error: Could not enter the project directory."; exit 1; }

# Step 3: Make uninstall.sh executable and run it
echo "Running the uninstaller..."
chmod +x uninstall.sh
./uninstall.sh

# Step 4: Clean up (remove the cloned project directory)
echo "Cleaning up..."
cd ..
rm -rf "$TEMP_DIR"

# Completion message
echo "Downloads Organizer has been uninstalled and the project directory cleaned up."
