| 1 | #!/usr/bin/envscip-shell filesystem . . `/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 [scip-shell system . . `[`. $# -ne 2 ] ; then |
| 36 | echoscip-shell system . . echo. >&2 "Usage: $0 mariadb|mongodb|mysql|postgresql users.conf" |
| 37 | exit 1 |
| 38 | fi |
| 39 | if [scip-shell system . . `[`. ! -e "$2" ] ; then |
| 40 | echoscip-shell system . . echo. >&2 "ERROR: Use configuration $2 does not exist!" |
| 41 | fi |
| 42 | |
| 43 | |
| 44 | # ====== Check/set environment variables ==================================== |
| 45 | if [scip-shell system . . `[`. ! -e /etc/os-releasescip-shell filesystem . . `/etc/os-release`. ] ; then |
| 46 | echoscip-shell system . . echo. >&2 "ERROR: /etc/os-release does not exist!" |
| 47 | exit 1 |
| 48 | fi |
| 49 | . /etc/os-releasescip-shell source . . `/etc/os-release`. |
| 50 | |
| 51 | DOMAIN="test.local" |
| 52 | ROOT_PASSWORD="!root!" |
| 53 | DATABASE="just_a_test_database" |
| 54 | MAINTAINER_PASSWORD="!maintainer!" |
| 55 | IMPORTER_PASSWORD="!importer!" |
| 56 | RESEARCHER_PASSWORD="!researcher!" |
| 57 | # shellcheck disable=SC1090 |
| 58 | . "$2" |
| 59 | |
| 60 | if [scip-shell system . . `[`. "${ROOT_PASSWORD}" == "!root!" ] || \ |
| 61 | [ "${MAINTAINER_PASSWORD}" == "!maintainer!" ] || \ |
| 62 | [ "${IMPORTER_PASSWORD}" == "!importer!" ] || \ |
| 63 | [ "${RESEARCHER_PASSWORD}" == "!researcher!" ] ; then |
| 64 | echoscip-shell system . . echo. >&2 "DO NOT USE THE EXAMPLE PASSWORDS!" |
| 65 | exit 1 |
| 66 | fi |
| 67 | |
| 68 | |
| 69 | # ###### MariaDB ############################################################ |
| 70 | if [scip-shell system . . `[`. "$1" == "mariadb" ] ; then |
| 71 | # Documentation: https://www.digitalocean.com/community/tutorials/how-to-install-mariadb-on-ubuntu-22-04 |
| 72 | server="mariadb" |
| 73 | |
| 74 | # ====== Install MariaDB ================================================= |
| 75 | echoscip-shell system . . echo. -e "\x1b[34m$(datescip-shell system . . date. +"%F %H:%M:%S"): Installing MariaDB ...\x1b[0m" |
| 76 | |
| 77 | if [scip-shell system . . `[`. "${ID}" == "ubuntu" ] || [scip-shell system . . `[`. "${ID}" == "debian" ] ; then |
| 78 | sudoscip-shell system . . sudo. DEBIAN_FRONTEND=noninteractive apt install -y -o APT::Keep-Downloaded-Packages=true mariadb-server mariadb-backup mariadb-client libmariadb-dev openssl |
| 79 | elif [scip-shell system . . `[`. "${ID}" == "fedora" ] ; then |
| 80 | sudoscip-shell system . . sudo. dnf install -y mariadb-server mariadb-backup mariadb-connector-c-devel openssl |
| 81 | sudoscip-shell system . . sudo. systemctl enable mariadb.service |
| 82 | sudoscip-shell system . . sudo. systemctl start mariadb.service |
| 83 | elif [scip-shell system . . `[`. "${ID}" == "freebsd" ] ; then |
| 84 | sudoscip-shell system . . sudo. pkg install -y mariadb118-server mariadb118-client openssl |
| 85 | sudoscip-shell system . . sudo. sysrc mysql_enable=YES |
| 86 | sudoscip-shell system . . sudo. service mysql-server start |
| 87 | else |
| 88 | echoscip-shell system . . echo. >&2 "ERROR: Unknown ID ${ID} in /etc/os-release. The installation script may need an update for supporting this system!" |
| 89 | exit 1 |
| 90 | fi |
| 91 | |
| 92 | # ====== Basic configuration ============================================= |
| 93 | sudoscip-shell system . . sudo. ./name-in-etc-hosts "${server}.${DOMAIN}" |
| 94 | sudoscip-shell system . . sudo. ./generate-test-certificates /etc/sslscip-shell filesystem . . `/etc/ssl`. "${server}.${DOMAIN}" |
| 95 | |
| 96 | # MariaDB needs separate certificate and key files. |
| 97 | # The chain is in the CA file, it must not be in the certificate file! |
| 98 | # Details: https://mariadb.com/kb/en/securing-connections-for-client-and-server/ |
| 99 | MARIADB_CA_FILE="/etc/ssl/TestLevel1/certs/TestLevel1.crtscip-shell filesystem . . `/etc/ssl/TestLevel1/certs/TestLevel1.crt`." |
| 100 | MARIADB_CRL_FILE="/etc/ssl/TestGlobal.crlscip-shell filesystem . . `/etc/ssl/TestGlobal.crl`." |
| 101 | MARIADB_CRT_FILE="/etc/ssl/${server}.${DOMAIN}/${server}.${DOMAIN}.crt" |
| 102 | MARIADB_KEY_FILE="/etc/ssl/${server}.${DOMAIN}/${server}.${DOMAIN}.key" |
| 103 | sudoscip-shell system . . sudo. chown mysql:mysql ${MARIADB_KEY_FILE} |
| 104 | |
| 105 | # Set root password, and remove test user and database. |
| 106 | ( |
| 107 | catscip-shell system . . cat. <<EOF |
| 108 | ALTER USER 'root'@'localhost' IDENTIFIED BY '${ROOT_PASSWORD}'; |
| 109 | DELETE FROM mysql.user WHERE User=''; |
| 110 | DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1'); |
| 111 | DROP DATABASE IF EXISTS ${DATABASE}; |
| 112 | DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'; |
| 113 | FLUSH PRIVILEGES; |
| 114 | EOF |
| 115 | ) | sudoscip-shell system . . sudo. mysql --user=root |
| 116 | |
| 117 | # Enable network access: |
| 118 | if [scip-shell system . . `[`. "${ID}" == "ubuntu" ] || [scip-shell system . . `[`. "${ID}" == "debian" ] ; then |
| 119 | sudoscip-shell system . . sudo. sed \ |
| 120 | -e '/^event_scheduler[ \t]*=.*$/dscip-shell filesystem . . `/^event_scheduler[ \t]*=.*$/d`.' -e 's/\(^\[mysqld\].*\)$/\1\nevent_scheduler = ON/' \ |
| 121 | -e 's/^\([#]\|\)\(max_allowed_packet[ \t]*\)=.*$/\2= 1G/g' \ |
| 122 | -e 's/^\(bind-address[ \t]*\)=.*$/\1= */g' \ |
| 123 | -e "s%\([#][ \t]*\|\)ssl-ca[ ]*=[ ]*.*%ssl-ca = ${MARIADB_CA_FILE}\nssl-crl = ${MARIADB_CRL_FILE}%" \ |
| 124 | -e "s%\([#][ \t]*\|\)ssl-cert[ ]*=[ ]*.*%ssl-cert = ${MARIADB_CRT_FILE}%" \ |
| 125 | -e "s%\([#][ \t]*\|\)ssl-key[ ]*=[ ]*.*%ssl-key = ${MARIADB_KEY_FILE}%" \ |
| 126 | -e "s%\([#][ \t]*\|\)require-secure-tscip-shell filesystem . . `/etc/mysql/mariadb.conf.d/50-server.cnf`.ransport[ ]*=[ ]*.*%require-secure-transport = on\ntls_version = TLSv1.3%" \ |
| 127 | /etc/mysql/mariadb.conf.d/50-server.cnf | sudoscip-shell system . . sudo. tee /etc/mysql/mariadb.conf.d/50-server.cnf.newscip-shell filesystem . . `/etc/mysql/mariadb.conf.d/50-server.cnf.new`. >/dev/nullscip-shell filesystem . . `/dev/null`. && \ |
| 128 | sudo diff --color /etc/mysql/mariadb.conf.d/50-server.cnfscip-shell filesystem . . `/etc/mysql/mariadb.conf.d/50-server.cnf`. /etc/mysql/mariadb.conf.d/50-server.cnf.newscip-shell filesystem . . `/etc/mysql/mariadb.conf.d/50-server.cnf.new`. || truescip-shell system . . true. && \ |
| 129 | sudo mv /etc/mysql/mariadb.conf.d/50-server.cnf.newscip-shell filesystem . . `/etc/mysql/mariadb.conf.d/50-server.cnf.new`. /etc/mysql/mariadb.conf.d/50-server.cnfscip-shell filesystem . . `/etc/mysql/mariadb.conf.d/50-server.cnf`. |
| 130 | sudoscip-shell system . . sudo. service mariadb restart |
| 131 | elif [scip-shell system . . `[`. "${ID}" == "fedora" ] ; then |
| 132 | sudoscip-shell system . . sudo. sed \ |
| 133 | -e '/^event_scheduler[ \t]*=.*$/dscip-shell filesystem . . `/^event_scheduler[ \t]*=.*$/d`.' -e 's/\(^\[mysqld\].*\)$/\1\nevent_scheduler = ON/' \ |
| 134 | -e "s%^#bind-address[ \t]*=.*%scip-shell filesystem . . `/etc/my.cnf.d/mariadb-server.cnf`.max_allowed_packet = 1G\nbind-address = *\nssl-ca = ${MARIADB_CA_FILE}\nssl-crl = ${MARIADB_CRL_FILE}\nssl-cert = ${MARIADB_CRT_FILE}\nssl-key = ${MARIADB_KEY_FILE}\nrequire-secure-transport = on\ntls_version = TLSv1.3%g" \ |
| 135 | /etc/my.cnf.d/mariadb-server.cnf | sudoscip-shell system . . sudo. tee /etc/my.cnf.d/mariadb-server.cnf.newscip-shell filesystem . . `/etc/my.cnf.d/mariadb-server.cnf.new`. && \ |
| 136 | sudo diff --color /etc/my.cnf.d/mariadb-server.cnfscip-shell filesystem . . `/etc/my.cnf.d/mariadb-server.cnf`. /etc/my.cnf.d/mariadb-server.cnf.newscip-shell filesystem . . `/etc/my.cnf.d/mariadb-server.cnf.new`. || truescip-shell system . . true. && \ |
| 137 | sudo mv /etc/my.cnf.d/mariadb-server.cnf.newscip-shell filesystem . . `/etc/my.cnf.d/mariadb-server.cnf.new`. /etc/my.cnf.d/mariadb-server.cnfscip-shell filesystem . . `/etc/my.cnf.d/mariadb-server.cnf`. |
| 138 | sudoscip-shell system . . sudo. service mariadb restart |
| 139 | elif [scip-shell system . . `[`. "${ID}" == "freebsd" ] ; then |
| 140 | sudoscip-shell system . . sudo. sed \ |
| 141 | -e '/^event_scheduler[ \t]*=.*$/dscip-shell filesystem . . `/^event_scheduler[ \t]*=.*$/d`.' -e 's/\(^\[mysqld\].*\)$/\1\nevent_scheduler = ON/' \ |
| 142 | -e "s%^bind-address[ \t]*=.*%max_allscip-shell filesystem . . `/usr/local/etc/mysql/conf.d/server.cnf`.owed_packet = 1G\nbind-address = *\nssl-ca = ${MARIADB_CA_FILE}\nssl-crl = ${MARIADB_CRL_FILE}\nssl-cert = ${MARIADB_CRT_FILE}\nssl-key = ${MARIADB_KEY_FILE}\nrequire-secure-transport = on\ntls_version = TLSv1.3%g" \ |
| 143 | /usr/local/etc/mysql/conf.d/server.cnf | sudoscip-shell system . . sudo. tee /usr/local/etc/mysql/conf.d/server.cnf.newscip-shell filesystem . . `/usr/local/etc/mysql/conf.d/server.cnf.new`. && \ |
| 144 | sudo diff --color /usr/local/etc/mysql/conf.d/server.cnfscip-shell filesystem . . `/usr/local/etc/mysql/conf.d/server.cnf`. /usr/local/etc/mysql/conf.d/server.cnf.newscip-shell filesystem . . `/usr/local/etc/mysql/conf.d/server.cnf.new`. || truescip-shell system . . true. && \ |
| 145 | sudo mv /usr/local/etc/mysql/conf.d/server.cnf.newscip-shell filesystem . . `/usr/local/etc/mysql/conf.d/server.cnf.new`. /usr/local/etc/mysql/conf.d/server.cnfscip-shell filesystem . . `/usr/local/etc/mysql/conf.d/server.cnf`. |
| 146 | sudoscip-shell system . . sudo. service mysql-server restart |
| 147 | fi |
| 148 | |
| 149 | # ====== Test configuration ============================================== |
| 150 | ./test-tls-connection "${server}.${DOMAIN}:3306" /etc/ssl/TestLevel1/certs/TestLevel1.crtscip-shell filesystem . . `/etc/ssl/TestLevel1/certs/TestLevel1.crt`. -- -starttls mysql |
| 151 | |
| 152 | |
| 153 | # ###### PostgreSQL ######################################################### |
| 154 | elif [scip-shell system . . `[`. "$1" == "postgresql" ] ; then |
| 155 | # Documentation: https://www.digitalocean.com/community/tutorials/how-to-install-postgresql-on-ubuntu-22-04-quickstart |
| 156 | server="postgresql" |
| 157 | |
| 158 | # ====== Install PostgreSQL ============================================== |
| 159 | echoscip-shell system . . echo. -e "\x1b[34m$(datescip-shell system . . date. +"%F %H:%M:%S"): Installing PostgreSQL ...\x1b[0m" |
| 160 | |
| 161 | if [scip-shell system . . `[`. "${ID}" == "ubuntu" ] || [scip-shell system . . `[`. "${ID}" == "debian" ] ; then |
| 162 | sudoscip-shell system . . sudo. DEBIAN_FRONTEND=noninteractive apt install -y -o APT::Keep-Downloaded-Packages=true openssl postgresql-all postgresql-contrib |
| 163 | elif [scip-shell system . . `[`. "${ID}" == "fedora" ] ; then |
| 164 | sudoscip-shell system . . sudo. dnf install -y openssl postgresql-server libpqxx-devel |
| 165 | sudoscip-shell system . . sudo. -u postgres /usr/bin/postgresql-setupscip-shell filesystem . . `/usr/bin/postgresql-setup`. --initdb || truescip-shell system . . true. |
| 166 | sudoscip-shell system . . sudo. systemctl enable postgresql.service |
| 167 | sudoscip-shell system . . sudo. systemctl start postgresql.service |
| 168 | elif [scip-shell system . . `[`. "${ID}" == "freebsd" ] ; then |
| 169 | sudoscip-shell system . . sudo. pkg install -y postgresql18-server postgresql18-client postgresql-libpqxx openssl |
| 170 | sudoscip-shell system . . sudo. sysrc postgresql_enable="YES" |
| 171 | sudoscip-shell system . . sudo. /usr/local/etc/rc.d/postgresqlscip-shell filesystem . . `/usr/local/etc/rc.d/postgresql`. initdb |
| 172 | sudoscip-shell system . . sudo. service postgresql start |
| 173 | else |
| 174 | echoscip-shell system . . echo. >&2 "ERROR: Unknown ID ${ID} in /etc/os-release. The installation script may need an update for supporting this system!" |
| 175 | exit 1 |
| 176 | fi |
| 177 | |
| 178 | # ====== Basic configuration ============================================= |
| 179 | sudoscip-shell system . . sudo. ./name-in-etc-hosts "${server}.${DOMAIN}" |
| 180 | sudoscip-shell system . . sudo. ./generate-test-certificates /etc/sslscip-shell filesystem . . `/etc/ssl`. "${server}.${DOMAIN}" |
| 181 | |
| 182 | # PostgreSQL needs separate certificate and key files. |
| 183 | # The chain is in the CA file, it must not be in the certificate file! |
| 184 | POSTGRESQL_CA_FILE="/etc/ssl/TestLevel1/certs/TestLevel1.crtscip-shell filesystem . . `/etc/ssl/TestLevel1/certs/TestLevel1.crt`." |
| 185 | POSTGRESQL_CRL_FILE="/etc/ssl/TestGlobal.crlscip-shell filesystem . . `/etc/ssl/TestGlobal.crl`." |
| 186 | POSTGRESQL_CRT_FILE="/etc/ssl/${server}.${DOMAIN}/${server}.${DOMAIN}.crt" |
| 187 | POSTGRESQL_KEY_FILE="/etc/ssl/${server}.${DOMAIN}/${server}.${DOMAIN}.key" |
| 188 | sudoscip-shell system . . sudo. chown postgres:postgres ${POSTGRESQL_KEY_FILE} |
| 189 | |
| 190 | POSTGRESDIR="" |
| 191 | if [scip-shell system . . `[`. -d /etc/postgresqlscip-shell filesystem . . `/etc/postgresql`. ] ; then |
| 192 | POSTGRESDIR="$(findscip-shell system . . find. /etc/postgresql/scip-shell filesystem . . `/etc/postgresql/`. -mindepth 2 -maxdepth 2 -type d -name main | sortscip-shell system . . sort. -r | headscip-shell system . . head. -n1)" |
| 193 | elif [scip-shell system . . `[`. -d /var/db/postgresscip-shell filesystem . . `/var/db/postgres`. ] ; then |
| 194 | POSTGRESDIR="$(findscip-shell system . . find. /var/db/postgresscip-shell filesystem . . `/var/db/postgres`. -mindepth 1 -maxdepth 1 -type d -name "data*" | sortscip-shell system . . sort. -r | headscip-shell system . . head. -n1)" |
| 195 | elif sudoscip-shell system . . sudo. -u postgres test -d /var/lib/pgsql/datascip-shell filesystem . . `/var/lib/pgsql/data`. ; then |
| 196 | POSTGRESDIR="/var/lib/pgsql/datascip-shell filesystem . . `/var/lib/pgsql/data`." |
| 197 | fi |
| 198 | if [scip-shell system . . `[`. "${POSTGRESDIR}" == "" ] ; then |
| 199 | echoscip-shell system . . echo. >&2 "ERROR: Cannot find the PostgreSQL configuration directory!" |
| 200 | exit 1 |
| 201 | fi |
| 202 | echoscip-shell system . . echo. "Using PostgreSQL settings in ${POSTGRESDIR}!" |
| 203 | |
| 204 | # Enable network access: |
| 205 | sudoscip-shell system . . sudo. -u postgres sed \ |
| 206 | -e 's%^\(host[ \t]*all[ \t]*all[ \t]*\)127.0.0.1/32\([ \t]*\).*$%\10.0.0.0/0 \2scram-sha-256%g' \ |
| 207 | -e 's%^\(host[ \t]*all[ \t]*all[ \t]*\)::1/128\([ \t]*\).*$%\1::/0 \2scram-sha-256%g' \ |
| 208 | "${POSTGRESDIR}"/pg_hba.conf | sudoscip-shell system . . sudo. -u postgres tee "${POSTGRESDIR}"/pg_hba.conf.new >/dev/nullscip-shell filesystem . . `/dev/null`. && \ |
| 209 | sudo -u postgres diff --color "${POSTGRESDIR}"/pg_hba.conf.new "${POSTGRESDIR}"/pg_hba.conf || truescip-shell system . . true. && \ |
| 210 | sudo -u postgres mv -f "${POSTGRESDIR}"/pg_hba.conf.new "${POSTGRESDIR}"/pg_hba.conf |
| 211 | |
| 212 | sudoscip-shell system . . sudo. -u postgres sed -r \ |
| 213 | -e "s%#listen_addresses = 'localhost'%listen_addresses = '*' %" \ |
| 214 | -e "s%^(#ssl|ssl) =.*%ssl = on%" \ |
| 215 | -e "s%^(#ssl|ssl)_ca_file = '.*'%ssl_ca_file = '${POSTGRESQL_CA_FILE}'%" \ |
| 216 | -e "s%^(#ssl|ssl)_crl_file = '.*'%ssl_crl_file = '${POSTGRESQL_CRL_FILE}'%" \ |
| 217 | -e "s%^(#ssl|ssl)_cert_file = '.*'%ssl_cert_file = '${POSTGRESQL_CRT_FILE}'%" \ |
| 218 | -e "s%^(#ssl|ssl)_key_file = '.*'%ssl_key_file = '${POSTGRESQL_KEY_FILE}'%" \ |
| 219 | -e "s%#ssl_ciphers = '.*'%ssl_ciphers = 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256'%" \ |
| 220 | -e "s%#ssl_prefer_server_ciphers = on%ssl_prefer_server_ciphers = on%" \ |
| 221 | -e "s%#ssl_min_protocol_version = 'TLSv1.2'%ssl_min_protocol_version = 'TLSv1.3'%" \ |
| 222 | "${POSTGRESDIR}"/postgresql.conf | sudoscip-shell system . . sudo. -u postgres tee "${POSTGRESDIR}"/postgresql.conf.new >/dev/nullscip-shell filesystem . . `/dev/null`. && \ |
| 223 | sudo -u postgres diff --color "${POSTGRESDIR}"/postgresql.conf.new "${POSTGRESDIR}"/postgresql.conf || truescip-shell system . . true. && \ |
| 224 | sudo -u postgres mv -f "${POSTGRESDIR}"/postgresql.conf.new "${POSTGRESDIR}"/postgresql.conf |
| 225 | |
| 226 | sudoscip-shell system . . sudo. service postgresql restart |
| 227 | sleepscip-shell system . . sleep. 5 |
| 228 | |
| 229 | # ====== Test configuration ============================================== |
| 230 | ./test-tls-connection "${server}.${DOMAIN}:5432" /etc/ssl/TestLevel1/certs/TestLevel1.crtscip-shell filesystem . . `/etc/ssl/TestLevel1/certs/TestLevel1.crt`. -- -starttls postgres |
| 231 | |
| 232 | |
| 233 | # ###### MongoDB ############################################################ |
| 234 | elif [scip-shell system . . `[`. "$1" == "mongodb" ] ; then |
| 235 | # Documentation: https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/ |
| 236 | server="mongodb" |
| 237 | |
| 238 | # ====== Install MongoDB ================================================= |
| 239 | echoscip-shell system . . echo. -e "\x1b[34m$(datescip-shell system . . date. +"%F %H:%M:%S"): Installing MongoDB ...\x1b[0m" |
| 240 | |
| 241 | MONGODB_VERSION="8.0" |
| 242 | MONGODB_KEY="${MONGODB_VERSION}" |
| 243 | |
| 244 | if [scip-shell system . . `[`. "${ID}" == "ubuntu" ] || [scip-shell system . . `[`. "${ID}" == "debian" ] ; then |
| 245 | for key in ${MONGODB_VERSION} dev ; do |
| 246 | wget -qO - "https://www.mongodb.org/static/pgp/server-${key}.asc" | gpgscip-shell system . . gpg. --dearmor | sudoscip-shell system . . sudo. tee "/usr/share/keyrings/mongodb-${key}.gpg" >/dev/nullscip-shell filesystem . . `/dev/null`. |
| 247 | done |
| 248 | . /etc/os-releasescip-shell source . . `/etc/os-release`. |
| 249 | ( |
| 250 | if [scip-shell system . . `[`. "${ID}" == "ubuntu" ] ; then |
| 251 | codename="${UBUNTU_CODENAME}" |
| 252 | if [[ ! "${codename}" =~ ^(precise|trusty|xenial|bionic|focal|jammy|noble)$ ]] ; then |
| 253 | # MongoDB only provides repositories for LTS versions. |
| 254 | # Assuming the latest LTS version here, for testing on non-LTS Ubuntu: |
| 255 | codename="noble" |
| 256 | fi |
| 257 | catscip-shell system . . cat. <<EOF |
| 258 | deb [ signed-by=/usr/share/keyrings/mongodb-${MONGODB_KEY}.gpg ] https://repo.mongodb.org/apt/ubuntu ${codename}/mongodb-org/${MONGODB_VERSION} multiverse |
| 259 | deb [ signed-by=/usr/share/keyrings/mongodb-dev.gpg ] https://repo.mongodb.org/apt/ubuntu ${codename}/mongodb-org/development multiverse |
| 260 | EOF |
| 261 | else |
| 262 | catscip-shell system . . cat. <<EOF |
| 263 | deb [ signed-by=/usr/share/keyrings/mongodb-${MONGODB_KEY}.gpg ] https://repo.mongodb.org/apt/debian ${VERSION_CODENAME}/mongodb-org/${MONGODB_VERSION} main |
| 264 | deb [ signed-by=/usr/share/keyrings/mongodb-dev.gpg ] https://repo.mongodb.org/apt/debian ${VERSION_CODENAME}/mongodb-org/development main |
| 265 | EOF |
| 266 | fi |
| 267 | ) | sudoscip-shell system . . sudo. tee /etc/apt/sources.list.d/mongodb-org.listscip-shell filesystem . . `/etc/apt/sources.list.d/mongodb-org.list`. >/dev/nullscip-shell filesystem . . `/dev/null`. |
| 268 | sudoscip-shell system . . sudo. apt update -qq |
| 269 | sudoscip-shell system . . sudo. DEBIAN_FRONTEND=noninteractive apt install -y -o APT::Keep-Downloaded-Packages=true mongodb-org mongodb-mongosh openssl |
| 270 | sudoscip-shell system . . sudo. systemctl enable mongod.service |
| 271 | |
| 272 | elif [scip-shell system . . `[`. "${ID}" == "fedora" ] ; then |
| 273 | ( |
| 274 | catscip-shell system . . cat. <<EOF |
| 275 | [mongodb-org] |
| 276 | name=MongoDB ${MONGODB_VERSION} Repository |
| 277 | baseurl=https://repo.mongodb.org/yum/redhat/9/mongodb-org/${MONGODB_VERSION}/x86_64/ |
| 278 | gpgcheck=1 |
| 279 | enabled=1 |
| 280 | gpgkey=https://www.mongodb.org/static/pgp/server-${MONGODB_KEY}.asc |
| 281 | EOF |
| 282 | ) | sudoscip-shell system . . sudo. tee /etc/yum.repos.d/mongodb-org.reposcip-shell filesystem . . `/etc/yum.repos.d/mongodb-org.repo`. |
| 283 | # ( |
| 284 | # cat <<EOF |
| 285 | # [mongodb-org-dev] |
| 286 | # name=MongoDB Development Repository |
| 287 | # baseurl=https://repo.mongodb.org/yum/redhat/9/mongodb-org/development/x86_64/ |
| 288 | # gpgcheck=1 |
| 289 | # enabled=1 |
| 290 | # gpgkey=https://www.mongodb.org/static/pgp/server-dev.asc |
| 291 | # EOF |
| 292 | # ) | sudo tee /etc/yum.repos.d/mongodb-org-dev.repo |
| 293 | sudoscip-shell system . . sudo. dnf install -y mongodb-org mongodb-mongosh-shared-openssl3 openssl |
| 294 | sudoscip-shell system . . sudo. systemctl enable mongod.service |
| 295 | sudoscip-shell system . . sudo. systemctl start mongod.service |
| 296 | |
| 297 | elif [scip-shell system . . `[`. "${ID}" == "freebsd" ] ; then |
| 298 | sudoscip-shell system . . sudo. pkg install -y mongodb80 mongodb-tools mongosh mongo-c-driver |
| 299 | sudoscip-shell system . . sudo. sysrc mongod_enable="YES" |
| 300 | sudoscip-shell system . . sudo. service mongod start |
| 301 | |
| 302 | else |
| 303 | echoscip-shell system . . echo. >&2 "ERROR: Unknown ID ${ID} in /etc/os-release. The installation script may need an update for supporting this system!" |
| 304 | exit 1 |
| 305 | fi |
| 306 | |
| 307 | # ====== Basic configuration ============================================= |
| 308 | sudoscip-shell system . . sudo. ./name-in-etc-hosts "${server}.${DOMAIN}" |
| 309 | sudoscip-shell system . . sudo. ./generate-test-certificates /etc/sslscip-shell filesystem . . `/etc/ssl`. "${server}.${DOMAIN}" |
| 310 | |
| 311 | # MongoDB wants key + certificate + chain (in this order!) in the PEM file: |
| 312 | MONGODB_CA_FILE="/etc/ssl/TestLevel1/certs/TestLevel1.crtscip-shell filesystem . . `/etc/ssl/TestLevel1/certs/TestLevel1.crt`." |
| 313 | MONGODB_CRL_FILE="/etc/ssl/TestGlobal.crlscip-shell filesystem . . `/etc/ssl/TestGlobal.crl`." |
| 314 | MONGODB_CRT_KEY_FILE="/etc/ssl/${server}.${DOMAIN}/${server}.${DOMAIN}.key+crt" |
| 315 | sudoscip-shell system . . sudo. touch ${MONGODB_CRT_KEY_FILE} |
| 316 | sudoscip-shell system . . sudo. chmod 600 ${MONGODB_CRT_KEY_FILE} |
| 317 | sudoscip-shell system . . sudo. cat /etc/ssl/${server}.${DOMAIN}/${server}.${DOMAIN}.key \ |
| 318 | /etc/ssl/${server}.${DOMAIN}/${server}.${DOMAIN}.crt | \ |
| 319 | sudo tee ${MONGODB_CRT_KEY_FILE} >/dev/nullscip-shell filesystem . . `/dev/null`. |
| 320 | if [scip-shell system . . `[`. "${ID}" == "fedora" ] ; then |
| 321 | sudoscip-shell system . . sudo. chown mongod:mongod ${MONGODB_CRT_KEY_FILE} |
| 322 | else |
| 323 | sudoscip-shell system . . sudo. chown mongodb:mongodb ${MONGODB_CRT_KEY_FILE} |
| 324 | fi |
| 325 | |
| 326 | |
| 327 | # WARNING: After installation, MongoDB gives everybody on 127.0.0.1 |
| 328 | # full access! |
| 329 | # The following settings enable authorization check, restricting access |
| 330 | # to the configured user (root). |
| 331 | if [scip-shell system . . `[`. "${ID}" == "freebsd" ] ; then |
| 332 | mongodConf=/usr/local/etc/mongodb.confscip-shell filesystem . . `/usr/local/etc/mongodb.conf`. |
| 333 | else |
| 334 | mongodConf=/etc/mongod.confscip-shell filesystem . . `/etc/mongod.conf`. |
| 335 | fi |
| 336 | |
| 337 | cpscip-shell system . . cp. ${mongodConf} /tmp/scip-shell filesystem . . `/tmp/`. |
| 338 | sudoscip-shell system . . sudo. sed \ |
| 339 | -e "s!# engine:! directoryPerDB: true!" \ |
| 340 | -e "s!# wiredTiger:! wiredTiger:\n engineConfig:\n directoryForIndexes: true!" \ |
| 341 | ${mongodConf} | sudoscip-shell system . . sudo. tee ${mongodConf}.new |
| 342 | sudoscip-shell system . . sudo. service mongod stop |
| 343 | sudoscip-shell system . . sudo. mv ${mongodConf}.new ${mongodConf} |
| 344 | sudoscip-shell system . . sudo. service mongod start |
| 345 | sleepscip-shell system . . sleep. 5 |
| 346 | |
| 347 | # ====== Make sure there is a root user ================================== |
| 348 | mongosh --quiet <<EOF |
| 349 | use admin |
| 350 | db.dropUser("root") |
| 351 | db.createUser({ user: "root", |
| 352 | pwd: "${ROOT_PASSWORD}", |
| 353 | roles: [ |
| 354 | "userAdminAnyDatabase", |
| 355 | "dbAdminAnyDatabase", |
| 356 | "readWriteAnyDatabase", |
| 357 | "clusterAdmin" |
| 358 | ] }) |
| 359 | quit() |
| 360 | EOF |
| 361 | |
| 362 | # ====== Configure MongoDB =============================================== |
| 363 | # The following settings enable authorization check, restricting access |
| 364 | # to the configured user (root): |
| 365 | cpscip-shell system . . cp. ${mongodConf} /tmp/scip-shell filesystem . . `/tmp/`. |
| 366 | sudoscip-shell system . . sudo. sed \ |
| 367 | -e "s!^ bindIp: 127.0.0.1.*! ipv6: true\n bindIpAll: true\n tls:\n mode: requireTLS\n CAFile: ${MONGODB_CA_FILE}\n CRLFile: ${MONGODB_CRL_FILE}\n certificateKeyFile: ${MONGODB_CRT_KEY_FILE}\n disabledProtocols: TLS1_0,TLS1_1,TLS1_2\n allowConnectionsWithoutCertificates: true!" \ |
| 368 | -e "s!#security:!security:\n authorization: enabled!" \ |
| 369 | -e "s!# engine:! directoryPerDB: true!" \ |
| 370 | -e "s!# wiredTiger:! wiredTiger:\n engineConfig:\n directoryForIndexes: true!" \ |
| 371 | ${mongodConf} | sudoscip-shell system . . sudo. tee ${mongodConf}.new |
| 372 | sudoscip-shell system . . sudo. service mongod stop |
| 373 | sudoscip-shell system . . sudo. mv ${mongodConf}.new ${mongodConf} |
| 374 | sudoscip-shell system . . sudo. service mongod start |
| 375 | sleepscip-shell system . . sleep. 5 |
| 376 | |
| 377 | # ====== Test configuration ============================================== |
| 378 | ./test-tls-connection "${server}.${DOMAIN}:27017" /etc/ssl/TestLevel1/certs/TestLevel1.crtscip-shell filesystem . . `/etc/ssl/TestLevel1/certs/TestLevel1.crt`. |
| 379 | |
| 380 | |
| 381 | # ###### Error ############################################################## |
| 382 | else |
| 383 | echoscip-shell system . . echo. >&2 "ERROR: Unsupported database: $1" |
| 384 | exit 1 |
| 385 | fi |