ao-mud is a spellbook of well-commented atomic bash scripts that each do one thing. we are building semantic building blocks for an autonomously-evolving digital spellcasting language.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.7 KiB

#!/bin/sh
# Function to check if a package is installed in Debian-based distributions
is_deb_package_installed() {
dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed"
}
# Function to check if a package is installed in Redhat-based distributions
is_rpm_package_installed() {
rpm -q "$1" &> /dev/null
}
# Function to check if a package is installed in Arch-based distributions
is_arch_package_installed() {
pacman -Q "$1" &> /dev/null
}
2 years ago
# Uninstall Bitcoin from source
uninstall_bitcoin_from_source() {
2 years ago
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 && return 0
fi
return 1
2 years ago
}
2 years ago
# Remove Bitcoin binaries explicitly
remove_bitcoin_binaries() {
echo "Could not find Makefile. Uninstalling Bitcoin by removing binaries explicitly..."
2 years ago
bitcoin_bins="bitcoind bitcoin-tx bitcoin-wallet test_bitcoin bitcoin-cli bitcoin-qt bitcoin-util"
for bin in $bitcoin_bins; do
2 years ago
bin_path=$(which $bin)
[ -n "$bin_path" ] && sudo rm -f "$bin_path"
done
}
2 years ago
# Uninstall Bitcoin package
uninstall_bitcoin_package() {
2 years ago
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 remove -y bitcoin && return 0
2 years ago
fi
elif command -v dnf &> /dev/null; then
if is_rpm_package_installed bitcoin; then
sudo dnf remove -y bitcoin && return 0
2 years ago
fi
elif command -v pacman &> /dev/null; then
if is_arch_package_installed bitcoin; then
sudo pacman -Rns bitcoin --noconfirm && return 0
2 years ago
fi
elif command -v brew &> /dev/null; then
if brew list --cask bitcoin-core; then
brew uninstall --cask bitcoin-core && return 0
2 years ago
fi
else
2 years ago
echo "Unsupported package manager"
return 1
fi
return 1
}
2 years ago
# 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]* )
if ! uninstall_bitcoin_package; then
if ! uninstall_bitcoin_from_source; then
remove_bitcoin_binaries
fi
fi
;;
[Nn]* )
2 years ago
echo "Uninstallation cancelled"
;;
* )
2 years ago
echo "Invalid input. Please answer with Y (yes) or N (no)"
uninstall_bitcoin
;;
esac
}
# Start the uninstallation
uninstall_bitcoin