-
Notifications
You must be signed in to change notification settings - Fork 172
/
Vagrantfile
68 lines (60 loc) · 2.29 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- mode: ruby -*-
# vi: set ft=ruby :
# all helper functions from https://github.com/NextThingCo/CHIP-SDK/pull/15
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each { |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
}
end
return nil
end
# usbfilter_exists and better_usbfilter_add originally part of a pull request
# https://github.com/mitchellh/vagrant/issues/5774
def usbfilter_exists(vendor_id, product_id)
# Determine if a usbfilter with the provided Vendor/Product ID combination
# already exists on this VM.
# NOTE: The "machinereadable" output for usbfilters is more
# complicated to work with (due to variable names including
# the numeric filter index) so we don't use it here.
#
machine_id_filepath = File.join(".vagrant", "machines", "default", "virtualbox", "id")
if not File.exists? machine_id_filepath
# VM hasn't been created yet.
return false
end
machine_id = File.read(machine_id_filepath)
vm_info = `VBoxManage showvminfo #{machine_id}`
filter_match = "VendorId: #{vendor_id}\nProductId: #{product_id}\n"
return vm_info.include? filter_match
end
def better_usbfilter_add(vb, vendor_id, product_id, filter_name)
# This is a workaround for the fact VirtualBox doesn't provide
# a way for preventing duplicate USB filters from being added.
#
# TODO: Implement this in a way that it doesn't get run multiple
# times on each Vagrantfile parsing.
if not usbfilter_exists(vendor_id, product_id)
vb.customize ["usbfilter", "add", "0",
"--target", :id,
"--name", filter_name,
"--vendorid", vendor_id,
"--productid", product_id
]
end
end
Vagrant.configure(2) do |config|
config.vm.box = "bento/ubuntu-16.04"
config.vm.provider "virtualbox" do |v|
v.gui = true
v.customize ['modifyvm', :id, '--usb', 'on']
v.customize ['modifyvm', :id, '--usbxhci', 'on']
better_usbfilter_add(v, "05ac", "8406", "Apple integrated SD card reader")
end
config.vm.provision "shell", inline: <<-SHELL
sudo apt-get update
sudo apt-get install -y curl unzip pv
SHELL
end