2537f95878bb49fc3a93fadd341da9a8974538d0
[barometer.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-2016 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
27 ROOT_UID=0
28 SUDO=""
29
30 # function to emit error message before quitting
31 function die() {
32     echo $1
33     exit 1
34 }
35
36 # Detect OS name and version from systemd based os-release file
37 . /etc/os-release
38
39 # Get OS name (the First word from $NAME in /etc/os-release)
40 OS_NAME="$ID"
41
42 # check if root
43 if [ "$UID" -ne "$ROOT_UID" ]
44 then
45     # installation must be run via sudo
46     SUDO="sudo -E"
47 fi
48
49 if [ "$1" != "-f" ] && [ -d "/opt/collectd" ] || [ -d "/etc/collectd" ]
50 then
51     die "collectd is already installed on this system, if you wish to reinstall please rerun the script with a -f argument"
52 fi
53
54 # If there is version specific dir available then set distro_dir to that
55 distro_dir="$OS_NAME/$VERSION_ID"
56
57 # build base system using OS specific scripts
58 if [ -d "$distro_dir" ] && [ -e "$distro_dir/build_base_machine.sh" ]; then
59     $SUDO $distro_dir/build_base_machine.sh || die "$distro_dir/build_base_machine.sh failed"
60 else
61     die "$distro_dir is not yet supported"
62 fi
63
64 if [ ! -d /lib/modules/`uname -r`/build ] ; then
65     die "Kernel devel is not available for active kernel. It can be caused by recent kernel update. Please reboot and run $0 again."
66 fi
67
68 # download and compile DPDK and Collectd
69 if [ -f ../src/Makefile ] ; then
70     cd ../src
71     make clobber || die "Make clobber failed"
72     make || die "Make failed"
73     make install || die "Make install failed"
74     cd -
75 else
76     die "Make failed; No Makefile"
77 fi