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:
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 QEMU_VERSION="qemu-2.5.0"
16 QEMU_DOWNLOAD_REPO="http://download.qemu-project.org/"
17 QEMU_DOWNLOAD_PACKAGE="${QEMU_VERSION}.tar.xz"
18 QEMU_PACKAGE_URL="${QEMU_DOWNLOAD_REPO}${QEMU_DOWNLOAD_PACKAGE}"
19 QEMU_INSTALL_DIR="/opt/${QEMU_VERSION}"
20 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
25 QEMU_VERSION="${i#*=}"
28 QEMU_INSTALL_DIR="${i#*=}"
41 if test "$(id -u)" -ne 0
43 echo "Please use root or sudo to be able to install into: ${QEMU_INSTALL_DIR}"
47 WORKING_DIR=$(mktemp -d) || \
48 { echo "Failed to create temporary working dir"; exit 1; }
49 trap "rm -r ${WORKING_DIR}" EXIT
53 rm -rf ${QEMU_INSTALL_DIR}
55 test -d ${QEMU_INSTALL_DIR} && \
56 { echo "Qemu already installed: ${QEMU_INSTALL_DIR}"; exit 0; }
59 # Download QEMU source code if no local copy exists
60 if [ ! -f /opt/${QEMU_DOWNLOAD_PACKAGE} ]; then
61 wget -P /opt -q ${QEMU_PACKAGE_URL} || \
62 { echo "Failed to download ${QEMU_VERSION}"; exit 1; }
65 # Extract archive into temp directory
66 tar --strip-components 1 -xf /opt/${QEMU_DOWNLOAD_PACKAGE} -C ${WORKING_DIR} || \
67 { echo "Failed to extract ${QEMU_VERSION}.tar.xz"; exit 1; }
70 mkdir ${QEMU_INSTALL_DIR} || \
71 { echo "Failed to create ${QEMU_INSTALL_DIR}"; exit 1; }
73 # Apply additional patches
76 chmod +x ${SCRIPT_DIR}/qemu_patches/${QEMU_VERSION}/*
77 run-parts --verbose --report ${SCRIPT_DIR}/qemu_patches/${QEMU_VERSION}
81 ./configure --target-list=x86_64-softmmu --prefix=${QEMU_INSTALL_DIR} || \
82 { echo "Failed to configure ${QEMU_VERSION}"; exit 1; }
84 { echo "Failed to compile ${QEMU_VERSION}"; exit 1; }
86 { echo "Failed to install ${QEMU_VERSION}"; exit 1; }
88 echo QEMU ${QEMU_VERSION} ready