Skip to content

Instantly share code, notes, and snippets.

@yzen
Last active December 29, 2015 20:19
Show Gist options
  • Save yzen/7723421 to your computer and use it in GitHub Desktop.
Save yzen/7723421 to your computer and use it in GitHub Desktop.
A Vagrantfile that bootstraps your B2G build environment with Ubuntu 12.04 and host B2G source.This script is compatible with keon and inari. If you want to add other devices, make sure you add the appropriate a usbfilter and the android rule.
# -*- mode: ruby -*-
# vi: set ft=ruby :
# To use this script and prepare your build environment, run the following
# command in the same directory as the Vagrantfile.
# B2G_PATH={path to your B2G directory} vagrant up
VAGRANTFILE_API_VERSION = "2"
# This script will be run on the first start and it will set up the build
# environment.
# All you need to do afterwards is:
# * vagrant ssh
# * Unplug/Plug the phone; run adb devices to make sure that the phone is
# listed.
# * cd B2G
# * ./configure.sh {your device}
# * ./build.sh
$bootstrap = <<SCRIPT
# Installing all build prerequisites.
apt-get update
apt-get install -y python-software-properties
add-apt-repository -y ppa:nilarimogard/webupd8
apt-get update
apt-get install -y autoconf2.13 bison bzip2 ccache curl flex gawk gcc g++ g++-multilib git ia32-libs lib32ncurses5-dev lib32z1-dev libgl1-mesa-dev libx11-dev libasound2 make zip android-tools-adb libxml2-utils
# Set ccache max size to 3GB
ccache --max-size 3GB
# Set the permission filters to the right devices.
cat <<EOF >> /etc/udev/rules.d/android.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="19d2", MODE="0666", GROUP="vagrant"
SUBSYSTEM=="usb", ATTR{idVendor}=="05c6", MODE="0666", GROUP="vagrant"
EOF
cat <<EOF >> /etc/udev/rules.d/51-android.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666", GROUP="vagrant"
SUBSYSTEM=="usb", ATTR{idVendor}=="05c6", MODE="0666", GROUP="vagrant"
EOF
chmod a+r /etc/udev/rules.d/android.rules
chmod a+r /etc/udev/rules.d/51-android.rules
service udev restart
# Not sure if it's necessary but the build complaints about the Java version.
apt-get purge -y openjdk*
add-apt-repository -y ppa:webupd8team/java
apt-get update
echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
apt-get install -y oracle-java7-installer
SCRIPT
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise64"
# Run the bootsrap script on start.
config.vm.provision "shell", inline: $bootstrap
# Use ubuntu 12.04
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
# Assign static IP to be able to use nfs option (if you have a conflict,
# change it to something else).
config.vm.network "private_network", ip: "192.168.50.4"
# Use B2G_PATH environment variable to sync with vm's /home/vagrant/B2G
# directory.
config.vm.synced_folder ENV['B2G_PATH'], "/home/vagrant/B2G", type: "nfs",
nfs_udp: true
config.vm.provider "virtualbox" do |v|
# Enable 4GB of RAM
v.customize ["modifyvm", :id, "--memory", "4096"]
# Enable usb
v.customize ["modifyvm", :id, "--usb", "on"]
# Filter the following devices:
v.customize ['usbfilter', 'add', '0', '--target', :id, '--name', 'zte', '--vendorid', '0x19d2']
v.customize ['usbfilter', 'add', '0', '--target', :id, '--name', 'qualcomm', '--vendorid', '0x05c6']
v.customize ['usbfilter', 'add', '0', '--target', :id, '--name', 'google', '--vendorid', '0x18d1']
end
end
@gasolin
Copy link

gasolin commented Jan 28, 2014

I start from your gist and expand it with full USB vendor list https://github.com/gasolin/foxbox/blob/master/Vagrantfile

I don't have much experience about vagrant but in future version of foxbox I'd like to make it works in GUI so gaia developer could debug directly in the Virtualbox.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment