forked from AMDESE/sev-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deps-install.sh
executable file
·322 lines (273 loc) · 9.93 KB
/
deps-install.sh
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/bin/bash
# Script to build AMD SEV Tool
###############################################################################
# Copyright 2018 Advanced Micro Devices, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################
NEED_DEPS=0
INSTALLER=""
SSL_DEV=""
AUTO_CONF="autoconf"
LIBVIRT_NAME="libvirt-devel"
UUID_NAME="libuuid-devel"
# Set to 1 to enable debugging or pass -d or --debug.
if [ "$(echo $1 | grep -E '^\-{0,2}d(ebug)?$')" != "" ]
then
DEBUGGING=1
else
DEBUGGING=0
fi
if [ ${DEBUGGING} -eq 1 ]
then
debug()
{
echo -n "[ DEBUG ] LINE "
echo "$@"
}
else
debug()
{
echo -n ""
}
fi
find_distribution_details()
{
OS_RELEASE=$(cat /etc/os-release)
debug $LINENO ":" "OS_RELEASE => " ${OS_RELEASE}
# Regular Expression to read /etc/os-release for major distributions.
ID_RE='ID\(\_LIKE\)\?\=\"\?[[:alpha:]]\+\([[:space:]][[:alpha:]]\*\)\?\"\?'
debug $LINENO ":" "ID_RE => ${ID_RE}"
# Read /etc/os-release to find the distribution base.
DIST_BASE=$(cat /etc/os-release | grep "${ID_RE}")
debug $LINENO ":" "DIST_BASE =>" ${DIST_BASE}
if [ "$(echo ${DIST_BASE} | grep 'suse')" != "" ] ||
[ "$(echo ${DIST_BASE} | grep 'sles')" != "" ]
then
# Cover all SLE and openSUSE distributions.
debug $LINENO ":" "Distribution recognized as SUSE based"
INSTALLER="zypper"
SSL_DEV="libopenssl-devel"
GCC_CPP="gcc-c++"
elif [ "$(echo ${DIST_BASE} | grep 'debian')" != "" ] ||
[ "$(echo ${DIST_BASE} | grep 'ubuntu')" != "" ]
then
# Cover all Debian and Ubuntu based distributions.
debug $LINENO ":" "Distribution recognized as Debian or Ubuntu based"
INSTALLER="apt-get"
SSL_DEV="libssl-dev"
LIBVIRT_NAME="libvirt-dev"
UUID_NAME="uuid-dev"
GCC_CPP="g++"
elif [ "$(echo ${DIST_BASE} | grep 'fedora')" != "" ] ||
[ "$(echo ${DIST_BASE} | grep 'rhel')" != "" ]
then
# Cover all Redhat based distributions.
debug $LINENO ":" "Distribution recognized as Fedora or Rhel based"
INSTALLER="yum"
SSL_DEV="openssl-devel"
GCC_CPP="gcc-c++"
else
debug $LINENO ":" "Regular expression could not match: \n" "${OS_RELEASE}"
echo "Distribution not recognized. Please manually install "\
"libelf libraries, libvirt-devel, make, zip, gcc, g++, git, wget, autoconf, and libssl-dev." >&2
exit 1
fi
debug $LINENO ":" "INSTALLER => ${INSTALLER}"
debug $LINENO ":" "SSL_DEV => ${SSL_DEV}"
debug $LINENO ":" "GCC_CPP => ${GCC_CPP}"
debug $LINENO ":" "LIBVIRT_NAME => ${LIBVIRT_NAME}"
debug $LINENO ":" "UUID_NAME => ${UUID_NAME}"
}
older_than_bionic()
{
VERSION_NUMBER=$(cat /etc/os-release | grep 'VERSION_ID=' | sed s%[a-z\_\-\=]%%ig)
IS_OLDER=0
debug $LINENO ":" "VERSION_NUMBER => ${VERSION_NUMBER}"
if [ ${VERSION_NUMBER} -lt 1804 ]
then
IS_OLDER=1
fi
debug $LINENO ":" "IS_OLDER => ${IS_OLDER}"
echo "${IS_OLDER}"
}
check_dependencies()
{
debug $LINENO ":" "Checking for dependencies..."
# Check for all required dependancies
if [ "${INSTALLER}" = "zypper" ] || [ "${INSTALLER}" = "yum" ]
then
if [ "$(rpm -q 'git' 2>&1 | grep 'not installed')" != "" ] ||
[ "$(rpm -q 'make' 2>&1 | grep 'not installed')" != "" ] ||
[ "$(rpm -q 'gcc' 2>&1 | grep 'not installed')" != "" ] ||
[ "$(rpm -q 'zip' 2>&1 | grep 'not installed')" != "" ] ||
[ "$(rpm -q 'wget' 2>&1 | grep 'not installed')" != "" ] ||
[ "$(rpm -q ${LIBVIRT_NAME} 2>&1 | grep 'not installed')" != "" ] ||
[ "$(rpm -q ${UUID_NAME} 2>&1 | grep 'not installed')" != "" ] ||
[ "$(rpm -q ${AUTO_CONF} 2>&1 | grep 'not installed')" != "" ] ||
[ "$(rpm -q ${SSL_DEV} 2>&1 | grep 'not installed')" != "" ] ||
[ "$(rpm -q ${GCC_CPP} 2>&1 | grep 'not installed')" != "" ]
then
debug $LINENO ":" "A dependency is missing, setting flag!"
NEED_DEPS=1
fi
elif [ "${INSTALLER}" = "apt-get" ]
then
if [ "$(older_than_bionic)" = "1" ]
then
AUTO_CONF="autoreconf"
fi
if [ "$(dpkg -l 'git' 2>&1 | grep 'no packages')" != "" ] ||
[ "$(dpkg -l 'make' 2>&1 | grep 'no packages')" != "" ] ||
[ "$(dpkg -l 'gcc' 2>&1 | grep 'no packages')" != "" ] ||
[ "$(dpkg -l 'zip' 2>&1 | grep 'no packages')" != "" ] ||
[ "$(dpkg -l 'wget' 2>&1 | grep 'no packages')" != "" ] ||
[ "$(dpkg -l ${LIBVIRT_NAME} 2>&1 | grep 'no packages')" != "" ] ||
[ "$(dpkg -l ${UUID_NAME} 2>&1 | grep 'no packages')" != "" ] ||
[ "$(dpkg -l ${AUTO_CONF} 2>&1 | grep 'no packages')" != "" ] ||
[ "$(dpkg -l ${SSL_DEV} 2>&1 | grep 'no packages')" != "" ] ||
[ "$(dpkg -l ${GCC_CPP} 2>&1 | grep 'no packages')" != "" ]
then
debug $LINENO ":" "A dependency is missing, setting flag!"
NEED_DEPS=1
fi
fi
}
fcomp()
{
debug $LINENO ":" "Attempting to determine which version number is greater."
RETVAL=0
if [ -n "${1}" ] && [ -n "${2}" ]
then
debug $LINENO ":" "Both arguments are non-zero values."
debug $LINENO ":" "\${1} (SYSTEM_SSL_VERSION) => ${1}"
debug $LINENO ":" "\${2} (ACCEPTED_SSL_VERSION) => ${2}"
if [ "${1%.*}" = "${2%.*}" ] && [ ! "${1#*.}" \< "${2#*.}" ]
then
debug $LINENO ":" "The system SSL version is new enough to use."
RETVAL=1
elif [ "${1%.*}" \> "${2%.*}" ]
then
debug $LINENO ":" "The system SSL version is new enough to use."
RETVAL=1
fi
else
debug $LINENO ":" "An error occured while attempting to parse the SSL version number."
debug $LINENO ":" "\${1} (SYSTEM_SSL_VERSION) => ${1}"
debug $LINENO ":" "\${2} (ACCEPTED_SSL_VERSIPN) => ${2}"
fi
return ${RETVAL}
}
check_ssl()
{
SSL_VERSION="1.1.0j"
ACCEPTED_SSL_VERSION="1.1.0"
ACCEPTED_SSL_VER_TRUNK=$(echo "${ACCEPTED_SSL_VERSION}" | sed 's/.\{2\}$//')
SYSTEM_SSL_VERSION=$(openssl version | awk '{print $2}' | sed "s/[a-zA-Z-]//g")
SYSTEM_SSL_VER_TRUNK=$(echo "${SYSTEM_SSL_VERSION}" | sed 's/.\{2\}$//')
debug $LINENO ":" "ACCEPTED_SSL_VER_TRUNK => ${ACCEPTED_SSL_VER_TRUNK}"
debug $LINENO ":" "SYSTEM_SSL_VER_TRUNK => ${SYSTEM_SSL_VER_TRUNK}"
CURRENT_DIR=$(pwd)
debug $LINENO ":" "CURRENT_DIR => ${CURRENT_DIR}"
fcomp ${SYSTEM_SSL_VER_TRUNK} ${ACCEPTED_SSL_VER_TRUNK}
FCOMP_RETURN=$?
if [ "${FCOMP_RETURN}" = "0" ] &&
[ ! -d ./openssl/ ]
then
debug $LINENO ":" "Local directory of openssl not detected..."
echo "Your version of openssl is not new enough!"
echo "Would you like to build a self-contained instance of the required openssl version"
printf "(internet connection required)? [y/N] "
read -r ssl_response
case ${ssl_response} in
[yY]*)
debug $LINENO ":" "User responded with YES."
echo "Downloading, compiling, and building against openssl version ${SSL_VERSION}"
# Download an acceptable version of openssl
wget https://www.openssl.org/source/openssl-${SSL_VERSION}.tar.gz
# create openssl directory
mkdir -p openssl
# Extract the tarball.
tar -xf openssl-${SSL_VERSION}.tar.gz -C openssl --strip-components 1
# Removing the tarball.
rm -f openssl-${SSL_VERSION}.tar.gz
# Enter the openssl directory, and build the library.
cd openssl/ || exit
./config
make -j64
cd "${CURRENT_DIR}" || exit
# Remove system ssl libraries from src Makefile.am
sed -i 's/^\# linked.*$//g' src/Makefile.am
sed -i 's/^sevtool_LDADD.*$//g' src/Makefile.am
# Add local ssl libraries to the src Makefile.am
echo "SSL_DIR=../openssl" >> src/Makefile.am
echo "sevtool_LDADD = \$(SSL_DIR)/libcrypto.a -ldl -lvirt -lvirt-qemu -luuid" >> src/Makefile.am
echo "sevtool_CXXFLAGS += -isystem \$(SSL_DIR)/include -isystem \$(SSL_DIR)" >> src/Makefile.am
;;
*)
debug $LINENO ":" "User responded with no."
echo "You will need to make sure you manually install all required dependencies."
;;
esac
elif [ "${FCOMP_RETURN}" = "0" ] &&
[ -d ./openssl/ ]
then
debug $LINENO ":" "Local directory of openssl detected..."
echo "Your version of openssl is not new enough!"
printf "Would you like to locally compile and build against the appropriate version? [y/N] "
read -r ssl_response
case ${ssl_response} in
[yY]*)
# Enter the openssl directory, and rebuild the library.
cd openssl/ || exit
./config
make -j64
# No adjustments to the automake file should be necessary as they were already done once.
cd "${CURRENT_DIR}" || exit
;;
*)
debug $LINENO ":" "User responded with no."
echo "You will need to make sure you manually install all required dependencies."
;;
esac
else
debug $LINENO ":" "Proper version of openssl detected as system install."
fi
}
main()
{
find_distribution_details
check_dependencies
# Install dependencies if they are needed.
if [ ${NEED_DEPS} -eq 1 ]
then
echo "One or more required software dependencies are missing on your system."
printf "Would you like to have them automatically installed? [y/N] "
read -r response
case ${response} in
[yY]*)
debug $LINENO ":" "User responded with YES."
debug $LINENO ":" "Running Command: \"sudo ${INSTALLER} install -y git make gcc "\
"zip wget ${LIBVIRT_NAME} ${UUID_NAME} ${AUTO_CONF} ${SSL_DEV} ${GCC_CPP}\""
sudo ${INSTALLER} install -y git make gcc zip wget ${UUID_NAME} ${LIBVIRT_NAME} ${AUTO_CONF} ${SSL_DEV} ${GCC_CPP}
;;
*)
debug $LINENO ":" "User responded with no."
echo "You will need to make sure you manually install all required dependencies."
;;
esac
fi
check_ssl
echo "Once all dependencies are met, you should be able to run \"autoreconf -if && ./configure && make\" to compile the sevtool."
}
main