Last active
August 29, 2015 14:07
-
-
Save mapio/ef23edceb8a5709b87d0 to your computer and use it in GitHub Desktop.
La configurazione di Vagrant per la macchina virtuale codebox4im
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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://github.com/mapio/codebox4im.git | |
else | |
echo "*** Updating 'codebox4im' from GitHub" | |
sudo -iu vagrant hg -R codebox4im pull --update | |
fi | |
} | |
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" | |
else | |
echo "*** Provisioning (via apt-get): $1" | |
apt-get -y install "$1" >> /tmp/provision.log 2>&1 && touch "$2" | |
fi | |
} | |
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/postinstall.sh /.codebox4im-updated-on-* | |
touch /.codebox4im-updated-on-$(date +%Y%m%d) | |
fi | |
) >> /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/codebox.pid \ | |
--chdir /home/vagrant --exec /usr/bin/codebox -- \ | |
run workspace >> /var/log/codebox.log 2>&1 | |
EOF | |
touch /var/log/codebox.log | |
service codebox start | |
} | |
function eclipse { | |
curl -sL http://mirror.switch.ch/eclipse/technology/epp/downloads/release/juno/SR2/eclipse-java-juno-SR2-linux-gtk.tar.gz > /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 https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python | |
pip install --upgrade --no-use-wheel setuptools | |
pip install --upgrade pip | |
} | |
function j4im_jar { | |
j4imversion="0.5-beta" | |
mkdir -p /usr/local/share/java | |
cd /usr/local/share/java | |
curl -L -o j4im.jar https://github.com/mapio/j4im/releases/download/${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/j4im.zip https://github.com/mapio/j4im/releases/download/${j4imversion}/j4im-${j4imversion}-javadoc.zip && unzip /tmp/j4im.zip && mv j4im-${j4imversion}-javadoc j4im | |
chmod -R a+rX /usr/share/nginx/html/docs | |
} | |
function j4im_jar~ { | |
j4imversion="0.5-beta" | |
mkdir -p /usr/local/share/java | |
cd /usr/local/share/java | |
curl -L -o j4im.jar https://github.com/mapio/j4im/releases/download/${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/j4im.zip https://github.com/mapio/j4im/releases/download/${j4imversion}/j4im-${j4imversion}-javadoc.zip && unzip /tmp/j4im.zip && 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/java.zip http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-apidocs.zip && unzip /tmp/java.zip && 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 | |
[ui] | |
username = IM Student <none@none.com> | |
ignore = ~/.hgignore | |
[web] | |
style = gitweb | |
allow_archive = gz zip bz2 | |
[hostfingerprints] | |
github.com = ce:67:99:25:2c:ac:78:12:7d:94:b5:62:2c:31:c5:16:a6:34:73:53 | |
bitbucket.org = 24:9c:45:8b:9c:aa:ba:55:4e:01:6d:58:ff:e4:28:7d:2a:14:ae:3b | |
[extensions] | |
graphlog = | |
color = | |
hggit = | |
mq = | |
rebase = | |
progress = | |
EOF | |
cat >/home/vagrant/.hgignore <<-EOF | |
syntax: glob | |
*.elc | |
*.pyc | |
*~ | |
.DS_Store | |
EOF | |
} | |
function nginx { | |
apt-get -y install nginx | |
cat >/etc/nginx/sites-available/codebox <<-'EOF' | |
server { | |
listen 80; | |
location / { | |
proxy_pass http://127.0.0.1:8000/; | |
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$ http://127.0.0.1:8000/start/ permanent; | |
location /start/ { | |
root /usr/share/nginx/html; | |
} | |
rewrite ^/docs$ http://127.0.0.1:8000/docs/ permanent; | |
location /docs/ { | |
root /usr/share/nginx/html; | |
} | |
} | |
EOF | |
mkdir -p /usr/share/nginx/html/start | |
cat >/usr/share/nginx/html/start/index.html <<-'EOF' | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>codebox4im</title> | |
<style> | |
body { | |
width: 35em; | |
margin: 0 auto; | |
font-family: Tahoma, Verdana, Arial, sans-serif; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>codebox4im</h1> | |
<ul> | |
<li>Accesso all'<a href="/?email=codebox&token=codebox">IDE</a>,</li> | |
<li>Documentazione locale: | |
<ul> | |
<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> | |
</ul> | |
</li> | |
</ul> | |
<p>Copyright 2014, Massimo Santini - <a href="https://github.com/mapio/codebox4im">https://github.com/mapio/codebox4im</a>.</p> | |
</body> | |
</html> | |
EOF | |
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 https://deb.nodesource.com/setup | 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 http://pighizzini.di.unimi.it/jb/librerie/prog-3ed.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/prog.zip http://pighizzini.di.unimi.it/jb/librerie/prog-doc-3ed.zip && unzip /tmp/prog.zip && 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 | |
EOF | |
cat > /home/vagrant/.bash_aliases <<-EOF | |
# codebox4im aliases | |
alias l='/bin/ls -Ghl' | |
EOF | |
cat >> /home/vagrant/.bashrc <<-'EOF' | |
export CLASSPATH="${CLASSPATH:+$CLASSPATH:}".:/usr/local/share/java/prog.jar:/usr/local/share/java/j4im.jar | |
export PS1='[\W]\$ ' | |
EOF | |
mkdir -p /home/vagrant/.pip | |
cat > /home/vagrant/.pip/pip.conf <<-EOF | |
[global] | |
download_cache = ~/.pip/cache | |
EOF | |
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 | |
_update | |
# 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 | |
_fixperms | |
_cleanup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
j4imversion="0.5-beta" | |
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 http://pighizzini.di.unimi.it/jb/librerie/prog-3ed.jar >/dev/null 2>&1 | |
echo "Installing j4im.jar..." | |
curl -L -o j4im.jar https://github.com/mapio/j4im/releases/download/${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/prog.zip http://pighizzini.di.unimi.it/jb/librerie/prog-doc-3ed.zip && unzip /tmp/prog.zip && mv doc prog ) >/dev/null 2>&1 | |
echo "Installing j4im api documentation..." | |
( curl -L -o /tmp/j4im.zip https://github.com/mapio/j4im/releases/download/${j4imversion}/j4im-${j4imversion}-javadoc.zip && unzip /tmp/j4im.zip && mv j4im-${j4imversion}-javadoc j4im ) >/dev/null 2>&1 | |
chmod -R a+rX /usr/share/nginx/html/docs | |
echo "Done." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vagrant.configure("2") do |config| | |
if ARGV[0] == 'up' || ARGV[0] == 'provision' || ARGV[0] == 'reload' | |
if File.exists?( 'provision.sh' ) | |
$provisioning_script = File.open( 'provision.sh' ).read | |
$stderr.puts( "Using 'provision.sh' for provisioning...\n" ) | |
else | |
require 'net/http' | |
$provisioning_script = Net::HTTP.get(URI('https://gist.githubusercontent.com/mapio/ef23edceb8a5709b87d0/raw/provision.sh')) | |
$stderr.puts( "Downloaded gist #ef23edceb8a5709b87d0 for provisioning...\n" ) | |
File.open( 'provision.sh', 'w' ) { |f| f.write( $provisioning_script ); f.close() } | |
end | |
$audio = 'null' | |
if Vagrant::Util::Platform.linux? | |
$audio = 'alsa' | |
elsif Vagrant::Util::Platform.darwin? | |
$audio = 'coreaudio' | |
elsif Vagrant::Util::Platform.windows? | |
$audio = 'dsound' | |
end | |
$stderr.puts( "Audio will be set to '" + $audio + "'\n" ) | |
end | |
if Vagrant.has_plugin?("vagrant-cachier") | |
config.cache.scope = :box | |
end | |
config.vm.provider "virtualbox" do |v| | |
v.customize ['modifyvm', :id, '--audio', $audio, '--audiocontroller', 'ac97'] | |
end | |
config.vm.define :codebox4im do |codebox4im| | |
codebox4im.vm.box = "ubuntu/trusty32" | |
codebox4im.vm.network :forwarded_port, guest: 80, host: 8000 | |
codebox4im.vm.provision :shell, :inline => $provisioning_script | |
end | |
config.vm.post_up_message = "Apri l'indirizzo http://127.0.0.1:8000/start/ per iniziare!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment