Browse Source

refactored

main
deicidus 2 years ago
parent
commit
a49a0ac43a
  1. 65
      spells/menu/bitcoin/uninstall-bitcoin

65
spells/menu/bitcoin/uninstall-bitcoin

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

Loading…
Cancel
Save