installation: update scripts to actually install
[barometer.git] / src / build_base_machine.sh
1 #!/bin/bash
2 #
3 # Top level scripts to build basic setup for the host
4 #
5
6 # Copyright 2017 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 #   Maryam Tahhan, Intel Corporation.
26 ROOT_UID=0
27 SUDO=""
28
29 # function to emit error message before quitting
30 function die() {
31     echo $1
32     exit 1
33 }
34
35 # Detect OS name and version from systemd based os-release file
36 . /etc/os-release
37
38 # Get OS name (the First word from $NAME in /etc/os-release)
39 OS_NAME="$ID"
40
41 # check if root
42 if [ "$UID" -ne "$ROOT_UID" ]
43 then
44     # installation must be run via sudo
45     SUDO="sudo -E"
46 fi
47
48 # If there is version specific dir available then set distro_dir to that
49 if [ -d "$OS_NAME/$VERSION_ID" ]; then
50     distro_dir="$OS_NAME/$VERSION_ID"
51 else
52     # Fallback - Default distro_dir = OS name
53     distro_dir="$OS_NAME"
54 fi
55
56 # build base system using OS specific scripts
57 if [ -d "$distro_dir" ] && [ -e "$distro_dir/install_build_deps.sh" ]; then
58     $SUDO $distro_dir/install_build_deps.sh || die "$distro_dir/install_build_deps.sh failed"
59 else
60     die "$distro_dir is not yet supported"
61 fi
62
63 # download and compile DPDK, OVS, RDT and Collectd
64 if [ -f Makefile ] ; then
65     make || die "Make failed"
66 else
67     die "Make failed; No Makefile"
68 fi
69