From d9912ac43e87001969b9baa873217346abf75c16 Mon Sep 17 00:00:00 2001 From: Peter Magnusson Date: Fri, 17 Jan 2014 13:53:15 +0100 Subject: [PATCH] Added support for building in vagrant --- .gitignore | 4 ++ Vagrantfile | 20 ++++++++ doc/building-on-vagrant.md | 29 ++++++++++++ scripts/activate | 30 ++++++++++++ scripts/bin/twister | 37 +++++++++++++++ scripts/vagrant_bootstrap.sh | 88 ++++++++++++++++++++++++++++++++++++ 6 files changed, 208 insertions(+) create mode 100644 Vagrantfile create mode 100644 doc/building-on-vagrant.md create mode 100644 scripts/activate create mode 100644 scripts/bin/twister create mode 100644 scripts/vagrant_bootstrap.sh diff --git a/.gitignore b/.gitignore index bf16a518..622f7a0b 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,10 @@ src/test_bitcoin *.patch .bitcoin +#vagrant part +vagrant +.vagrant + # Compilation and Qt preprocessor part *.qm Makefile diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 00000000..ab17d938 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,20 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure("2") do |config| + + config.vm.box = 'debian7' + config.vm.box_url = 'http://puppet-vagrant-boxes.puppetlabs.com/debian-70rc1-x64-vbox4210.box' + + config.vm.provider "virtualbox" do |v| + v.customize ["modifyvm", :id, "--memory", 1024] + end + + #config.vm.synced_folder '.', '/srv/Mailpile' + + + config.vm.network :public_network + config.vm.network :forwarded_port, guest: 28332, host: 28332, guest_ip: '127.0.0.1' + + config.vm.provision :shell, :path => 'scripts/vagrant_bootstrap.sh' +end diff --git a/doc/building-on-vagrant.md b/doc/building-on-vagrant.md new file mode 100644 index 00000000..cc88191e --- /dev/null +++ b/doc/building-on-vagrant.md @@ -0,0 +1,29 @@ +# Vagrant + Debian building instructions + +This will run a virtual machine with all tools required to build and run twister +using Vagrant. +This will probably work wherever vagrant can be installed. + +## Dependencies +* http://www.vagrantup.com/ +* https://www.virtualbox.org/ + + +## Install +1. git clone https://github.com/miguelfreitas/twister-core.git +1. cd twister-core +1. vagrant up + + + +## Tweeking +If you have lots of ram in your machine, feel free to use it +edit the twister-core/Vagrantfile and change the line +``` +v.customize ["modifyvm", :id, "--memory", 1024] +``` +and write 2048, 4096 or whatever you feel resonable +before running vagrant up. + +This will make compile time and life in general much +better in the virtual machine. \ No newline at end of file diff --git a/scripts/activate b/scripts/activate new file mode 100644 index 00000000..2fdccca3 --- /dev/null +++ b/scripts/activate @@ -0,0 +1,30 @@ +#!/bin/bash +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +export TWISTER_CORE_PATH='/home/vagrant/twister-core' +export TWISTER_HOME='/home/vagrant/.twister' + +alias twisterd='$TWISTER_CORE_PATH/src/twisterd' + + + +if [ ! -n "$TWISTER_OLD_PATH" ]; then + echo 'setting up the environment' + export TWISTER_OLD_PATH=$PATH + export TWISTER_OLD_PS1=$PS1 + export PATH=$DIR/bin:$PATH + export PS1="(twister)$PS1\n> " +else + echo 'already active' +fi + +function deactivate { + if [ -n "$TWISTER_OLD_PATH" ]; then + echo 'cleaning up the environment' + export PATH=$TWISTER_OLD_PATH + export PS1=$TWISTER_OLD_PS1 + unset TWISTER_OLD_PATH + unset TWISTER_OLD_PS1 + unset -f deactivate + fi +} \ No newline at end of file diff --git a/scripts/bin/twister b/scripts/bin/twister new file mode 100644 index 00000000..b5c82cb3 --- /dev/null +++ b/scripts/bin/twister @@ -0,0 +1,37 @@ +#!/bin/bash + +RPCUSER='user' +RPCPASSWORD='pwd' +RPCALLOWIP='127.0.0.1' + +BIN=$TWISTER_CORE_PATH/src/twisterd + +CONFFILE="$TWISTER_HOME/twister.conf" + +OPTS="-daemon -debug" +if [ ! -f "$CONFFILE" ]; then + OPTS='$OPTS -pid=$PIDFILE -rpcuser=$RPCUSER -rpcpassword=$RPCPASSWORD -rpcallowip=$RPCALLOWIP' +fi + + +function usage { + echo "Usage : $(basename $0) start|stop" + echo + exit +} + +if [ $# -lt 1 ] +then + usage $@ +fi + +case "$1" in + start) $BIN $OPTS + echo + ;; + stop) $BIN stop + ;; + *) echo "Invalid option: $1" + usage $@ + ;; +esac \ No newline at end of file diff --git a/scripts/vagrant_bootstrap.sh b/scripts/vagrant_bootstrap.sh new file mode 100644 index 00000000..35f94465 --- /dev/null +++ b/scripts/vagrant_bootstrap.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +TWISTER_CORE_PATH='/home/vagrant/twister-core' +TWISTER_HOME='/home/vagrant/.twister' +AS_VAGRANT='sudo -u vagrant' + +function failed { + echo + echo 'Something failed !!!!!' + echo + exit 1 +} +function checkfail { + if [ ! $? -eq 0 ]; then + failed + fi + sleep 3 +} + +echo +echo 'Running bootstrap for twister-core' +echo +$AS_VAGRANT ln -s /vagrant $TWISTER_CORE_PATH + + +echo '.. fixing permissions' +cd $TWISTER_CORE_PATH +find $TWISTER_CORE_PATH/scripts -type d -exec chmod 755 {} \; +find $TWISTER_CORE_PATH/scripts -type f -exec chmod 644 {} \; +chmod 755 $TWISTER_CORE_PATH/scripts/bin/* +apt-get update + + +echo '.. installing tools and libraries' +apt-get install -y git build-essential autoconf libtool libssl-dev libboost-all-dev libdb++-dev libminiupnpc-dev openssl +checkfail + + +echo '.. bootstrapping libtorrent' +cd $TWISTER_CORE_PATH/libtorrent +$AS_VAGRANT ./bootstrap.sh +checkfail +$AS_VAGRANT ./configure --enable-logging --enable-debug --enable-dht +checkfail + + +echo '.. compiling' +cd $TWISTER_CORE_PATH/src +$AS_VAGRANT make -f makefile.unix +checkfail + + +echo '.. configuration & web gui' +$AS_VAGRANT mkdir $TWISTER_HOME +cd $TWISTER_HOME +$AS_VAGRANT touch twister.conf +echo -e "rpcuser=user\nrpcpassword=pwd\nrpcallowip=127.0.0.1" > twister.conf +chmod 600 twister.conf +git clone https://github.com/miguelfreitas/twister-html.git html +checkfail + + + + +if [ $? -eq 0 ]; then + echo + echo '==================================================================' + echo " +Done. +To start the web interface, enter the following command: + $ vagrant ssh -c '$TWISTER_CORE_PATH/src/twisterd -daemon -debug' +Open http://127.0.0.1:28332/index.html and use the user/pwd credentials +Create your account ! + +If you want to do some development or other stuff then... + $ vargrant ssh + $ source twister-core/scripts/activate + + This will give you some nice to have commands like + * twister start|stop - to start and stop the server + * twisted - alias to ~/twisted-core/src/twisted + + Good luck! + " +else + failed + +fi \ No newline at end of file