#!/bin/bash set -euo pipefail # This script exists to find out if you have vagrant and libvirt set # up, and to help you do first-time setup tasks so you can run the # installer tests. # These two functions are borrowed from install.sh. proc error { if test $Argc != 0 { echo -en '\e[0;31m' > !2 echo @Argv | shell {fold -s || cat} >&2 echo -en '\e[0m' > !2 } } proc fail { error @Argv exit 1 } # Look for executable dependencies. for dep in [vagrant pip] { which $dep > /dev/null || fail "Please install $dep(1)." } # If on a Debian/Ubuntu system, and the dependencies for installing the Vagrant plugins we # need aren't present, bail out and print an error message. if test -f /etc/debian_version { for package in [zlib1g-dev ruby-dev libvirt-dev qemu-utils] { if ! test -e /usr/share/doc/$(package) { echo "Seems you should run: sudo apt-get install -y $(package)" exit 1 } } } # Check if Vagrant has plugins we need; if not, we install them. # # vagrant-libvirt plugin: used to run VMs via qemu. # # vagrant-mutate: used to convert VMs into qemu format. for vgplugin in [vagrant-mutate vagrant-libvirt] { shell {vagrant plugin list | grep -q $vgplugin} || vagrant plugin install $vgplugin } cd $[mktemp -d] git clone https://github.com/sciurus/vagrant-mutate cd vagrant-mutate rake build vagrant plugin install pkg/vagrant-mutate-1.2.0.gem # Also get vagrant-mutate from git, due to this bug: # https://github.com/sciurus/vagrant-mutate/issues/88 # Download this particular random Debian Jessie VM and then convert it to # libvirt format. shell {vagrant box list | grep -q thoughtbot_jessie} || vagrant box add thoughtbot_jessie https://vagrantcloud.com/thoughtbot/boxes/debian-jessie-64/versions/0.1.0/providers/virtualbox.box shell {vagrant box list | grep -q 'thoughtbot_jessie.*libvirt'} || vagrant mutate thoughtbot_jessie libvirt # Do the same for the main Trusty (Ubuntu 14.04) VM. shell {vagrant box list | grep -q 'trusty64'} || vagrant box add trusty64 https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box shell {vagrant box list | grep -q 'trusty64.*libvirt'} || vagrant mutate trusty64 libvirt # Do the same for a 32-bit Debian VM. shell {vagrant box list | grep -q 'debian-7.8-32-nocm'} || vagrant box add debian-7.8-32-nocm https://vagrantcloud.com/puppetlabs/boxes/debian-7.8-32-nocm/versions/1.0.2/providers/virtualbox.box shell {vagrant box list | grep -q 'debian-7.8-32-nocm.*libvirt'} || vagrant mutate debian-7.8-32-nocm libvirt # Do the same for the main Precise (Ubuntu 12.04) VM. shell {vagrant box list | grep -q 'precise64'} || vagrant box add precise64 https://vagrantcloud.com/hashicorp/boxes/precise64/versions/1.1.0/providers/virtualbox.box shell {vagrant box list | grep -q 'precise64.*libvirt'} || vagrant mutate precise64 libvirt # Do the same for a CentOS base box. See notes in Vagrantfile about that. shell {vagrant box list | grep -q 'centos7_convertible'} || vagrant box add centos7_convertible http://cloud.centos.org/centos/7/vagrant/x86_64/images/CentOS-7-x86_64-Vagrant-1609_01.VirtualBox.box shell {vagrant box list | grep -q 'centos7_convertible.*libvirt'} || vagrant mutate centos7_convertible libvirt --input-provider virtualbox # Download the latest released version of Asheesh's stodgy-tester tool, if it is absent. if test ! -f ~/.local/bin/stodgy-tester { pip install --user --upgrade git+https://github.com/paulproteus/stodgy-tester.git#egg=stodgy-tester } (CommandList children: [ (C {(set)} {(-euo)} {(pipefail)}) (FuncDef name: error body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_Pound "$#")} {(KW_Bang "!") (Lit_Other "=")} {(0)} {(Lit_Other "]")} ) terminator: ) ] action: [ (SimpleCommand words: [{(echo)} {(-en)} {(SQ <"\\e[0;31m">)}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[56])] ) (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_At "$@"))}) (Subshell child: (AndOr children:[(C {(fold)} {(-s)})(C {(cat)})] op_id:Op_DPipe) redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[78])] spids: [68 76] ) ] negated: False ) (SimpleCommand words: [{(echo)} {(-en)} {(SQ <"\\e[0m">)}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[90])] ) ] spids: [-1 45] ) ] spids: [-1 94] ) ] spids: [28] ) spids: [24 27] ) (FuncDef name: fail body: (BraceGroup children: [(C {(error)} {(DQ ($ VSub_At "$@"))}) (C {(exit)} {(1)})] spids: [103] ) spids: [99 102] ) (ForEach iter_name: dep iter_words: [{(vagrant)} {(pip)}] do_arg_iter: False body: (DoGroup children: [ (AndOr children: [ (SimpleCommand words: [{(which)} {($ VSub_Name "$dep")}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[142])] ) (C {(fail)} {(DQ ("Please install ") ($ VSub_Name "$dep") ("(1)."))}) ] op_id: Op_DPipe ) ] spids: [135 156] ) spids: [128 133] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-f)} {(/etc/debian_version)} {(Lit_Other "]")}) terminator: ) ] action: [ (ForEach iter_name: package iter_words: [{(zlib1g-dev)} {(ruby-dev)} {(libvirt-dev)} {(qemu-utils)}] do_arg_iter: False body: (DoGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (Pipeline children: [ (C {(Lit_Other "[")} {(-e)} {(/usr/share/doc/) (${ VSub_Name package)} {(Lit_Other "]")} ) ] negated: True ) terminator: ) ] action: [ (C {(echo)} { (DQ ("Seems you should run: sudo apt-get install -y ") (${ VSub_Name package) ) } ) (C {(exit)} {(1)}) ] spids: [-1 215] ) ] spids: [-1 233] ) ] spids: [195 236] ) spids: [185 193] ) ] spids: [-1 177] ) ] spids: [-1 238] ) (ForEach iter_name: vgplugin iter_words: [{(vagrant-mutate)} {(vagrant-libvirt)}] do_arg_iter: False body: (DoGroup children: [ (AndOr children: [ (Subshell child: (Pipeline children: [ (C {(vagrant)} {(plugin)} {(list)}) (C {(grep)} {(-q)} {(DQ ($ VSub_Name "$vgplugin"))}) ] negated: False ) spids: [269 285] ) (C {(vagrant)} {(plugin)} {(install)} {(DQ ($ VSub_Name "$vgplugin"))}) ] op_id: Op_DPipe ) ] spids: [266 299] ) spids: [260 264] ) (C {(cd)} { (CommandSubPart command_list: (CommandList children:[(C {(mktemp)} {(-d)})]) left_token: spids: [303 307] ) } ) (C {(git)} {(clone)} {(https) (Lit_Other ":") (//github.com/sciurus/vagrant-mutate)}) (C {(cd)} {(vagrant-mutate)}) (C {(rake)} {(build)}) (C {(vagrant)} {(plugin)} {(install)} {(pkg/vagrant-mutate-1.2.0.gem)}) (AndOr children: [ (Subshell child: (Pipeline children: [(C {(vagrant)} {(box)} {(list)}) (C {(grep)} {(-q)} {(thoughtbot_jessie)})] negated: False ) spids: [348 362] ) (C {(vagrant)} {(box)} {(add)} {(thoughtbot_jessie)} {(https) (Lit_Other ":") ( //vagrantcloud.com/thoughtbot/boxes/debian-jessie-64/versions/0.1.0/providers/virtualbox.box ) } ) ] op_id: Op_DPipe ) (AndOr children: [ (Subshell child: (Pipeline children: [ (C {(vagrant)} {(box)} {(list)}) (C {(grep)} {(-q)} {(SQ <"thoughtbot_jessie.*libvirt">)}) ] negated: False ) spids: [378 394] ) (C {(vagrant)} {(mutate)} {(thoughtbot_jessie)} {(libvirt)}) ] op_id: Op_DPipe ) (AndOr children: [ (Subshell child: (Pipeline children: [(C {(vagrant)} {(box)} {(list)}) (C {(grep)} {(-q)} {(SQ )})] negated: False ) spids: [410 426] ) (C {(vagrant)} {(box)} {(add)} {(trusty64)} {(https) (Lit_Other ":") ( //cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box ) } ) ] op_id: Op_DPipe ) (AndOr children: [ (Subshell child: (Pipeline children: [ (C {(vagrant)} {(box)} {(list)}) (C {(grep)} {(-q)} {(SQ <"trusty64.*libvirt">)}) ] negated: False ) spids: [442 458] ) (C {(vagrant)} {(mutate)} {(trusty64)} {(libvirt)}) ] op_id: Op_DPipe ) (AndOr children: [ (Subshell child: (Pipeline children: [(C {(vagrant)} {(box)} {(list)}) (C {(grep)} {(-q)} {(SQ )})] negated: False ) spids: [474 490] ) (C {(vagrant)} {(box)} {(add)} {(debian-7.8-32-nocm)} {(https) (Lit_Other ":") ( //vagrantcloud.com/puppetlabs/boxes/debian-7.8-32-nocm/versions/1.0.2/providers/virtualbox.box ) } ) ] op_id: Op_DPipe ) (AndOr children: [ (Subshell child: (Pipeline children: [ (C {(vagrant)} {(box)} {(list)}) (C {(grep)} {(-q)} {(SQ <"debian-7.8-32-nocm.*libvirt">)}) ] negated: False ) spids: [506 522] ) (C {(vagrant)} {(mutate)} {(debian-7.8-32-nocm)} {(libvirt)}) ] op_id: Op_DPipe ) (AndOr children: [ (Subshell child: (Pipeline children: [(C {(vagrant)} {(box)} {(list)}) (C {(grep)} {(-q)} {(SQ )})] negated: False ) spids: [538 554] ) (C {(vagrant)} {(box)} {(add)} {(precise64)} {(https) (Lit_Other ":") (//vagrantcloud.com/hashicorp/boxes/precise64/versions/1.1.0/providers/virtualbox.box) } ) ] op_id: Op_DPipe ) (AndOr children: [ (Subshell child: (Pipeline children: [ (C {(vagrant)} {(box)} {(list)}) (C {(grep)} {(-q)} {(SQ <"precise64.*libvirt">)}) ] negated: False ) spids: [570 586] ) (C {(vagrant)} {(mutate)} {(precise64)} {(libvirt)}) ] op_id: Op_DPipe ) (AndOr children: [ (Subshell child: (Pipeline children: [ (C {(vagrant)} {(box)} {(list)}) (C {(grep)} {(-q)} {(SQ )}) ] negated: False ) spids: [602 618] ) (C {(vagrant)} {(box)} {(add)} {(centos7_convertible)} {(http) (Lit_Other ":") ( //cloud.centos.org/centos/7/vagrant/x86_64/images/CentOS-7-x86_64-Vagrant-1609_01.VirtualBox.box ) } ) ] op_id: Op_DPipe ) (AndOr children: [ (Subshell child: (Pipeline children: [ (C {(vagrant)} {(box)} {(list)}) (C {(grep)} {(-q)} {(SQ <"centos7_convertible.*libvirt">)}) ] negated: False ) spids: [634 650] ) (C {(vagrant)} {(mutate)} {(centos7_convertible)} {(libvirt)} {(--input-provider)} {(virtualbox)}) ] op_id: Op_DPipe ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(KW_Bang "!")} {(-f)} {(TildeSubPart prefix:"") (/.local/bin/stodgy-tester)} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(pip)} {(install)} {(--user)} {(--upgrade)} {(git) (Lit_Other "+") (https) (Lit_Other ":") (//github.com/paulproteus/stodgy-tester.git) (Lit_Pound "#") (Lit_VarLike "egg=") (stodgy-tester) } ) ] spids: [-1 685] ) ] spids: [-1 705] ) ] )