diff --git a/spells/menu/bitcoin/uninstall-bitcoin b/spells/menu/bitcoin/uninstall-bitcoin index 7818ac8..5758b34 100755 --- a/spells/menu/bitcoin/uninstall-bitcoin +++ b/spells/menu/bitcoin/uninstall-bitcoin @@ -15,57 +15,66 @@ is_arch_package_installed() { pacman -Q "$1" &> /dev/null } -# Function to uninstall Bitcoin from source +# Uninstall Bitcoin from source uninstall_bitcoin_from_source() { - # Find the path to the bitcoin binary - bitcoin_bin=$(which bitcoin) - - if [ -z "$bitcoin_bin" ]; then - say "Could not find Bitcoin installed from source" + echo "Attempting to uninstall Bitcoin Core installed from source..." + make_directory=$(dirname "$(find / -name "Makefile.in" 2>/dev/null | grep "bitcoin")") + if [ -n "$make_directory" ]; then + cd "$make_directory" && sudo make uninstall > /dev/null 2>&1 + else return 1 fi +} - # Assume the parent directory of the binary is the source directory - bitcoin_src_dir=$(dirname "$bitcoin_bin") - - say "Uninstalling Bitcoin Core installed from source in $bitcoin_src_dir" - cd "$bitcoin_src_dir" - sudo make uninstall +# Remove Bitcoin binaries explicitly +remove_bitcoin_binaries() { + echo "Could not find Makefile. Uninstalling Bitcoin by removing binaries explicitly..." + bitcoin_bins=("bitcoind" "bitcoin-tx" "bitcoin-wallet" "test_bitcoin" "bitcoin-cli" "bitcoin-qt" "bitcoin-util") + for bin in "${bitcoin_bins[@]}"; do + bin_path=$(which $bin) + [ -n "$bin_path" ] && sudo rm -f "$bin_path" + done } -# Function to uninstall Bitcoin package +# Uninstall Bitcoin package uninstall_bitcoin_package() { - # Detect the operating system's package manager and uninstall - if command -v apt &> /dev/null && is_deb_package_installed bitcoin; then - say "Uninstalling Bitcoin Core package installed with apt" - sudo apt-get remove -y bitcoin - elif command -v dnf &> /dev/null && is_rpm_package_installed bitcoin; then - say "Uninstalling Bitcoin Core package installed with dnf" - sudo dnf remove -y bitcoin - elif command -v pacman &> /dev/null && is_arch_package_installed bitcoin; then - say "Uninstalling Bitcoin Core package installed with pacman" - sudo pacman -Rns bitcoin --noconfirm - elif command -v brew &> /dev/null && brew list --cask bitcoin-core; then - say "Uninstalling Bitcoin Core package installed with brew" - brew uninstall --cask bitcoin-core + echo "Attempting to uninstall Bitcoin Core package..." + + # Detect the operating system's package manager + if command -v apt &> /dev/null; then + if is_deb_package_installed bitcoin; then + sudo apt-get remove -y bitcoin + fi + elif command -v dnf &> /dev/null; then + if is_rpm_package_installed bitcoin; then + sudo dnf remove -y bitcoin + fi + elif command -v pacman &> /dev/null; then + if is_arch_package_installed bitcoin; then + sudo pacman -Rns bitcoin --noconfirm + fi + elif command -v brew &> /dev/null; then + if brew list --cask bitcoin-core; then + brew uninstall --cask bitcoin-core + fi else - # If no package manager is found, assume it was installed from source - uninstall_bitcoin_from_source + echo "Unsupported package manager" + exit 1 fi } -# Function to uninstall Bitcoin +# Uninstall Bitcoin uninstall_bitcoin() { read -p "This will uninstall Bitcoin Core and might delete your wallet data. Are you sure? (Y/n) " yn case $yn in [Yy]* ) - uninstall_bitcoin_package + uninstall_bitcoin_package || uninstall_bitcoin_from_source || remove_bitcoin_binaries ;; [Nn]* ) - say "Uninstallation cancelled" + echo "Uninstallation cancelled" ;; * ) - say "Invalid input. Please answer with Y (yes) or N (no)" + echo "Invalid input. Please answer with Y (yes) or N (no)" uninstall_bitcoin ;; esac