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