Skip to content

Instantly share code, notes, and snippets.

@mapio mapio/Vagrantfile
Last active Aug 29, 2015

What would you like to do?
La configurazione di Vagrant per la macchina virtuale codebox4im
function _cleanup {
echo "*** Cleaning up"
apt-get -y autoremove
apt-get -y autoclean
) >> /tmp/provision.log 2>&1
function _fixperms {
echo "*** Fixing /home/vagrant permissions and ownership"
chown -R vagrant:vagrant /home/vagrant
chmod -R go= /home/vagrant
) >> /tmp/provision.log 2>&1
function _github {
if ! [ -d /home/vagrant/codebox4im ]; then
echo "*** Cloning 'codebox4im' from GitHub"
sudo -iu vagrant hg clone git://
echo "*** Updating 'codebox4im' from GitHub"
sudo -iu vagrant hg -R codebox4im pull --update
function _provision {
if [ -r "$2" ]; then
echo "*** Already provisioned: $1" 1>&2
elif [ "$(type -t "$1")" == function ]; then
echo "*** Provisioning: $1"
"$1" >> /tmp/provision.log 2>&1 && touch "$2"
echo "*** Provisioning (via apt-get): $1"
apt-get -y install "$1" >> /tmp/provision.log 2>&1 && touch "$2"
function _update {
echo "*** Updating system packages"
if ! [ -r /.codebox4im-updated-on-$(date +%Y%m%d) ]; then
apt-get -y update
apt-get -y dist-upgrade
rm -f /home/vagrant/ /.codebox4im-updated-on-*
touch /.codebox4im-updated-on-$(date +%Y%m%d)
) >> /tmp/provision.log 2>&1
function codebox {
npm install -g codebox
cat > /etc/init/codebox.conf <<-EOF
description "Codebox"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown
respawn # restart when job dies
# Start the Process
env DIR=/home/vagrant/
env NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
exec start-stop-daemon \
--start \
--chuid vagrant \
--make-pidfile --pidfile /var/run/ \
--chdir /home/vagrant --exec /usr/bin/codebox -- \
run workspace >> /var/log/codebox.log 2>&1
touch /var/log/codebox.log
service codebox start
function eclipse {
curl -sL > /tmp/eclipse.tgz
cd /usr/local/lib && tar zxvf /tmp/eclipse.tgz
chown -R root:root /usr/local/lib/eclipse
ln -s /usr/local/lib/eclipse/eclipse /usr/local/bin/
rm /tmp/eclipse.tgz
function getpip {
curl -sL | python
pip install --upgrade --no-use-wheel setuptools
pip install --upgrade pip
function j4im_jar {
mkdir -p /usr/local/share/java
cd /usr/local/share/java
curl -L -o j4im.jar${j4imversion}/j4im-${j4imversion}.jar
chmod -R a+rX /usr/local/share/java
mkdir -p /usr/share/nginx/html/docs
cd /usr/share/nginx/html/docs
curl -L -o /tmp/${j4imversion}/j4im-${j4imversion} && unzip /tmp/ && mv j4im-${j4imversion}-javadoc j4im
chmod -R a+rX /usr/share/nginx/html/docs
function j4im_jar~ {
mkdir -p /usr/local/share/java
cd /usr/local/share/java
curl -L -o j4im.jar${j4imversion}/j4im-${j4imversion}.jar
chmod -R a+rX /usr/local/share/java
mkdir -p /usr/share/nginx/html/docs
cd /usr/share/nginx/html/docs
curl -L -o /tmp/${j4imversion}/j4im-${j4imversion} && unzip /tmp/ && mv j4im-${j4imversion}-javadoc j4im
chmod -R a+rX /usr/share/nginx/html/docs
function java7 {
add-apt-repository -y ppa:webupd8team/java && apt-get -y update
echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections
apt-get -y install libxtst6 oracle-java7-installer
function java_docs {
mkdir -p /usr/share/nginx/html/docs
cd /usr/share/nginx/html/docs
curl -L -C - -b "oraclelicense=accept-securebackup-cookie" -o /tmp/ && unzip /tmp/ && mv docs java
chmod -R a+rX /usr/share/nginx/html/docs
function mercurial {
pip install mercurial
pip install hg-git
cat >/home/vagrant/.hgrc <<-EOF
username = IM Student <>
ignore = ~/.hgignore
style = gitweb
allow_archive = gz zip bz2
[hostfingerprints] = ce:67:99:25:2c:ac:78:12:7d:94:b5:62:2c:31:c5:16:a6:34:73:53 = 24:9c:45:8b:9c:aa:ba:55:4e:01:6d:58:ff:e4:28:7d:2a:14:ae:3b
graphlog =
color =
hggit =
mq =
rebase =
progress =
cat >/home/vagrant/.hgignore <<-EOF
syntax: glob
function nginx {
apt-get -y install nginx
cat >/etc/nginx/sites-available/codebox <<-'EOF'
server {
listen 80;
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_max_temp_file_size 0;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
rewrite ^/start$ permanent;
location /start/ {
root /usr/share/nginx/html;
rewrite ^/docs$ permanent;
location /docs/ {
root /usr/share/nginx/html;
mkdir -p /usr/share/nginx/html/start
cat >/usr/share/nginx/html/start/index.html <<-'EOF'
<!DOCTYPE html>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
<li>Accesso all'<a href="/?email=codebox&amp;token=codebox">IDE</a>,</li>
<li>Documentazione locale:
<li>Java SE <a href="/docs/java/">General Documentation</a> e <a href="/docs/java/api/">API Specification</a>,</li>
<li>Libreria <a href="/docs/prog/"><samp>prog</samp></a>,</li>
<li>Libreria <a href="/docs/j4im/"><samp>j4im</samp></a>,</li>
<p>Copyright 2014, Massimo Santini - <a href=""></a>.</p>
rm -f /etc/nginx/sites-enabled/default
ln -s /etc/nginx/sites-available/codebox /etc/nginx/sites-enabled/
/etc/init.d/nginx reload
function nodejs {
curl -L | sudo bash -
apt-get install -y nodejs
function prog_jar {
mkdir -p /usr/local/share/java
cd /usr/local/share/java
curl -L -o prog.jar
chmod -R a+rX /usr/local/share/java
mkdir -p /usr/share/nginx/html/docs
cd /usr/share/nginx/html/docs
curl -L -o /tmp/ && unzip /tmp/ && mv doc prog
chmod -R a+rX /usr/share/nginx/html/docs
function sound {
apt-get -y install alsa-base linux-image-extra-$(uname -r)
modprobe snd-intel8x0
echo snd-intel8x0 >> /etc/modules
usermod -a -G audio vagrant
function userfiles {
cat >/home/vagrant/.inputrc <<-EOF
# silence!
set bell-style none
# be 8 bit clean
set input-meta on
set output-meta on
set convert-meta off
# Mac OSX filenames
set completion-ignore-case on
# misc
"\e[3~": delete-char
"\C-h": backward-delete-char
"\e[6~": history-search-forward
"\e[5~": history-search-backward
# python
Tab: complete
cat > /home/vagrant/.bash_aliases <<-EOF
# codebox4im aliases
alias l='/bin/ls -Ghl'
cat >> /home/vagrant/.bashrc <<-'EOF'
export CLASSPATH="${CLASSPATH:+$CLASSPATH:}".:/usr/local/share/java/prog.jar:/usr/local/share/java/j4im.jar
export PS1='[\W]\$ '
mkdir -p /home/vagrant/.pip
cat > /home/vagrant/.pip/pip.conf <<-EOF
download_cache = ~/.pip/cache
rm -rf /home/vagrant/.npm
mkdir /home/vagrant/workspace
function virtualenvs {
sudo -iu vagrant virtualenv -p /usr/bin/python2 /home/vagrant/.venv
# Update the package archive
export DEBIAN_FRONTEND=noninteractive
# Provisioned via apt-get install
_provision unzip /usr/bin/unzip
_provision g++ /usr/bin/g++
_provision git /usr/bin/git
_provision python-dev /usr/include/python2.7/Python.h
# Provisioned by a function
_provision sound /lib/modules/$(uname -r)/kernel/sound/pci/snd-intel8x0.ko
_provision getpip /usr/local/bin/pip
_provision nodejs /usr/bin/nodejs
_provision codebox /usr/bin/codebox
_provision java7 /usr/lib/jvm/java-7-oracle/jre/bin/java
_provision prog_jar /usr/local/share/java/prog.jar
_provision j4im_jar /usr/local/share/java/j4im.jar
_provision java_docs /usr/share/nginx/html/docs/java/index.html
_provision mercurial /usr/local/bin/hg
_provision userfiles /home/vagrant/.userfiles
_provision nginx /usr/sbin/nginxx
# Finalizing
mkdir -p /usr/local/share/java
cd /usr/local/share/java
rm -f prog.jar j4im.jar
echo "Installing prog.jar..."
curl -L -o prog.jar >/dev/null 2>&1
echo "Installing j4im.jar..."
curl -L -o j4im.jar${j4imversion}/j4im-${j4imversion}.jar >/dev/null 2>&1
chmod -R a+rX /usr/local/share/java
mkdir -p /usr/share/nginx/html/docs
cd /usr/share/nginx/html/docs
rm -rf prog j4im
echo "Installing prog api documentation..."
( curl -L -o /tmp/ && unzip /tmp/ && mv doc prog ) >/dev/null 2>&1
echo "Installing j4im api documentation..."
( curl -L -o /tmp/${j4imversion}/j4im-${j4imversion} && unzip /tmp/ && mv j4im-${j4imversion}-javadoc j4im ) >/dev/null 2>&1
chmod -R a+rX /usr/share/nginx/html/docs
echo "Done."
Vagrant.configure("2") do |config|
if ARGV[0] == 'up' || ARGV[0] == 'provision' || ARGV[0] == 'reload'
if File.exists?( '' )
$provisioning_script = '' ).read
$stderr.puts( "Using '' for provisioning...\n" )
require 'net/http'
$provisioning_script = Net::HTTP.get(URI(''))
$stderr.puts( "Downloaded gist #ef23edceb8a5709b87d0 for provisioning...\n" ) '', 'w' ) { |f| f.write( $provisioning_script ); f.close() }
$audio = 'null'
if Vagrant::Util::Platform.linux?
$audio = 'alsa'
elsif Vagrant::Util::Platform.darwin?
$audio = 'coreaudio'
$audio = 'dsound'
$stderr.puts( "Audio will be set to '" + $audio + "'\n" )
if Vagrant.has_plugin?("vagrant-cachier")
config.cache.scope = :box
config.vm.provider "virtualbox" do |v|
v.customize ['modifyvm', :id, '--audio', $audio, '--audiocontroller', 'ac97']
config.vm.define :codebox4im do |codebox4im| = "ubuntu/trusty32" :forwarded_port, guest: 80, host: 8000
codebox4im.vm.provision :shell, :inline => $provisioning_script
config.vm.post_up_message = "Apri l'indirizzo per iniziare!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.