| 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 [ $# -ne 3 ] ; then |
| 36 |
echo >&2 "Usage: $0 template-users.conf mydatabase-users.conf database" |
| 37 |
exit 1 |
| 38 |
fi |
| 39 |
TEMPLATE="$1" |
| 40 |
CONFIG="$2" |
| 41 |
DATABASE="$3" |
| 42 |
if [[ ! "${CONFIG}" =~ (-users\.conf)$ ]] ; then |
| 43 |
echo >&2 "ERROR: Name must be <PREFIX>-users.conf!" |
| 44 |
exit 1 |
| 45 |
fi |
| 46 |
|
| 47 |
|
| 48 |
# ====== Generate secure test user passwords ================================ |
| 49 |
if [ ! -e "${CONFIG}" ] ; then |
| 50 |
echo -e "\x1b[34m$(date +"%F %H:%M:%S"): Generating ${CONFIG} ...\x1b[0m" |
| 51 |
while read -r line ; do |
| 52 |
echo >&2 "$line" |
| 53 |
if [[ "${line}" =~ ^(.*[\"])(!.*!)([\"])$ ]] ; then |
| 54 |
echo "${BASH_REMATCH[1]}$(pwgen -s 128)${BASH_REMATCH[3]}" |
| 55 |
else |
| 56 |
echo "${line}" |
| 57 |
fi |
| 58 |
done <"${TEMPLATE}" | tee "${CONFIG}" |
| 59 |
fi |
| 60 |
|
| 61 |
# shellcheck disable=SC1090 |
| 62 |
. "${CONFIG}" |
| 63 |
|
| 64 |
|
| 65 |
# ====== Write HiPerConTracer Importer configuration files ================== |
| 66 |
name="$(dirname "${CONFIG}")/importer-${DATABASE}.conf" |
| 67 |
cat >"${name}" <<EOF |
| 68 |
# ====== Importer Configuration ============================================= |
| 69 |
|
| 70 |
# Import modes: DeleteImportedFiles MoveImportedFiles KeepImportedFiles |
| 71 |
# DeleteImportedFiles = Delete successfully imported files |
| 72 |
# MoveImportedFiles = Move successfully imported files to good path |
| 73 |
# KeepImportedFiles = Keep successfully imported files where they are |
| 74 |
# Use only for debugging! Any importer rerun will process them again! |
| 75 |
import_mode = MoveImportedFiles |
| 76 |
|
| 77 |
# Regular expression to filter input files: |
| 78 |
import_path_filter = |
| 79 |
|
| 80 |
# Import directory and maximum search depth (1 = only the directory itself): |
| 81 |
import_file_path = data/ |
| 82 |
import_max_depth = 6 |
| 83 |
|
| 84 |
# NOTE: good and bad file directories MUST NOT be a subdirectory of the |
| 85 |
# import directory! |
| 86 |
bad_file_path = bad/ |
| 87 |
good_file_path = good/ |
| 88 |
|
| 89 |
# Sorting of files in good/bad file directories, taking levels of the |
| 90 |
# original file name's directory hierarchy as well as of the timestamp: |
| 91 |
move_directory_depth = 2 |
| 92 |
move_timestamp_depth = 3 |
| 93 |
|
| 94 |
# Interval for showing current importer status in output log (in s, minimum 5): |
| 95 |
status_interval = 60 |
| 96 |
# Interval for directory garbage collection (in s, minimum 10): |
| 97 |
gc_interval = 65 |
| 98 |
# Maximum age for unused, empty directories (in s, minimum 60): |
| 99 |
gc_max_age = 120 |
| 100 |
|
| 101 |
# Custom table mappings (Reader:Table): |
| 102 |
# table = Ping:Ping |
| 103 |
# table = Traceroute:Traceroute |
| 104 |
# table = Jitter:Jitter |
| 105 |
EOF |
| 106 |
|
| 107 |
for backend in MariaDB PostgreSQL MongoDB ; do |
| 108 |
host="${backend,,}" |
| 109 |
server="${host}.${DOMAIN}" |
| 110 |
for user in ${USERS} ; do |
| 111 |
database="${DATABASE}" |
| 112 |
if [ "${backend}" == "MongoDB" ] && [ "${user}" == "root" ] ; then |
| 113 |
database="admin" # MongoDB's root user is in database "admin"! |
| 114 |
fi |
| 115 |
# shellcheck disable=SC2001 |
| 116 |
name="$(echo "${CONFIG}" | sed -e "s/-users\.conf$/-${user}-${backend,,}.conf/")" |
| 117 |
passwordVariable="${user^^}_PASSWORD" |
| 118 |
password="${!passwordVariable}" |
| 119 |
if [ "${user}" == "root" ] && [ "${backend}" == "PostgreSQL" ] ; then |
| 120 |
user="postgres" # The PostgreSQL root user is "postgres", not "root"! |
| 121 |
fi |
| 122 |
|
| 123 |
cat >"${name}" <<EOF |
| 124 |
# ====== Database Server Configuration ====================================== |
| 125 |
|
| 126 |
# ----- TLS configuration options ------------------------------------------- |
| 127 |
# NOTE: |
| 128 |
# dbcafile sets a TLS CA file. |
| 129 |
# dbcertkeyfile sets a TLS client certificate file. |
| 130 |
# dbconnectionflags sets TLS connection flags (space-separated): |
| 131 |
# * NONE: default, i.e. require properly configured TLS |
| 132 |
# * DisableTLS: disable TLS |
| 133 |
# * AllowInvalidHostname: allow invalid hostnames in certificate |
| 134 |
# * AllowInvalidCertificate: allow invalid certificate |
| 135 |
# WARNING: Do *not* use these options! Instead, configure TLS properly!! |
| 136 |
# --------------------------------------------------------------------------- |
| 137 |
|
| 138 |
|
| 139 |
# ****** Configuration with ${backend} server: *************** |
| 140 |
dbbackend = ${backend} |
| 141 |
dbserver = ${server} |
| 142 |
dbport = 0 |
| 143 |
dbcafile = ${HOME}/TestLevel1.crt |
| 144 |
dbcrlfile = ${HOME}/TestGlobal.crl |
| 145 |
dbcertfile = NONE |
| 146 |
dbkeyfile = NONE |
| 147 |
dbconnectionflags = NONE |
| 148 |
dbuser = ${user} |
| 149 |
dbpassword = ${password} |
| 150 |
database = ${database} |
| 151 |
dbreconnectdelay = 5 |
| 152 |
EOF |
| 153 |
if [ "${backend}" == "MongoDB" ] ; then |
| 154 |
sed -e "s/^dbcertfile /dbcertkeyfile/" \ |
| 155 |
-e "/^dbkeyfile/d" \ |
| 156 |
<"${name}" >"${name}".new && \ |
| 157 |
mv "${name}".new "${name}" |
| 158 |
fi |
| 159 |
done |
| 160 |
done |
| 161 |
|
| 162 |
|
| 163 |
# ====== Write DBeaver configuration files ================================== |
| 164 |
# shellcheck disable=SC2001 |
| 165 |
prefix="$(echo "${CONFIG}" | sed -e "s/-users\.conf$//")" |
| 166 |
if [ -x ../make-dbeaver-configuration ] ; then |
| 167 |
# Running in development environment: |
| 168 |
../make-dbeaver-configuration "${prefix}"-*-*.conf --join || true |
| 169 |
else |
| 170 |
make-dbeaver-configuration "${prefix}"-*-*.conf --join || true |
| 171 |
fi |