Repository navigation
Expand file tree
/
Copy pathprepare-machine
More file actions
executable file
·300 lines (261 loc) · 8 KB
/
Copy pathprepare-machine
File metadata and controls
executable file
·300 lines (261 loc) · 8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/bin/bash
# AdaptMON machine preparation script.
#
# Author: Michal Sedlak <sedlakm@cesnet.cz>
# Copyright (c) 2026 CESNET, z.s.p.o.
set -euo pipefail # bash "strict" mode
usage()
{
echo "Usage: ./prepare-machine [ ARGS ] <ROLE>"
echo
echo "ARGS:"
echo " -h, --help ... Print help"
echo " -v, --verbose ... Verbose mode"
echo
echo "ROLE: dev-container | dev-machine"
}
detect_os()
{
local os_id
local os_id_like
local os_version
local os_version_major
os_id="$(grep ^ID= /etc/os-release | cut -d'=' -f2 | tr -d '"')"
os_id_like="$(grep ^ID_LIKE= /etc/os-release | cut -d'=' -f2 | tr -d '"')"
os_version="$(grep ^VERSION= /etc/os-release | cut -d'=' -f2 | tr -d '"')"
os_version_major="${os_version%%.*}"
if [[ "$os_id" =~ fedora|rhel || "$os_id_like" =~ fedora|rhel ]] && [ "$os_version_major" = 8 ] && [ "$os_id" != ol ]; then
echo "rocky8"
elif [[ "$os_id" =~ fedora|rhel || "$os_id_like" =~ fedora|rhel ]] && [ "$os_version_major" = 9 ] && [ "$os_id" != ol ]; then
echo "rocky9"
elif [ "$os_id" = ol ] && [ "$os_version_major" = 8 ]; then
echo "ol8"
elif [ "$os_id" = ol ] && [ "$os_version_major" = 9 ]; then
echo "ol9"
elif [ "$os_id" = ol ] && [ "$os_version_major" = 10 ]; then
echo "ol10"
else
echo "unknown"
fi
}
parse_args()
{
local role
role=dev-machine
while [ $# != 0 ]; do
case "$1" in
dev-container)
role=dev-container
shift
;;
dev-machine)
role=dev-machine
shift
;;
-h|--help)
usage
exit 0
;;
-v|--verbose)
set -x
shift
;;
*)
echo "Unknown parameter '$1'"
usage
exit 1
esac
done
echo "Selected role: $role"
case "$role" in
dev-machine)
;;
dev-container)
GCC_TOOLSET_AUTOENABLE=${GCC_TOOLSET_AUTOENABLE-true}
INSTALL_NIX=${INSTALL_NIX-true}
;;
esac
if [ "$OS" = "ol10" ]; then
GCC_TOOLSET_VERSION=${GCC_TOOLSET_VERSION-15}
USE_GCC_TOOLSET=${USE_GCC_TOOLSET-true}
INSTALL_UV=${INSTALL_UV-true}
fi
USE_GCC_TOOLSET=${USE_GCC_TOOLSET-true}
GCC_TOOLSET_VERSION=${GCC_TOOLSET_VERSION-14}
GCC_TOOLSET_AUTOENABLE=${GCC_TOOLSET_AUTOENABLE-false}
INSTALL_UV=${INSTALL_UV-false}
USE_LBR_REPOS=${USE_LBR_REPOS-false}
INSTALL_DPDK_BUILDTOOLS=${INSTALL_DPDK_BUILDTOOLS-false}
INSTALL_NIX=${INSTALL_NIX-false}
NIX_VERSION=${NIX_VERSION-2.35.2}
echo
echo "=== Setup parameters ==="
echo "USE_GCC_TOOLSET=${USE_GCC_TOOLSET}"
echo "GCC_TOOLSET_VERSION=${GCC_TOOLSET_VERSION}"
echo "GCC_TOOLSET_AUTOENABLE=${GCC_TOOLSET_AUTOENABLE}"
echo "INSTALL_UV=${INSTALL_UV}"
echo "USE_LBR_REPOS=${USE_LBR_REPOS}"
echo "INSTALL_DPDK_BUILDTOOLS=${INSTALL_DPDK_BUILDTOOLS}"
echo "INSTALL_NIX=${INSTALL_NIX}"
echo "NIX_VERSION=${NIX_VERSION}"
}
enable_extra_repos()
{
echo
echo "*** Enabling extra repositories ***"
$SUDO dnf install -y 'dnf-command(config-manager)'
case "$OS" in
rocky8)
$SUDO dnf install -y epel-release
$SUDO dnf config-manager --set-enabled powertools
;;
rocky9)
$SUDO dnf install -y epel-release
$SUDO dnf config-manager --set-enabled crb
;;
ol8|ol9)
$SUDO dnf install -y epel-release
$SUDO dnf config-manager --set-enabled "${OS}_codeready_builder"
;;
ol10)
$SUDO dnf install -y oracle-epel-release-el10
$SUDO dnf config-manager --set-enabled "ol10_codeready_builder"
;;
esac
if [ "$USE_LBR_REPOS" = true ]; then
$SUDO dnf copr enable @CESNET/nfb-framework
$SUDO dnf config-manager --add-repo https://www.liberouter.org/repo/dcpro/liberouter-dcpro-extras.repo
fi
}
install_common_tools()
{
echo
echo "*** Installing common tools ***"
$SUDO dnf install -y sudo git
}
install_cpp_tools()
{
echo
echo "*** Installing and setting up CPP development tools ***"
$SUDO dnf install -y \
cmake make rpm-build \
gcc gcc-c++ \
clang-tools-extra \
doxygen
if [ "$USE_GCC_TOOLSET" = true ]; then
$SUDO dnf install -y "gcc-toolset-${GCC_TOOLSET_VERSION}"
if [ "$GCC_TOOLSET_AUTOENABLE" = true ]; then
if [ "$GCC_TOOLSET_VERSION" -lt 15 ]; then
echo "source /opt/rh/gcc-toolset-${GCC_TOOLSET_VERSION}/enable" | $SUDO tee "/etc/profile.d/gcc-toolset-${GCC_TOOLSET_VERSION}-enable.sh"
else
echo "eval \"\$(gcc-toolset-${GCC_TOOLSET_VERSION}-env printenv | grep gcc-toolset)\"" | $SUDO tee "/etc/profile.d/gcc-toolset-${GCC_TOOLSET_VERSION}-enable.sh"
fi
$SUDO chmod 644 "/etc/profile.d/gcc-toolset-${GCC_TOOLSET_VERSION}-enable.sh"
fi
fi
}
install_library_deps()
{
echo
echo "*** Installing library dependencies ***"
if [ "$USE_GCC_TOOLSET" = true ]; then
$SUDO dnf install -y \
"gcc-toolset-${GCC_TOOLSET_VERSION}-libasan-devel" \
"gcc-toolset-${GCC_TOOLSET_VERSION}-libubsan-devel"
else
$SUDO dnf install -y --enablerepo=devel \
libasan-static \
libubsan-static
fi
$SUDO dnf install -y \
libpcap-devel
}
install_dpdk()
{
echo
echo "*** Installing DPDK ***"
if [ "$INSTALL_DPDK_BUILDTOOLS" = true ]; then
$SUDO dnf install -y \
meson ninja-build python3-pyelftools numactl-devel rdma-core-devel \
libacl-devel bzip2-devel
fi
if [ "$USE_LBR_REPOS" = true ]; then
$SUDO dnf install -y kernel-headers kernel-devel
$SUDO dnf install -y lbr_dpdk lbr_dpdk-devel
else
$SUDO dnf install -y dpdk dpdk-devel
fi
}
install_python_tools()
{
echo
echo "*** Installing python tools ***"
if [ "$INSTALL_UV" = true ]; then
$SUDO dnf install -y uv
else
echo "Skipped uv installation"
fi
}
install_nix_shell()
{
echo
echo "*** Installing nix shell ***"
if [ "$INSTALL_NIX" = true ]; then
if nix --version; then
echo "WARNING: Nix is already installed, skipping installation"
else
local tmp
tmp="$(mktemp --tmpdir -d prepare-machine-XXXXXXXX)"
trap "rm -rf '$tmp'" EXIT
curl -Lo "$tmp/nix-${NIX_VERSION}-x86_64-linux.tar.xz" "https://releases.nixos.org/nix/nix-${NIX_VERSION}/nix-${NIX_VERSION}-x86_64-linux.tar.xz"
tar xf "$tmp/nix-${NIX_VERSION}-x86_64-linux.tar.xz" -C "$tmp"
mkdir -p ~/.config/nix/
if [ -f ~/.config/nix/nix.conf ]; then
mv ~/.config/nix/nix.conf ~/.config/nix/nix.conf.bak
fi
touch ~/.config/nix/nix.conf
echo 'build-users-group =' >> ~/.config/nix/nix.conf
if [ -f /.dockerenv ]; then # Are we running in docker?
echo 'sandbox = false' >> ~/.config/nix/nix.conf
fi
NIX_BECOME="$SUDO" "$tmp/nix-${NIX_VERSION}-x86_64-linux/install"
# Prefetch nix-shell packages
(
. ~/.nix-profile/etc/profile.d/nix.sh
nix-shell --run echo
)
fi
else
echo "Skipped nix-shell installation"
fi
}
install_rpm_builddeps()
{
echo
echo "*** Installing RPM build dependencies ***"
if [ -f ./adaptmon.spec ]; then
$SUDO dnf builddep -y --define 'builddep_only 1' "./adaptmon.spec"
else
echo "WARNING: Skipped installation of RPM build dependencies. Specfile not found."
fi
}
main()
{
if [ "$EUID" = 0 ]; then
SUDO=${SUDO-}
else
SUDO=${SUDO-sudo}
fi
OS="$(detect_os)"
echo "Detected OS: $OS"
parse_args "$@"
enable_extra_repos
install_common_tools
install_cpp_tools
install_library_deps
install_dpdk
install_python_tools
install_nix_shell
install_rpm_builddeps
}
main "$@"