forked from kata-containers/tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure_podman_for_kata.sh
executable file
·75 lines (65 loc) · 2.2 KB
/
configure_podman_for_kata.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
#!/bin/bash
#
# Copyright (c) 2020 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
set -o errexit
set -o nounset
set -o pipefail
cidir=$(dirname "$0")
source "${cidir}/../lib/common.bash"
default_kata_config="/usr/share/defaults/kata-containers/configuration.toml"
kata_config="/etc/kata-containers/configuration.toml"
TEST_INITRD="${TEST_INITRD:-no}"
TRUSTED_GROUP="${TRUSTED_GROUP:-kvm}"
setup_prerequisites() {
# Verify host kernel version
host_kernel_version=$(uname -r|cut -d. -f1-2)
kernel_version="4.14"
result=$(echo "${host_kernel_version} >= ${kernel_version}"|bc)
[ "${result}" -ne 1 ] && die "Host kernel version is ${host_kernel_version} which is too old"
# Disable selinux
if [ "$(getenforce)" != "Disabled" ]; then
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
fi
# Add user to KVM
getent group "${TRUSTED_GROUP}" &>/dev/null || sudo groupadd --system "${TRUSTED_GROUP}"
sudo usermod -a -G "${TRUSTED_GROUP}" $USER
newgrp "${TRUSTED_GROUP}" << END
echo "This is running as group $(id -gn)"
END
sudo chown root:"${TRUSTED_GROUP}" /dev/"${TRUSTED_GROUP}"
sudo chmod g+rw /dev/"${TRUSTED_GROUP}"
}
setup_kata_configuration_files() {
sudo mkdir -p $(dirname "${kata_config}")
[ ! -e "${kata_config}" ] && sudo install -D "${default_kata_config}" $(dirname "${kata_config}")
sudo chown root:"${TRUSTED_GROUP}" "${kata_config}"
sudo chmod g+r "${kata_config}"
}
disable_vhost_net() {
sudo sed -i -e 's/^#disable_vhost_net = true/disable_vhost_net = true/' "${kata_config}"
}
modify_kata_image_permissions() {
if [ "${TEST_INITRD}" == "yes" ]; then
img=$(readlink -f /usr/share/kata-containers/kata-containers-initrd.img)
else
img=$(readlink -f /usr/share/kata-containers/kata-containers.img)
fi
sudo chown -R "root:$TRUSTED_GROUP" "$img"
sudo chmod -R g+rw "$img"
}
kata_runtime_podman() {
echo 'kata-runtime = ["/usr/local/bin/kata-runtime"]' | sudo tee -a /usr/share/containers/libpod.conf
sudo sed -i -e 's/^runtime =.*/runtime = "kata-runtime"/' /usr/share/containers/libpod.conf
}
main() {
setup_prerequisites
setup_kata_configuration_files
disable_vhost_net
modify_kata_image_permissions
kata_runtime_podman
}
main "$@"