From 73e8df12cf3d8ca38efca726ed47e46b5011478d Mon Sep 17 00:00:00 2001 From: kmpm Date: Sat, 18 Jan 2014 02:44:57 +0100 Subject: [PATCH] moved vagrant and changed to ubuntu Also using the new autoconf --- .gitignore | 3 - Vagrantfile | 20 --- contrib/buildenv/.gitignore | 3 + contrib/buildenv/Vagrantfile | 39 ++++++ .../buildenv/scripts}/activate | 2 +- .../buildenv/scripts}/bin/twister | 2 +- contrib/buildenv/scripts/vagrant_bootstrap.sh | 131 ++++++++++++++++++ doc/building-on-vagrant.md | 29 ++-- scripts/vagrant_bootstrap.sh | 88 ------------ 9 files changed, 190 insertions(+), 127 deletions(-) delete mode 100644 Vagrantfile create mode 100644 contrib/buildenv/.gitignore create mode 100644 contrib/buildenv/Vagrantfile rename {scripts => contrib/buildenv/scripts}/activate (92%) rename {scripts => contrib/buildenv/scripts}/bin/twister (92%) mode change 100644 => 100755 create mode 100644 contrib/buildenv/scripts/vagrant_bootstrap.sh delete mode 100644 scripts/vagrant_bootstrap.sh diff --git a/.gitignore b/.gitignore index 4143888b..674b0c7d 100644 --- a/.gitignore +++ b/.gitignore @@ -34,9 +34,6 @@ Makefile.in # *.lo -#vagrant part -vagrant -.vagrant # Compilation and Qt preprocessor part *.qm diff --git a/Vagrantfile b/Vagrantfile deleted file mode 100644 index ab17d938..00000000 --- a/Vagrantfile +++ /dev/null @@ -1,20 +0,0 @@ -# -*- 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/contrib/buildenv/.gitignore b/contrib/buildenv/.gitignore new file mode 100644 index 00000000..c7cdb590 --- /dev/null +++ b/contrib/buildenv/.gitignore @@ -0,0 +1,3 @@ +#vagrant part +vagrant +.vagrant \ No newline at end of file diff --git a/contrib/buildenv/Vagrantfile b/contrib/buildenv/Vagrantfile new file mode 100644 index 00000000..b388cc3c --- /dev/null +++ b/contrib/buildenv/Vagrantfile @@ -0,0 +1,39 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : +require 'time' +timezone = Time.now.zone + + +Vagrant.configure("2") do |config| + + config.vm.define "precise64" do |precise64| + precise64.vm.box = 'precise64' + precise64.vm.box_url = 'http://files.vagrantup.com/precise64.box' + end + + #config.vm.define "saucy64" do |saucy64| + # saucy64.vm.box = 'saucy64' + # saucy64.vm.box_url = 'http://cloud-images.ubuntu.com/vagrant/saucy/current/saucy-server-cloudimg-amd64-vagrant-disk1.box' + #end + + + config.vm.provider "virtualbox" do |v| + v.customize ["modifyvm", :id, "--memory", ENV.fetch('VAGRANT_RAM', 1024)] + v.customize ["modifyvm", :id, "--cpus", ENV.fetch('VAGRANT_CPU', 1)] + v.customize ["modifyvm", :id, "--rtcuseutc", "on"] + end + + + config.vm.synced_folder "../../", "/home/vagrant/twister-core" + + config.vm.network :public_network + config.vm.network :forwarded_port, guest: 28332, host: 28332, host_ip: '127.0.0.1' + + config.vm.provision :shell do |s| + bootstrap = ENV.fetch('DO_BOOTSTRAP', 1) + compile = ENV.fetch('DO_COMPILE', 1) + run = ENV.fetch('DO_RUN', 1) + s.path = 'scripts/vagrant_bootstrap.sh' + s.args = ["#{timezone}", "#{bootstrap}", "#{compile}", "#{run}"] + end +end diff --git a/scripts/activate b/contrib/buildenv/scripts/activate similarity index 92% rename from scripts/activate rename to contrib/buildenv/scripts/activate index 2fdccca3..d2bf32f4 100644 --- a/scripts/activate +++ b/contrib/buildenv/scripts/activate @@ -4,7 +4,7 @@ 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' +alias twisterd='$TWISTER_CORE_PATH/twisterd' diff --git a/scripts/bin/twister b/contrib/buildenv/scripts/bin/twister old mode 100644 new mode 100755 similarity index 92% rename from scripts/bin/twister rename to contrib/buildenv/scripts/bin/twister index b5c82cb3..097fa771 --- a/scripts/bin/twister +++ b/contrib/buildenv/scripts/bin/twister @@ -4,7 +4,7 @@ RPCUSER='user' RPCPASSWORD='pwd' RPCALLOWIP='127.0.0.1' -BIN=$TWISTER_CORE_PATH/src/twisterd +BIN=$TWISTER_CORE_PATH/twisterd CONFFILE="$TWISTER_HOME/twister.conf" diff --git a/contrib/buildenv/scripts/vagrant_bootstrap.sh b/contrib/buildenv/scripts/vagrant_bootstrap.sh new file mode 100644 index 00000000..a9ef5382 --- /dev/null +++ b/contrib/buildenv/scripts/vagrant_bootstrap.sh @@ -0,0 +1,131 @@ +#!/bin/bash + +TWISTER_CORE_PATH='/home/vagrant/twister-core' +TWISTER_HOME='/home/vagrant/.twister' +AS_VAGRANT='sudo -u vagrant' + +if [ -n "$1" ]; then + timezone=$1 +else + timezone="UTC" +fi + +bootstrap=$2 +compile=$3 +run=$4 + +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 " +bootstrap=$bootstrap +compile=$compile +run=$run +" +echo +echo ".. setting timezone" +service ntp stop +ntpdate ntp1.sp.se +service ntp start +echo "$timezone" | sudo tee /etc/timezone && dpkg-reconfigure --frontend noninteractive tzdata +#$AS_VAGRANT ln -s /vagrant $TWISTER_CORE_PATH + + +echo '.. fixing permissions' +cd $TWISTER_CORE_PATH +find /vagrant/scripts -type d -exec chmod 755 {} \; +find /vagrant/scripts -type f -exec chmod 644 {} \; +chmod 755 /vagrant/scripts/bin/* + +echo '.. checking apt cache' +timestamp_file="$(mktemp)" +touch -d "$(date -R -d '1 day ago')" $timestamp_file +file=/var/cache/apt +if [ $file -ot $timestamp_file ]; then + apt-get update +fi + + +echo '.. configuration & web gui' +if [ ! -d "$TWISTER_HOME" ]; then + $AS_VAGRANT mkdir $TWISTER_HOME + cd $TWISTER_HOME + $AS_VAGRANT touch twister.conf + echo -e "rpcuser=user\nrpcpassword=pwd\nrpcallowip=*" > twister.conf + chmod 600 twister.conf +fi + +if [ ! -d "$TWISTER_HOME/html" ]; then + cd "$TWISTER_HOME" + git clone https://github.com/miguelfreitas/twister-html.git html + checkfail +fi + + + +if [ $bootstrap -eq 1 ]; then +echo '.. bootstrapping' + 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 + + cd $TWISTER_CORE_PATH + $AS_VAGRANT ./bootstrap.sh + checkfail +fi + +if [ $compile -eq 1 ]; then + echo '.. compiling' + $AS_VAGRANT make + checkfail +fi + + + + + + +if [ $run -eq 1 ]; then + echo '.. launching twisterd' + cd $TWISTER_CORE_PATH + $AS_VAGRANT -H ./twisterd -debug -daemon +fi + + + +if [ $? -eq 0 ]; then + echo + echo '==================================================================' + echo " +Done. +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/contrib/buildenv/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/twisted + + + Good luck! + " +else + failed + +fi \ No newline at end of file diff --git a/doc/building-on-vagrant.md b/doc/building-on-vagrant.md index cc88191e..3a9ae36e 100644 --- a/doc/building-on-vagrant.md +++ b/doc/building-on-vagrant.md @@ -1,8 +1,9 @@ -# Vagrant + Debian building instructions +# Vagrant + Ubuntu 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. +This will probably work wherever vagrant can be installed so Windows, Mac, Linux +at least ## Dependencies * http://www.vagrantup.com/ @@ -11,19 +12,19 @@ This will probably work wherever vagrant can be installed. ## Install 1. git clone https://github.com/miguelfreitas/twister-core.git -1. cd twister-core -1. vagrant up +2. cd twister-core/contrib/buildenv +3. 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 +If you have lots of ram and CPU in your machine, feel free to use it. +Before running vagrant up please set +VAGRANT_RAM and/or VAGRANT_CPU environment variables to whatever is fitting. +Default is 1 CPU and 1024 MB RAM. + +Example with 2 CPU and 4096 MB RAM. +```bash +export VAGRANT_CPU=2 +export VAGRANT_RAM=4096 +``` \ No newline at end of file diff --git a/scripts/vagrant_bootstrap.sh b/scripts/vagrant_bootstrap.sh deleted file mode 100644 index 35f94465..00000000 --- a/scripts/vagrant_bootstrap.sh +++ /dev/null @@ -1,88 +0,0 @@ -#!/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