| 1 | #!/usr/bin/env bash |
| 2 | # ========================================================================== |
| 3 | # _ _ _ ____ ____ _____ |
| 4 | # | | | (_) _ \ ___ _ __ / ___|___ _ _|_ _| __ __ _ ___ ___ _ __ |
| 5 | # | |_| | | |_) / _ \ '__| | / _ \| '_ \| || '__/ _` |/ __/ _ \ '__| |
| 6 | # | _ | | __/ __/ | | |__| (_) | | | | || | | (_| | (_| __/ | |
| 7 | # |_| |_|_|_| \___|_| \____\___/|_| |_|_||_| \__,_|\___\___|_| |
| 8 | # |
| 9 | # --- High-Performance Connectivity Tracer (HiPerConTracer) --- |
| 10 | # https://www.nntb.no/~dreibh/hipercontracer/ |
| 11 | # ========================================================================== |
| 12 | # |
| 13 | # High-Performance Connectivity Tracer (HiPerConTracer) |
| 14 | # Copyright (C) 2015-2026 by Thomas Dreibholz |
| 15 | # |
| 16 | # This program is free software: you can redistribute it and/or modify |
| 17 | # it under the terms of the GNU General Public License as published by |
| 18 | # the Free Software Foundation, either version 3 of the License, or |
| 19 | # (at your option) any later version. |
| 20 | # |
| 21 | # This program is distributed in the hope that it will be useful, |
| 22 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | # GNU General Public License for more details. |
| 25 | # |
| 26 | # You should have received a copy of the GNU General Public License |
| 27 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 28 | # |
| 29 | # Contact: [email protected] |
| 30 | |
| 31 | # Bash options: |
| 32 | set -eu |
| 33 | |
| 34 | |
| 35 | if [ $# -lt 1 ] ; then |
| 36 | echo >&2 "Usage: $0 mariadb|mongodb|mysql|postgresql [--force-removal-without-confirmation]" |
| 37 | exit 1 |
| 38 | fi |
| 39 | |
| 40 | if [ $# -lt 2 ] || [ "$2" != "--force-removal-without-confirmation" ] ; then |
| 41 | echo -n "WARNING: THIS SCRIPT WILL ERASE THE EXISTING DATABASES. To proceed, type \"I am sure!\": " |
| 42 | read -er agree |
| 43 | if [ "$agree" != "I am sure!" ] ; then |
| 44 | echo "Exiting." |
| 45 | exit |
| 46 | fi |
| 47 | fi |
| 48 | |
| 49 | |
| 50 | # ====== Check/set environment variables ==================================== |
| 51 | if [ ! -e /etc/os-release ] ; then |
| 52 | echo >&2 "ERROR: /etc/os-release does not exist!" |
| 53 | exit 1 |
| 54 | fi |
| 55 | . /etc/os-release |
| 56 | |
| 57 | |
| 58 | |
| 59 | # ###### MariaDB ############################################################ |
| 60 | if [ "$1" == "mariadb" ] ; then |
| 61 | echo -e "\x1b[34m$(date +"%F %H:%M:%S"): Uninstalling MariaDB ...\x1b[0m" |
| 62 | |
| 63 | if [ "${ID}" == "ubuntu" ] || [ "${ID}" == "debian" ] ; then |
| 64 | sudo DEBIAN_FRONTEND=noninteractive apt purge -y mariadb-client mariadb-server mariadb-backup |
| 65 | elif [ "${ID}" == "fedora" ] ; then |
| 66 | sudo dnf remove -y 'mariadb-*' |
| 67 | elif [ "${ID}" == "freebsd" ] ; then |
| 68 | sudo service mysql-server stop || true |
| 69 | sudo service mysql-server disable || true |
| 70 | sudo pkg remove -y 'mariadb*-server' || true |
| 71 | else |
| 72 | echo >&2 "ERROR: Unknown ID ${ID} in /etc/os-release. The installation script may need an update for supporting this system!" |
| 73 | exit 1 |
| 74 | fi |
| 75 | |
| 76 | if [ -d /var/lib/mysql ] ; then |
| 77 | sudo rm -rf /var/lib/mysql |
| 78 | fi |
| 79 | if [ -d /var/db/mysql ] ; then |
| 80 | sudo rm -rf /var/db/mysql |
| 81 | fi |
| 82 | |
| 83 | |
| 84 | # ###### PostgreSQL ######################################################### |
| 85 | elif [ "$1" == "postgresql" ] ; then |
| 86 | echo -e "\x1b[34m$(date +"%F %H:%M:%S"): Uninstalling PostgreSQL ...\x1b[0m" |
| 87 | |
| 88 | if [ "${ID}" == "ubuntu" ] || [ "${ID}" == "debian" ] ; then |
| 89 | sudo DEBIAN_FRONTEND=noninteractive apt purge -y 'postgresql-*' |
| 90 | elif [ "${ID}" == "fedora" ] ; then |
| 91 | sudo dnf remove -y 'postgresql-*' |
| 92 | elif [ "${ID}" == "freebsd" ] ; then |
| 93 | sudo service postgresql stop || true |
| 94 | sudo pkg remove -y 'postgresql*-*' || true |
| 95 | else |
| 96 | echo >&2 "ERROR: Unknown ID ${ID} in /etc/os-release. The installation script may need an update for supporting this system!" |
| 97 | exit 1 |
| 98 | fi |
| 99 | |
| 100 | if [ -d /var/lib/postgresql ] ; then |
| 101 | sudo rm -rf /var/lib/postgresql |
| 102 | fi |
| 103 | if [ -d /var/lib/pgsql ] ; then |
| 104 | sudo rm -rf /var/lib/pgsql |
| 105 | fi |
| 106 | if [ -d /var/db/postgres ] ; then |
| 107 | sudo rm -rf /var/db/postgres |
| 108 | fi |
| 109 | |
| 110 | |
| 111 | # ###### MongoDB ############################################################ |
| 112 | elif [ "$1" == "mongodb" ] ; then |
| 113 | echo -e "\x1b[34m$(date +"%F %H:%M:%S"): Uninstalling MongoDB ...\x1b[0m" |
| 114 | |
| 115 | if [ "${ID}" == "ubuntu" ] || [ "${ID}" == "debian" ] ; then |
| 116 | sudo DEBIAN_FRONTEND=noninteractive apt purge -y 'mongodb-*' |
| 117 | elif [ "${ID}" == "fedora" ] ; then |
| 118 | sudo dnf remove -y 'mongodb-*' |
| 119 | elif [ "${ID}" == "freebsd" ] ; then |
| 120 | sudo service mongod stop || true |
| 121 | sudo pkg remove -y 'mongodb*' mongosh || true |
| 122 | sudo rm -f /usr/local/etc/mongodb.conf || true |
| 123 | else |
| 124 | echo >&2 "ERROR: Unknown ID ${ID} in /etc/os-release. The installation script may need an update for supporting this system!" |
| 125 | exit 1 |
| 126 | fi |
| 127 | |
| 128 | if [ -d /var/lib/mongodb ] ; then |
| 129 | sudo rm -rf /var/lib/mongodb |
| 130 | fi |
| 131 | |
| 132 | # ###### Error ############################################################## |
| 133 | else |
| 134 | echo >&2 "ERROR: Unsupported database: $1" |
| 135 | exit 1 |
| 136 | fi |