6ecfe8363c0e4fd152083d79670a02435454df59
[ci-management.git] / scripts / init-respin-env.sh
1 #!/bin/bash
2
3 # Copyright 2016 The Linux Foundation
4
5 set -e
6
7 vagrant_version=1.8.1
8 ruby_version=2.1.5
9 ruby_patch=https://gist.github.com/mislav/055441129184a1512bb5.txt
10 rbenv_git=https://github.com/rbenv/rbenv.git
11
12 PVENAME="${CPPROJECT}-openstack"
13 PVE_PATH="${PVE_ROOT}/${PVENAME}"
14 PVERC=${PVE_PATH}/bin/activate
15 PVE_BINDIR=$(dirname $PVERC)
16 PVE_ROOT="${HOME}/src/python-virtual"
17
18 LOCAL_LIB="${HOME}/src/local-lib"
19 LL_LIBDIR="${LOCAL_LIB}/lib"
20
21 RH_ARCH64=x86_64
22 RH_ARCH32=i686
23 DEB_ARCH64=amd64
24 DEB_ARCH32=i386
25 LV_IMG_DIR=/var/lib/libvirt/images/
26 SRC_TIMESTAMP=""
27 DST_TIMESTAMP=""
28
29 init_virtualenv
30 init_rbenv
31 init_ruby
32 select_ruby ${ruby_version}
33 init_virtualenv
34 init_vagrant
35 install_vagrant_plugins
36 import_vagrant_box
37 init_local_lib
38 init_javascript
39
40 function init_virtualenv ()
41 {
42     test -d ${PVE_BINDIR} && return 0
43
44     if [ -f /etc/debian_version ]
45     then
46         sudo apt-get -y -qq install virtualenvwrapper python-virtualenv libpython-dev
47     elif [ -f /etc/redhat-release ]
48     then
49         sudo yum -y install python-virtualenv
50     fi
51
52     mkdir -p ${PVE_PATH}
53     virtualenv ${PVE_PATH}
54
55     echo "Please copy all OS_* variables from https://secure.vexxhost.com/console/#/account/credentials to the end of ${PVERC}"
56     echo "Press enter when finished"
57     read
58 }
59
60 function init_local_lib ()
61 {
62     test -d ${LL_LIBDIR} && return 0
63
64     echo "local lib init incomplete"
65 }
66
67 function init_javascript ()
68 {
69     which js && which jq && return 0
70
71     if [ -f /etc/debian_version ]
72     then
73         sudo apt-get -y -qq install nodejs jq
74     elif [ -f /etc/redhat-release ]
75     then
76         sudo yum -y install nodejs jq
77     fi
78 }
79
80 function init_vagrant ()
81 {
82     which vagrant && return 0
83
84     vagrant_pkg_name=vagrant_${vagrant_version}_x86_64.deb
85     vagrant_pkg=https://releases.hashicorp.com/vagrant/${vagrant_version}/${vagrant_pkg_name}
86
87     wget -c ${vagrant_pkg}
88     sudo dpkg -i ${vagrant_pkg_name}
89 }
90
91 function init_rbenv ()
92 {
93     which rbenv && return 0
94
95     # clone rbenv
96     test -d ~/.rbenv/.git || git clone ${rbenv_git} ~/.rbenv
97
98     # clone ruby-build
99     mkdir -p ~/.rbenv/plugins
100     test -d ~/.rbenv/plugins/ruby-build/.git || git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
101
102     # build ruby-build
103     cd ~/.rbenv && src/configure && make -C src
104
105     # Add rbenv to bashrc
106     grep HOME/.rbenv/bin ~/.bash_profile || echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
107
108     # Add rbenv to current environment
109     export PATH="$HOME/.rbenv/bin:$PATH"
110 }
111
112 function init_ruby ()
113 {
114     # Install ruby build deps
115     sudo apt-get build-dep ruby
116     #sudo apt-get -y install \
117     #     autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev \
118     #     zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
119
120     # Build ruby
121     curl -fsSL ${ruby_patch} | rbenv install --patch ${ruby_version}
122 }
123
124 function select_ruby ()
125 {
126     # Select ruby ${ruby_version} from rbenv
127     rbenv local ${1}
128     rbenv global ${1}
129 }
130
131 function install_vagrant_plugins ()
132 {
133     for plugin in vagrant-openstack-provider vagrant-cachier vagrant-mutate
134     do
135         vagrant plugin install ${plugin}
136     done
137 }
138
139 function import_vagrant_box ()
140 {
141     # Add dummy box
142     vagrant box add dummy https://github.com/huit/vagrant-openstack/blob/master/dummy.box
143
144     cp ${CI_MGMT}/vagrant/examples/box/dummy/Vagrantfile ~/.vagrant.d/boxes/dummy/0/openstack/
145 }
146