Build: Minimal Build for Trafficgen Mode Only Use.
[vswitchperf.git] / systems / build_base_machine.sh
1 #!/bin/bash
2 #
3 # Top level scripts to build basic setup for the host
4 #
5
6 # Copyright 2015 OPNFV, Intel Corporation.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #     http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19
20 #
21 # Contributors:
22 #   Aihua Li, Huawei Technologies.
23 #   Abdul Halim, Intel Corporation.
24 #   Martin Klozik, Intel Corporation.
25
26 ROOT_UID=0
27 SUDO=""
28
29 export VSPERFENV_DIR="$HOME/vsperfenv"
30
31 # function to emit error message before quitting
32 function die() {
33     echo $1
34     exit 1
35 }
36
37 # Detect OS name and version from systemd based os-release file
38 . /etc/os-release
39
40 # Get OS name (the First word from $NAME in /etc/os-release)
41 OS_NAME="$ID"
42
43 # check if root
44 if [ "$UID" -ne "$ROOT_UID" ]
45 then
46     # installation must be run via sudo
47     SUDO="sudo -E"
48 fi
49
50 # If there is version specific dir available then set distro_dir to that
51 if [ -d "$OS_NAME/$VERSION_ID" ]; then
52     distro_dir="$OS_NAME/$VERSION_ID"
53 else
54     # Fallback - Default distro_dir = OS name
55     distro_dir="$OS_NAME"
56 fi
57
58 if [ $# -eq 0 ]; then
59     echo "No parameters provided - continuing with Normal Build"
60     # build base system using OS specific scripts
61     if [ -d "$distro_dir" ] && [ -e "$distro_dir/build_base_machine.sh" ]; then
62         $SUDO $distro_dir/build_base_machine.sh || die "$distro_dir/build_base_machine.sh failed"
63     else
64         die "$distro_dir is not yet supported"
65 fi
66 fi
67
68 if [ -d "$distro_dir" ] && [ -e "$distro_dir/prepare_python_env.sh" ] ; then
69     $distro_dir/prepare_python_env.sh || die "prepare_python_env.sh failed"
70 else
71     die "$distro_dir is not yet supported"
72 fi
73
74 if [ ! -d /lib/modules/`uname -r`/build ] ; then
75     die "Kernel devel is not available for active kernel. It can be caused by recent kernel update. Please reboot and run $0 again."
76 fi
77
78 if [ $# -eq 0 ]; then
79     echo "No parameters provided - continuing with SRC Download and Compile"
80     # download and compile DPDK, OVS and QEMU
81     if [ -f ../src/Makefile ] ; then
82         cd ../src
83         make || die "Make failed"
84         cd -
85     else
86         die "Make failed; No Makefile"
87     fi
88 else
89     echo "Downloading and compiling only T-Rex"
90     if [ -f ../src/trex/Makefile ]; then
91         cd ../src/trex/
92         make || die "Make failed"
93         cd -
94     else
95         die "Make failed; No Makefile"
96     fi
97 fi