Victor Morales | 5be79b4 | 2018-02-17 03:52:57 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # SPDX-license-identifier: Apache-2.0 |
| 3 | ############################################################################## |
| 4 | # Copyright (c) 2017-2018 |
| 5 | # All rights reserved. This program and the accompanying materials |
| 6 | # are made available under the terms of the Apache License, Version 2.0 |
| 7 | # which accompanies this distribution, and is available at |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | ############################################################################## |
| 10 | |
| 11 | vagrant_version=2.0.2 |
| 12 | |
| 13 | function usage { |
| 14 | cat <<EOF |
| 15 | usage: setup.sh -p <PROVIDER> |
| 16 | Argument: |
| 17 | -p Vagrant provider |
| 18 | EOF |
| 19 | } |
| 20 | |
| 21 | while getopts ":p:" OPTION; do |
| 22 | case $OPTION in |
| 23 | p) |
| 24 | provider=$OPTARG |
| 25 | ;; |
| 26 | \?) |
| 27 | usage |
| 28 | exit 1 |
| 29 | ;; |
| 30 | esac |
| 31 | done |
| 32 | |
| 33 | case $provider in |
| 34 | "virtualbox" | "libvirt" ) |
| 35 | export VAGRANT_DEFAULT_PROVIDER=${provider} |
| 36 | ;; |
| 37 | * ) |
| 38 | usage |
| 39 | exit 1 |
| 40 | esac |
| 41 | source /etc/os-release || source /usr/lib/os-release |
| 42 | |
| 43 | packages=() |
| 44 | case ${ID,,} in |
| 45 | *suse) |
| 46 | INSTALLER_CMD="sudo -H -E zypper -q install -y --no-recommends" |
| 47 | |
| 48 | # Vagrant installation |
| 49 | vagrant_pgp="pgp_keys.asc" |
| 50 | wget -q https://keybase.io/hashicorp/$vagrant_pgp |
| 51 | wget -q https://releases.hashicorp.com/vagrant/$vagrant_version/vagrant_${vagrant_version}_x86_64.rpm |
| 52 | gpg --quiet --with-fingerprint $vagrant_pgp |
| 53 | sudo rpm --import $vagrant_pgp |
| 54 | sudo rpm --checksig vagrant_${vagrant_version}_x86_64.rpm |
| 55 | sudo rpm --install vagrant_${vagrant_version}_x86_64.rpm |
| 56 | rm vagrant_${vagrant_version}_x86_64.rpm |
| 57 | rm $vagrant_pgp |
| 58 | |
| 59 | case $VAGRANT_DEFAULT_PROVIDER in |
| 60 | virtualbox) |
| 61 | wget -q http://download.virtualbox.org/virtualbox/rpm/opensuse/$VERSION/virtualbox.repo -P /etc/zypp/repos.d/ |
| 62 | $INSTALLER_CMD --enablerepo=epel dkms |
| 63 | wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | rpm --import - |
| 64 | packages+=(VirtualBox-5.1) |
| 65 | ;; |
| 66 | libvirt) |
| 67 | # vagrant-libvirt dependencies |
| 68 | packages+=(qemu libvirt libvirt-devel ruby-devel gcc qemu-kvm zlib-devel libxml2-devel libxslt-devel make) |
| 69 | # NFS |
| 70 | packages+=(nfs-kernel-server) |
| 71 | ;; |
| 72 | esac |
| 73 | sudo zypper -n ref |
| 74 | ;; |
| 75 | |
| 76 | ubuntu|debian) |
| 77 | INSTALLER_CMD="sudo -H -E apt-get -y -q=3 install" |
| 78 | |
| 79 | # Vagrant installation |
| 80 | wget -q https://releases.hashicorp.com/vagrant/$vagrant_version/vagrant_${vagrant_version}_x86_64.deb |
| 81 | sudo dpkg -i vagrant_${vagrant_version}_x86_64.deb |
| 82 | rm vagrant_${vagrant_version}_x86_64.deb |
| 83 | |
| 84 | case $VAGRANT_DEFAULT_PROVIDER in |
| 85 | virtualbox) |
| 86 | echo "deb http://download.virtualbox.org/virtualbox/debian trusty contrib" >> /etc/apt/sources.list |
| 87 | wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add - |
| 88 | wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add - |
| 89 | packages+=(virtualbox-5.1 dkms) |
| 90 | ;; |
| 91 | libvirt) |
| 92 | # vagrant-libvirt dependencies |
| 93 | packages+=(qemu libvirt-bin ebtables dnsmasq libxslt-dev libxml2-dev libvirt-dev zlib1g-dev ruby-dev) |
| 94 | # NFS |
| 95 | packages+=(nfs-kernel-server) |
| 96 | ;; |
| 97 | esac |
| 98 | sudo apt-get update |
| 99 | ;; |
| 100 | |
| 101 | rhel|centos|fedora) |
| 102 | PKG_MANAGER=$(which dnf || which yum) |
| 103 | sudo $PKG_MANAGER updateinfo |
| 104 | INSTALLER_CMD="sudo -H -E ${PKG_MANAGER} -q -y install" |
| 105 | |
| 106 | # Vagrant installation |
| 107 | wget -q https://releases.hashicorp.com/vagrant/$vagrant_version/vagrant_${vagrant_version}_x86_64.rpm |
| 108 | $INSTALLER_CMD vagrant_${vagrant_version}_x86_64.rpm |
| 109 | rm vagrant_${vagrant_version}_x86_64.rpm |
| 110 | |
| 111 | case $VAGRANT_DEFAULT_PROVIDER in |
| 112 | virtualbox) |
| 113 | wget -q http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo -P /etc/yum.repos.d |
| 114 | $INSTALLER_CMD --enablerepo=epel dkms |
| 115 | wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | rpm --import - |
| 116 | packages+=(VirtualBox-5.1) |
| 117 | ;; |
| 118 | libvirt) |
| 119 | # vagrant-libvirt dependencies |
| 120 | packages+=(qemu libvirt libvirt-devel ruby-devel gcc qemu-kvm) |
| 121 | # NFS |
| 122 | packages+=(nfs-utils nfs-utils-lib) |
| 123 | ;; |
| 124 | esac |
| 125 | ;; |
| 126 | |
| 127 | esac |
| 128 | |
| 129 | ${INSTALLER_CMD} ${packages[@]} |
| 130 | if [ $VAGRANT_DEFAULT_PROVIDER == libvirt ]; then |
| 131 | vagrant plugin install vagrant-libvirt |
| 132 | sudo usermod -a -G libvirt $USER |
| 133 | fi |