Merge "Remove -a build flag"
[multicloud/k8s.git] / kud / hosting_providers / vagrant / node.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2018
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 set -o nounset
12 set -o pipefail
13
14 # usage() - Prints the usage of the program
15 function usage {
16     cat <<EOF
17 usage: $0 [-v volumes]
18 Optional Argument:
19     -v List of key pair values for volumes and mount points ( e. g. sda=/var/lib/docker/,sdb=/var/lib/libvirt/ )
20 EOF
21 }
22
23 # mount_external_partition() - Create partition and mount the external volume
24 function mount_external_partition {
25     local dev_name="/dev/$1"
26     local mount_dir=$2
27
28     sfdisk $dev_name --no-reread << EOF
29 ;
30 EOF
31     mkfs -t ext4 ${dev_name}1
32     mkdir -p $mount_dir
33     mount ${dev_name}1 $mount_dir
34     echo "${dev_name}1 $mount_dir           ext4    errors=remount-ro,noatime,barrier=0 0       1" >> /etc/fstab
35 }
36
37 while getopts "h?v:" opt; do
38     case $opt in
39         v)
40             dict_volumes="$OPTARG"
41             ;;
42         h|\?)
43             usage
44             exit
45             ;;
46     esac
47 done
48
49 swapoff -a
50 if [[ -n "${dict_volumes+x}" ]]; then
51     for kv in ${dict_volumes//,/ } ;do
52         mount_external_partition ${kv%=*} ${kv#*=}
53     done
54 fi
55
56 vendor_id=$(lscpu|grep "Vendor ID")
57 if [[ $vendor_id == *GenuineIntel* ]]; then
58     kvm_ok=$(cat /sys/module/kvm_intel/parameters/nested)
59     if [[ $kvm_ok == 'N' ]]; then
60         echo "Enable Intel Nested-Virtualization"
61         rmmod kvm-intel
62         echo 'options kvm-intel nested=y' >> /etc/modprobe.d/dist.conf
63         modprobe kvm-intel
64         echo kvm-intel >> /etc/modules
65     fi
66 else
67     kvm_ok=$(cat /sys/module/kvm_amd/parameters/nested)
68     if [[ $kvm_ok == '0' ]]; then
69         echo "Enable AMD Nested-Virtualization"
70         rmmod kvm-amd
71         sh -c "echo 'options kvm-amd nested=1' >> /etc/modprobe.d/dist.conf"
72         modprobe kvm-amd
73         echo kvm-amd >> /etc/modules
74     fi
75 fi
76 modprobe vhost_net
77 echo vhost_net >> /etc/modules
78 source /etc/os-release || source /usr/lib/os-release
79 case ${ID,,} in
80     *suse)
81     ;;
82     ubuntu|debian)
83         apt-get install -y cpu-checker
84         kvm-ok
85     ;;
86     rhel|centos|fedora)
87     ;;
88 esac