xmr.sh/uninstall
2022-06-01 19:11:46 +01:00

85 lines
2.4 KiB
Bash
Executable file

#!/bin/bash
################################################################
# Colors #
################################################################
# Reset
Off='\033[0m' # Text Reset
# Regular Colors
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
Yellow='\033[0;33m' # Yellow
Purple='\033[0;35m' # Purple
White='\033[0;37m' # White
# Background
On_Black='\033[40m' # Black
OkBullet="${Green}${On_Black}:: ${White}${On_Black}"
WarnBullet="${Yellow}${On_Black}:: ${White}${On_Black}"
ErrBullet="${Red}${On_Black}:: ${White}${On_Black}"
Ok="${Green}${On_Black} ok.${Off}"
Fail="${Red}${On_Black} failed!${Off}"
Nok="${Yellow}${On_Black} nok.${Off}"
################################################################
# Vars #
################################################################
XMRSH_DIR="/opt/xmr.sh"
XMRSH_LOG_FILE="/tmp/xmr.sh-$(date +%Y%m%d-%H%M%S).log"
################################################################
# Functions #
################################################################
check_root() {
echo -ne "${OkBullet}Checking root... ${Off}"
if [[ $EUID -ne 0 ]]; then
echo -e "${Fail}"
echo -e "${ErrBullet}You need to run this script as root (UID=0).${Off}"
exit 1
fi
echo -e "${Ok}"
}
check_return() {
if [ "$1" -ne 0 ]; then
echo -e "${Fail}"
echo -e "${ErrBullet}Installation failed. Check the logs in ${XMRSH_LOG_FILE}${Off}"
exit "$1"
fi
}
uninstall() {
pushd $XMRSH_DIR >>"${XMRSH_LOG_FILE}" 2>&1 || check_return $?
echo -e "${OkBullet}Uninstalling xmr.sh..."
if [ -f docker-compose.yml ]; then
docker-compose down >>"${XMRSH_LOG_FILE}" 2>&1
fi
check_return $?
while true; do
read -r -e -p " Do you want to keep the data directory with the blockchain and other data files? [y/n]: " yn
case $yn in
[Yy]*)
find . -type f -not -name 'data' -print0 | xargs -0 -I {} rm {}
check_return $?
break
;;
[Nn]*)
rm -rf ./*
check_return $?
break
;;
*) echo " Please answer yes or no." ;;
esac
done
popd || check_return $?
echo -e "${OkBullet}Uninstall complete."
}
check_root
uninstall
exit 0