Debian Codegraph @

src/TestDB/0-make-configurations

raw
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 -euo pipefail
33
34
35 # ###### Helper function to show script information #########################
36 show-script ()
37 {
38 local script="$1"
39 local columns
40 columns="$(print-utf8 -t 2>/dev/null || echo "80")"
41 columns="${columns/ */}"
42 columns=$((columns - 2))
43 print-utf8 -n -s "\e[1;36m█" "▀" "█\e[0m" ;
44 figlet -w "${columns}" "$(basename "${script}")" | print-utf8 -n -C "\e[1;36m█\e[25m" "█\e[0m" ;
45 print-utf8 -n -s "\e[1;36m█" "▄" "█\e[0m"
46 }
47
48
49
50 # ##### Main program ########################################################
51
52 # ====== Handle arguments ===================================================
53 if [ $# -ne 3 ] ; then
54 echo >&2 "Usage: $0 template-users.conf mydatabase-users.conf database"
55 exit 1
56 fi
57 TEMPLATE="$1"
58 CONFIG="$2"
59 DATABASE="$3"
60 if [[ ! "${CONFIG}" =~ (-users\.conf)$ ]] ; then
61 echo >&2 "ERROR: Name must be <PREFIX>-users.conf!"
62 exit 1
63 fi
64
65 # ====== Check/set environment variables ====================================
66 if [ ! -e /etc/os-release ] ; then
67 echo >&2 "ERROR: /etc/os-release does not exist!"
68 exit 1
69 fi
70 . /etc/os-release
71
72 # ====== Dependencies =======================================================
73 # These scripts need the X.509-Tools of the System-Tools software suite!
74 if ! command -v check-certificate || \
75 ! command -v print-utf8 || \
76 ! command -v test-tls-connection || \
77 ! command -v view-certificate ; then
78 if [ "${ID}" == "ubuntu" ] ; then
79 sudo apt-add-repository -sy ppa:dreibh/ppa
80 sudo apt update
81 sudo DEBIAN_FRONTEND=noninteractive apt install -y \
82 figlet td-print-utf8 td-x509-tools
83 elif [ "${ID}" == "fedora" ] ; then
84 sudo dnf copr enable -y dreibh/ppa
85 sudo dnf install -y \
86 figlet td-system-tools-print-utf8 td-system-tools-x509-tools
87 elif [ "${ID}" == "freebsd" ] ; then
88 sudo pkg install -y figlet td-system-tools
89 else
90 # Install from sources:
91 if [ ! -e system-tools ] ; then
92 git clone https://[email protected]/dreibh/system-tools.git
93 pushd system-tools 2>/dev/null
94 else
95 pushd system-tools 2>/dev/null
96 git pull
97 fi
98 sudo ci/get-dependencies -i
99 ./autogen.sh
100 sudo make install
101 popd 2>/dev/null
102 fi
103 fi
104
105 show-script "$(basename "$0")"
106
107
108 # ====== Generate secure test user passwords ================================
109 if [ ! -e "${CONFIG}" ] ; then
110 echo -e "\x1b[34m$(date +"%F %H:%M:%S"): Generating ${CONFIG} ...\x1b[0m"
111 while read -r line ; do
112 echo >&2 "$line"
113 if [[ "${line}" =~ ^(.*[\"])(!.*!)([\"])$ ]] ; then
114 echo "${BASH_REMATCH[1]}$(pwgen -s 128)${BASH_REMATCH[3]}"
115 else
116 echo "${line}"
117 fi
118 done <"${TEMPLATE}" | tee "${CONFIG}"
119 fi
120
121 # shellcheck disable=SC1090
122 . "${CONFIG}"
123
124
125 # ====== Write HiPerConTracer Importer configuration files ==================
126 name="$(dirname "${CONFIG}")/importer-${DATABASE}.conf"
127 cat >"${name}" <<EOF
128 # ====== Importer Configuration =============================================
129
130 # Import modes: DeleteImportedFiles MoveImportedFiles KeepImportedFiles
131 # DeleteImportedFiles = Delete successfully imported files
132 # MoveImportedFiles = Move successfully imported files to good path
133 # KeepImportedFiles = Keep successfully imported files where they are
134 # Use only for debugging! Any importer rerun will process them again!
135 import_mode = MoveImportedFiles
136
137 # Regular expression to filter input files:
138 import_path_filter =
139
140 # Import directory and maximum search depth (1 = only the directory itself):
141 import_file_path = data/
142 import_max_depth = 6
143
144 # NOTE: good and bad file directories MUST NOT be a subdirectory of the
145 # import directory!
146 bad_file_path = bad/
147 good_file_path = good/
148
149 # Sorting of files in good/bad file directories, taking levels of the
150 # original file name's directory hierarchy as well as of the timestamp:
151 move_directory_depth = 2
152 move_timestamp_depth = 3
153
154 # Interval for showing current importer status in output log (in s, minimum 5):
155 status_interval = 60
156 # Interval for directory garbage collection (in s, minimum 10):
157 gc_interval = 65
158 # Maximum age for unused, empty directories (in s, minimum 60):
159 gc_max_age = 120
160
161 # Custom table mappings (Reader:Table):
162 # table = Ping:Ping
163 # table = Traceroute:Traceroute
164 # table = Jitter:Jitter
165 EOF
166
167 for backend in MariaDB PostgreSQL MongoDB ; do
168 host="${backend,,}"
169 server="${host}.${DOMAIN}"
170 for user in ${USERS} ; do
171 database="${DATABASE}"
172 if [ "${backend}" == "MongoDB" ] && [ "${user}" == "root" ] ; then
173 database="admin" # MongoDB's root user is in database "admin"!
174 fi
175 # shellcheck disable=SC2001
176 name="$(echo "${CONFIG}" | sed -e "s/-users\.conf$/-${user}-${backend,,}.conf/")"
177 passwordVariable="${user^^}_PASSWORD"
178 password="${!passwordVariable}"
179 if [ "${user}" == "root" ] && [ "${backend}" == "PostgreSQL" ] ; then
180 user="postgres" # The PostgreSQL root user is "postgres", not "root"!
181 fi
182
183 cat >"${name}" <<EOF
184 # ====== Database Server Configuration ======================================
185
186 # ----- TLS configuration options -------------------------------------------
187 # NOTE:
188 # dbcafile sets a TLS CA file.
189 # dbcertkeyfile sets a TLS client certificate file.
190 # dbconnectionflags sets TLS connection flags (space-separated):
191 # * NONE: default, i.e. require properly configured TLS
192 # * DisableTLS: disable TLS
193 # * AllowInvalidHostname: allow invalid hostnames in certificate
194 # * AllowInvalidCertificate: allow invalid certificate
195 # WARNING: Do *not* use these options! Instead, configure TLS properly!!
196 # ---------------------------------------------------------------------------
197
198
199 # ****** Configuration with ${backend} server: ***************
200 dbbackend = ${backend}
201 dbserver = ${server}
202 dbport = 0
203 dbcafile = ${HOME}/TestLevel1.crt
204 dbcrlfile = ${HOME}/TestGlobal.crl
205 dbcertfile = NONE
206 dbkeyfile = NONE
207 dbconnectionflags = NONE
208 dbuser = ${user}
209 dbpassword = ${password}
210 database = ${database}
211 dbreconnectdelay = 5
212 EOF
213 if [ "${backend}" == "MongoDB" ] ; then
214 sed -e "s/^dbcertfile /dbcertkeyfile/" \
215 -e "/^dbkeyfile/d" \
216 <"${name}" >"${name}".new && \
217 mv "${name}".new "${name}"
218 fi
219 done
220 done
221
222
223 # ====== Write DBeaver configuration files ==================================
224 # shellcheck disable=SC2001
225 prefix="$(echo "${CONFIG}" | sed -e "s/-users\.conf$//")"
226 if [ -x ../make-dbeaver-configuration ] ; then
227 # Running in development environment:
228 ../make-dbeaver-configuration "${prefix}"-*-*.conf --join || true
229 else
230 make-dbeaver-configuration "${prefix}"-*-*.conf --join || true
231 fi