Debian Codegraph @

src/TestDB/4-clean-database

raw symbols SCIP
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 2 ] ; then
36 echo >&2 "Usage: $0 mariadb|mongodb|mysql|postgresql users.conf [--force-removal-without-confirmation]"
37 exit 1
38 fi
39 CONFIG="$2"
40 if [ ! -e "${CONFIG}" ] ; then
41 echo >&2 "ERROR: Use configuration $2 does not exist!"
42 fi
43 if [ $# -gt 2 ] ; then
44 OPTION="$3"
45 else
46 OPTION=""
47 fi
48
49 if [ "${OPTION}" != "--force-removal-without-confirmation" ] ; then
50 echo -n "WARNING: THIS SCRIPT WILL ERASE THE EXISTING DATABASES. To proceed, type \"I am sure!\": "
51 read -er agree
52 if [ "$agree" != "I am sure!" ] ; then
53 echo "Exiting."
54 exit
55 fi
56 fi
57
58 DOMAIN="test.local"
59 DATABASE="just_a_test_database"
60 MAINTAINER_PASSWORD=
61 # IMPORTER_PASSWORD=
62 # RESEARCHER_PASSWORD=
63 # shellcheck disable=SC1090
64 . "$2"
65
66
67 # ###### MySQL/MariaDB ######################################################
68 if [ "$1" == "mysql" ] || [ "$1" == "mariadb" ] ; then
69 # Documentation: https://www.digitalocean.com/community/tutorials/how-to-install-mariadb-on-ubuntu-22-04
70 server="mariadb"
71
72 echo -e "\x1b[34m$(date +"%F %H:%M:%S"): Removing all rows from MySQL/MariaDB database ...\x1b[0m"
73 mysql \
74 --host="${server}.${DOMAIN}" \
75 --port 3306 \
76 --protocol=tcp \
77 --ssl \
78 --ssl-verify-server-cert \
79 --ssl-ca=/etc/ssl/TestLevel1/certs/TestLevel1.crt \
80 --ssl-crl=/etc/ssl/TestGlobal.crl \
81 --user=maintainer \
82 --password="${MAINTAINER_PASSWORD}" \
83 --database="${DATABASE}" \
84 <../SQL/mariadb-delete-all-rows.sql
85
86
87 # ###### PostgreSQL #########################################################
88 elif [ "$1" == "postgresql" ] ; then
89 # Documentation: https://www.digitalocean.com/community/tutorials/how-to-install-postgresql-on-ubuntu-22-04-quickstart
90 server="postgresql"
91
92 echo -e "\x1b[34m$(date +"%F %H:%M:%S"): Removing all rows from PostgreSQL database ...\x1b[0m"
93 PGPASSWORD="${MAINTAINER_PASSWORD}" \
94 PGSSLMODE="verify-full" \
95 PGSSLROOTCERT="/etc/ssl/TestLevel1/certs/TestLevel1.crt" \
96 PGSSLCRL="/etc/ssl/TestGlobal.crl" \
97 psql \
98 --host="${server}.${DOMAIN}" \
99 --port=5432 \
100 --username=maintainer \
101 --dbname="${DATABASE}" \
102 <../SQL/postgresql-delete-all-rows.sql
103
104
105 # ###### MongoDB ############################################################
106 elif [ "$1" == "mongodb" ] ; then
107 # Documentation: https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/
108 server="mongodb"
109
110 echo -e "\x1b[34m$(date +"%F %H:%M:%S"): Removing all rows from MongoDB database ...\x1b[0m"
111 mongosh \
112 "mongodb://${server}.${DOMAIN}:27017/${DATABASE}" \
113 --tls \
114 --tlsDisabledProtocols TLS1_0,TLS1_1,TLS1_2 \
115 --tlsCAFile /etc/ssl/TestLevel1/certs/TestLevel1.crt \
116 --username maintainer \
117 --password "${MAINTAINER_PASSWORD}" \
118 --quiet \
119 <../NoSQL/mongodb-delete-all-rows.ms
120 # FIXME! --tlsCRLFile /etc/ssl/TestGlobal.crl
121
122
123 # ###### Error ##############################################################
124 else
125 echo >&2 "ERROR: Unsupported database: $1"
126 exit 1
127 fi