summaryrefslogtreecommitdiff
path: root/tools/env_builder.sh
blob: b6171c7d07ef908f7d6437cea2e6fbf2a84164c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash

# This sets up a developer testing environment that can be used with various
# openstack projects (mainly for taskflow, but for others it should work
# fine also).
#
# Some things to note:
#
# - The mysql server that is setup is *not* secured.
# - The zookeeper server that is setup is *not* secured.
# - The downloads from external services are *not* certificate verified.
#
# Overall it should only be used for testing/developer environments (it was
# tested on ubuntu 14.04 and rhel 6.x, for other distributions some tweaking
# may be required).

set -e
set -u

# If on a debian environment this will make apt-get *not* prompt for passwords.
export DEBIAN_FRONTEND=noninteractive

# http://www.unixcl.com/2009/03/print-text-in-style-box-bash-scripting.html
Box () {
    str="$@"
    len=$((${#str}+4))
    for i in $(seq $len); do echo -n '*'; done;
    echo; echo "* "$str" *";
    for i in $(seq $len); do echo -n '*'; done;
    echo
}

set +e
python_27=`which python2.7`
set -e

build_dir=`mktemp -d`
echo "Created build directory $build_dir..."
cd $build_dir

# Get python 2.7 installed (if it's not).
if [ -z "$python_27" ]; then
    py_file="Python-2.7.7.tgz"
    py_base_file=${py_file%.*}
    py_url="https://www.python.org/ftp/python/2.7.7/$py_file"

    Box "Building python 2.7..."
    wget $py_url -O "$build_dir/$py_file" --no-check-certificate -nv
    tar -xf "$py_file"
    cd $build_dir/$py_base_file
    ./configure --disable-ipv6 -q
    make --quiet

    Box "Installing python 2.7..."
    make altinstall >/dev/null 2>&1
    python_27=/usr/local/bin/python2.7
fi

set +e
pip_27=`which pip2.7`
set -e
if [ -z "$pip_27" ]; then
    Box "Installing pip..."
    wget "https://bootstrap.pypa.io/get-pip.py" \
         -O "$build_dir/get-pip.py" --no-check-certificate -nv
    $python_27 "$build_dir/get-pip.py" >/dev/null 2>&1
    pip_27=/usr/local/bin/pip2.7
fi

Box "Installing tox..."
$pip_27 install -q 'tox>=1.6.1,<1.7.0'

Box "Installing system packages..."
if [ -f "/etc/redhat-release" ]; then
    yum install -y -q mysql-devel postgresql-devel mysql-server
    mysqld="mysqld"
elif [ -f "/etc/debian_version" ]; then
    apt-get -y -qq install libmysqlclient-dev mysql-server postgresql
    mysqld="mysql"
else
    echo "Unknown distribution!!"
    lsb_release -a
    exit 1
fi

Box "Setting up mysql..."
service $mysqld restart
/usr/bin/mysql --user="root" --execute='CREATE DATABASE 'openstack_citest''
cat << EOF > $build_dir/mysql.sql
CREATE USER 'openstack_citest'@'localhost' IDENTIFIED BY 'openstack_citest';
CREATE USER 'openstack_citest' IDENTIFIED BY 'openstack_citest';
GRANT ALL PRIVILEGES ON *.* TO 'openstack_citest'@'localhost';
GRANT ALL PRIVILEGES ON *.* TO 'openstack_citest';
FLUSH PRIVILEGES;
EOF
/usr/bin/mysql --user="root" < $build_dir/mysql.sql

Box "Installing zookeeper..."
zk_file="cloudera-cdh-4-0.x86_64.rpm"
zk_url="http://archive.cloudera.com/cdh4/one-click-install/redhat/6/x86_64/$zk_file"
if [ -f "/etc/redhat-release" ]; then
    wget $zk_url -O $build_dir/$zk_file --no-check-certificate -nv
    yum -y -q --nogpgcheck localinstall $build_dir/$zk_file
    yum -y -q install zookeeper-server java
    service zookeeper-server stop
    service zookeeper-server init --force
    mkdir -pv /var/lib/zookeeper
    python -c "import random; print random.randint(1, 16384)" > /var/lib/zookeeper/myid
    zookeeperd="zookeeper-server"
elif [ -f "/etc/debian_version" ]; then
    apt-get install -y -qq zookeeperd
    zookeeperd="zookeeper"
else
    echo "Unknown distribution!!"
    lsb_release -a
    exit 1
fi

Box "Starting zookeeper..."
service $zookeeperd restart
service $zookeeperd status