Repository navigation
Expand file tree
/
Copy pathprepare-machine
More file actions
executable file
·190 lines (162 loc) · 5.55 KB
/
Copy pathprepare-machine
File metadata and controls
executable file
·190 lines (162 loc) · 5.55 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
#!/bin/bash
set -euo pipefail
usage() {
echo "Usage: ./prepare-machine [ ARGS ] <ROLE>"
echo
echo "ARGS:"
echo " -h, --help ... Print help"
echo " -v, --verbose ... Verbose mode"
echo
echo "ROLE: dev-docker | dev-machine"
}
ROLE=dev-machine
while [ $# != 0 ]; do
case "$1" in
dev-docker)
ROLE=dev-docker
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
case "$ROLE" in
dev-machine)
;;
dev-docker)
GCC_TOOLSET_AUTOENABLE=${GCC_TOOLSET_AUTOENABLE-true}
INSTALL_NIX=${INSTALL_NIX-true}
;;
esac
if [ "$EUID" = 0 ]; then
SUDO=${SUDO-}
else
SUDO=${SUDO-sudo}
fi
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%%.*}"
echo "=== Setting up development environment ==="
echo "Selected role: $ROLE"
echo
echo "*** Installing common tools ***"
$SUDO dnf install -y sudo git
echo
echo "*** Enabling extra repositories (epel/crb) ***"
$SUDO dnf install -y 'dnf-command(config-manager)'
if [[ "$OS_ID" =~ fedora|rhel || "$OS_ID_LIKE" =~ fedora|rhel ]] && [ "$OS_VERSION_MAJOR" = 8 ] && [ "$OS_ID" != ol ]; then
# PowerTools repository is enabled (CentOS/Rocky/etc. 8)
echo "Detected OS: RHEL-like 8"
$SUDO dnf install -y epel-release
$SUDO dnf config-manager --set-enabled powertools
elif [[ "$OS_ID" =~ fedora|rhel || "$OS_ID_LIKE" =~ fedora|rhel ]] && [ "$OS_VERSION_MAJOR" = 9 ] && [ "$OS_ID" != ol ]; then
# CodeReady Builder repository is enabled (CentOS/Rocky/etc. 9+)
echo "Detected OS: RHEL-like 9"
$SUDO dnf install -y epel-release
$SUDO dnf config-manager --set-enabled crb
elif [ "$OS_ID" = ol ] && [[ "$OS_VERSION_MAJOR" =~ 8|9 ]]; then
# CodeReady Builder repository is enabled (Oracle Linux 8, 9)
echo "Detected OS: Oracle Linux ${OS_VERSION_MAJOR}"
$SUDO dnf install -y epel-release
$SUDO dnf config-manager --set-enabled "ol${OS_VERSION_MAJOR}_codeready_builder"
elif [ "$OS_ID" = ol ] && [ "$OS_VERSION_MAJOR" = 10 ]; then
# CodeReady Builder repository is enabled (Oracle Linux 10)
echo "Detected OS: Oracle Linux 10"
$SUDO dnf install -y oracle-epel-release-el10
$SUDO dnf config-manager --set-enabled "ol10_codeready_builder"
# OL10 comes with gcc 14 by default, but misses libasan-static package
GCC_TOOLSET_VERSION=${GCC_TOOLSET_VERSION-15}
USE_GCC_TOOLSET=${USE_GCC_TOOLSET-true}
INSTALL_UV=${INSTALL_UV-true}
fi
echo
echo "*** Setting up CPP development tools ***"
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}
$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}"
fi
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
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 \
dpdk dpdk-devel dpdk-tools \
echo
echo "*** Installing python tools ***"
if [ "$INSTALL_UV" = true ]; then
$SUDO dnf install -y uv
else
echo "WARNING: Package uv is not installed"
fi
if [ "$INSTALL_NIX" = true ]; then
echo
echo "*** Installing nix shell ***"
if nix --version; then
echo "WARNING: Nix is already installed, skipping installation"
else
NIX_VERSION=2.35.2
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
fi
if [ -f ./adaptmon.spec ]; then
echo
echo "*** Installing RPM build dependencies ***"
$SUDO dnf builddep -y --define 'builddep_only 1' "./adaptmon.spec"
fi