Commit aa541fd8 authored by Tails developers's avatar Tails developers

vagrant: Add task to create our squeeze basebox

As we use Veewee to automate the creation of the basebox, we are forced to back
up on the "do not execute Vagrant manually" stance. This is due to the fact that
Veewee is quite hackish and itself calls `vagrant` directly. So we move our
monkey-patching from the Rakefile to the Vagrantfile itself.

In order to support an HTTP proxy, the `preseed.cfg` file that Veewee need is
created beforehands in another Rake task. Proxies bound to localhost will
result in a failure and an explicit error messages.

Note: it is unfortunately not possible to use `definitions.rb` to add
`mirror/http/proxy` to the installer command-line. As the defined proxy is
set by network-preesed, it will prevent the installer from retrieving
the preseed file provided by Veewee on a local interface.
parent 703e118c
......@@ -29,3 +29,6 @@
......@@ -20,9 +20,6 @@
require 'rubygems'
require 'vagrant'
# Add Vagrant (monkey-)patch
require 'vagrant/lib/vagrant_verified_download'
# Path to the directory which holds our Vagrantfile
VAGRANT_PATH = File.expand_path('../vagrant', __FILE__)
......@@ -79,3 +76,58 @@ namespace :vm do
abort "'vagrant destroy' failed" unless result
namespace :basebox do
task :create_preseed_cfg do
require 'erb'
require 'uri'
if ENV['http_proxy']
proxy_host = URI.parse(ENV['http_proxy']).host
if ['localhost', '[::1]'].include?(proxy_host) || proxy_host.start_with?('127.0.0.')
abort 'Using an HTTP proxy listening on the loopback is doomed to fail.'
$stderr.puts "Building basebox using HTTP proxy: #{ENV['http_proxy']}"
$stderr.puts "No HTTP proxy set to build basebox"
preseed_cfg_path = File.expand_path('../vagrant/definitions/squeeze/preseed.cfg', __FILE__)
template ="#{preseed_cfg_path}.erb")), 'w') do |f|
f.write template.result
desc 'Create virtual machine template (a.k.a. basebox)'
task :create_basebox => [:create_preseed_cfg] do
# veewee is pretty stupid regarding path handling
Dir.chdir(VAGRANT_PATH) do
require 'veewee'
# Veewee assumes a separate process for each task. So we mimic that.
env = => Vagrant::UI::Basic)
Process.fork do
env.cli('basebox', 'build', 'squeeze')
abort "Building the basebox failed (exit code: #{$?.exitstatus})." if $?.exitstatus != 0
Process.fork do
env.cli('basebox', 'validate', 'squeeze')
abort "Validating the basebox failed (exit code: #{$?.exitstatus})." if $?.exitstatus != 0
Process.fork do
env.cli('basebox', 'export', 'squeeze')
abort "Exporting the basebox failed (exit code: #{$?.exitstatus})." if $?.exitstatus != 0
......@@ -17,15 +17,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <>.
# As we need a monkey-patched Vagrant, we need to disable direct usage
if $PROGRAM_NAME.end_with? 'vagrant'
STDERR.puts <<-END_OF_MESSAGE.gsub(/^ /, '')
This Vagrantfile is not meant to be used directly with `vagrant`, but
through `rake`, using the Rakefile that is present in the root of Tails
exit 1
# Monkey-patched Vagrant!
$:.unshift File.expand_path('../lib', __FILE__)
require 'vagrant_verified_download' do |config| = 'tails'
......@@ -38,6 +38,9 @@ echo "pre-up sleep 5" >> /etc/network/interfaces
# Clean downloaded APT packages
apt-get clean
# Remove HTTP proxy configuration
sed -e '/http::Proxy/d' -i /etc/apt/apt.conf
# Zero out the free space to save space in the final image:
dd if=/dev/zero of=/EMPTY bs=1M
rm -f /EMPTY
......@@ -10,7 +10,7 @@ d-i netcfg/get_domain string
d-i mirror/country string manual
d-i mirror/http/hostname string
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string
d-i mirror/http/proxy string <%= ENV['http_proxy'] %>
# Set clock to UTC
d-i clock-setup/utc boolean true
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment