CSIT-205 Update qemu install script
[csit.git] / resources / libraries / bash / qemu_build.sh
1 #!/bin/bash
2 # Copyright (c) 2016 Cisco and/or its affiliates.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 QEMU_VERSION="qemu-2.2.1"
16
17 QEMU_DOWNLOAD_REPO="http://wiki.qemu-project.org/download/"
18 QEMU_DOWNLOAD_PACKAGE="${QEMU_VERSION}.tar.bz2"
19 QEMU_PACKAGE_URL="${QEMU_DOWNLOAD_REPO}${QEMU_DOWNLOAD_PACKAGE}"
20 QEMU_INSTALL_DIR="/opt/qemu"
21
22 if test "$(id -u)" -ne 0
23 then
24     echo "Please use root or sudo to be able to install into: ${QEMU_INSTALL_DIR}"
25     exit 1
26 fi
27
28 WORKING_DIR=$(mktemp -d)
29 test $? -eq 0 || exit 1
30
31 cleanup () {
32     rm -r ${WORKING_DIR}
33 }
34
35 trap cleanup EXIT
36
37 if [[ "$@" == "--force" ]]
38 then
39     rm -rf ${QEMU_INSTALL_DIR}
40 else
41     test -d ${QEMU_INSTALL_DIR} && echo "Qemu already installed: ${QEMU_INSTALL_DIR}" && exit 0
42 fi
43
44 echo
45 echo Downloading QEMU source
46 echo
47 wget -P ${WORKING_DIR} -q ${QEMU_PACKAGE_URL} || exit
48 test $? -eq 0 || exit 1
49
50 echo
51 echo Extracting QEMU
52 echo
53 tar --strip-components 1 -xjf ${WORKING_DIR}/${QEMU_DOWNLOAD_PACKAGE} -C ${WORKING_DIR} || exit
54 test $? -eq 0 || exit 1
55
56 echo
57 echo Building QEMU
58 echo
59 cd ${WORKING_DIR}
60 mkdir ${QEMU_INSTALL_DIR}
61 mkdir build
62 cd build
63 ../configure --target-list=x86_64-softmmu --prefix=${QEMU_INSTALL_DIR} || exit
64 make -j`nproc` || exit 1
65 make install || exit 1
66
67 echo
68 echo QEMU ready
69 echo