Debian Codegraph @

src/TestDB/name-in-etc-hosts

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 if [ $# -lt 1 ] ; then
36 echo >&2 "Usage: $0 name ..."
37 exit 1
38 fi
39 HEADER="# Testbed:"
40 if ! grep -q "^${HEADER}" /etc/hosts ; then
41 cat >>/etc/hosts <<EOF
42
43 ${HEADER}
44 EOF
45 fi
46
47 while [ $# -gt 0 ] ;do
48 NAME="$1"
49 shift
50 # shellcheck disable=SC2001
51 name="$(echo "${NAME}" | sed -e "s/\..*$//g")"
52 # shellcheck disable=SC2001
53 domain="$(echo "${NAME}" | sed -e "s/^[^\.]*\.//g")"
54 echo "${name}.${domain}"
55 sed \
56 -e "/${name}\.${domain}/d" \
57 -e "s/^\(${HEADER}.*\)$/\1\n127.0.0.1 ${name}.${domain} ${name}\n::1 ${name}.${domain} ${name}/" \
58 </etc/hosts >/etc/hosts.new && \
59 cat /etc/hosts.new >/etc/hosts
60 done