aboutsummaryrefslogtreecommitdiffstats
path: root/lib/_installers
blob: 45fbd8423853439d9a127eb5de2cfb2fc144cfc4 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#!/bin/bash

source /var/onap/_commons
source /var/onap/_onap_functions

# _install_bind() - Install bind utils
function _install_bind {
    install_packages bind9 bind9utils
}

# install_java() - Install java binaries
function install_java {
    if is_package_installed openjdk-8-jdk; then
        return
    fi
    source /etc/os-release || source /usr/lib/os-release
    case ${ID,,} in
        *suse)
        ;;
        ubuntu|debian)
            install_package software-properties-common
            add-apt-repository -y ppa:openjdk-r/ppa
        ;;
        rhel|centos|fedora)
        ;;
    esac
    update_repos

    # Remove Java 7
    uninstall_packages default-jre openjdk-7-jdk openjdk-7-jre openjdk-7-jre-headless

    install_package openjdk-8-jdk
    # ca-certificates-java is not a dependency in the Oracle JDK/JRE so this must be explicitly installed.
    /var/lib/dpkg/info/ca-certificates-java.postinst configure
}

# install_maven() - Install maven binaries
function install_maven {
    if is_package_installed maven3; then
        return
    fi
    install_java
    source /etc/os-release || source /usr/lib/os-release
    case ${ID,,} in
        *suse)
        ;;
        ubuntu|debian)
            install_package software-properties-common
            add-apt-repository -y ppa:andrei-pozolotin/maven3
        ;;
        rhel|centos|fedora)
        ;;
    esac
    update_repos
    install_package maven3

    # Remove Java 7
    uninstall_package openjdk-7-jdk

    _configure_maven
}

# install_nodejs() - Download and install NodeJS
function install_nodejs {
    if is_package_installed nodejs; then
        return
    fi
    curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
    install_package nodejs

    # Update NPM to latest version
    npm install npm -g
}

# install_python() - Install Python 2.7 and other tools necessary for development.
function install_python {
    install_packages python2.7 python-dev
}

# _install_pip() - Install Python Package Manager
function _install_pip {
    install_python
    if ! which pip; then
        curl -sL https://bootstrap.pypa.io/get-pip.py | python
    fi
}

# install_python_package() - Install python modules
function install_python_package {
    local python_packages=$@

    _install_pip
    pip install $python_packages
}

# install_python_requirements() - Install a list of python modules defined in requirement.txt file
function install_python_requirements {
    local python_project_path=$1

    _install_pip
    pushd $python_project_path
    pip install -r requirements.txt
    popd
}

# _configure_docker_settings() - Configures Docker settings
function _configure_docker_settings {
    local docker_conf_backup=/tmp/docker.backup
    local docker_conf=/etc/default/docker
    local chameleonsocks_filename=chameleonsocks.sh
    local max_concurrent_downloads=${1:-3}

    cp ${docker_conf} ${docker_conf_backup}
    if [ $http_proxy ]; then
        echo "export http_proxy=$http_proxy" >> $docker_conf
    fi
    if [ $https_proxy ]; then
        echo "export https_proxy=$https_proxy" >> $docker_conf
        #If you have a socks proxy, then use that to connect to the nexus repo
        #via a redsocks container
        if [ $socks_proxy ]; then
            wget https://raw.githubusercontent.com/crops/chameleonsocks/master/$chameleonsocks_filename
            chmod 755 $chameleonsocks_filename
            socks=$(echo $socks_proxy | sed -e "s/^.*\///" | sed -e "s/:.*$//")
            port=$(echo $socks_proxy | sed -e "s/^.*://")
            PROXY=$socks PORT=$port ./$chameleonsocks_filename --install
            rm $chameleonsocks_filename
            cp ${docker_conf_backup} ${docker_conf}
        fi
    fi
    rm ${docker_conf_backup}

    echo "DOCKER_OPTS=\"-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --max-concurrent-downloads $max_concurrent_downloads \"" >> $docker_conf
    usermod -aG docker $USER

    source /etc/os-release || source /usr/lib/os-release
    case ${ID,,} in
        *suse)
        ;;
        ubuntu|debian)
            service docker restart
            sleep 10
        ;;
        rhel|centos|fedora)
        ;;
    esac
}

# install_docker() - Download and install docker-engine
function install_docker {
    if $(docker version &>/dev/null); then
        return
    fi
    source /etc/os-release || source /usr/lib/os-release
    case ${ID,,} in
        *suse)
        ;;
        ubuntu|debian)
            install_packages software-properties-common linux-image-extra-$(uname -r) linux-image-extra-virtual apt-transport-https ca-certificates curl
            curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
            add-apt-repository \
            "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
            $(lsb_release -cs) stable"
        ;;
        rhel|centos|fedora)
        ;;
    esac
    update_repos

    install_package docker-ce
    _configure_docker_settings
}

# install_docker_compose() - Download and install docker-engine 
function install_docker_compose {
    local docker_compose_version=${1:-1.21.0}
    if [ ! -d /opt/docker ]; then
        mkdir /opt/docker
        curl -L https://github.com/docker/compose/releases/download/$docker_compose_version/docker-compose-`uname -s`-`uname -m` > /opt/docker/docker-compose
        chmod +x /opt/docker/docker-compose
    fi
}

# install_chefdk() - Install ChefDK package
function install_chefdk {
    local chefdk_version="2.4.17"

    if is_package_installed chefdk; then
        return
    fi
    pushd $(mktemp -d)
    source /etc/os-release || source /usr/lib/os-release
    case ${ID,,} in
        *suse)
        ;;
        ubuntu|debian)
        chefdk_pkg="chefdk_$chefdk_version-1_amd64.deb"
        chefdk_url="https://packages.chef.io/files/stable/chefdk/$chefdk_version/ubuntu/$VERSION_ID/$chefdk_pkg"

        wget $chefdk_url
        dpkg -i $chefdk_pkg
        apt-get install -f -y
        ;;
        rhel|centos|fedora)
        rpm -Uvh "https://packages.chef.io/files/stable/chefdk/$chefdk_version/el/7/chefdk-$chefdk_version-1.el7.x86_64.rpm"
        ;;
    esac
    popd
}

# _install_ODL() - Download and Install OpenDayLight SDN controller
function _install_ODL {
    if [ ! -d /opt/opendaylight/current ]; then
        mkdir -p /opt/opendaylight/
        wget "https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/integration/distribution-karaf/"$odl_version"/distribution-karaf-"$odl_version".tar.gz" -P /opt/
        tar xvf "/opt/distribution-karaf-"$odl_version".tar.gz" -C /tmp/
        mv "/tmp/distribution-karaf-"$odl_version /opt/opendaylight/current
        rm -rf "/opt/distribution-karaf-"$odl_version".tar.gz"
    fi
}

# install_go() - Install GoLang package
function install_go {
    if is_package_installed golang-go; then
        return
    fi
    source /etc/os-release || source /usr/lib/os-release
    case ${ID,,} in
        *suse)
        ;;
        ubuntu|debian)
            install_package software-properties-common
            add-apt-repository -y ppa:gophers/archive
        ;;
        rhel|centos|fedora)
        ;;
    esac
    update_repos

    install_package golang-go
}

# install_dep() - Install dep GoLand tool
function install_dep {
    install_go
    curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
}

# install_hadoop() - Function that installs Hadoop
function install_hadoop {
    local release=titan
    local version=1.0.0
    local filename=$release-$version-hadoop1
    local dest_folder=/opt/hadoop/current

    if [ ! -d $dest_folder ]; then
        curl http://s3.thinkaurelius.com/downloads/$release/$filename.zip -o /tmp/${filename}.zip
        install_package unzip
        mkdir -p $dest_folder
        unzip /tmp/${filename}.zip -d $dest_folder
    fi

    pushd $dest_folder/${filename}
    # Change commitlog_directory and data_file_directories values (https://stackoverflow.com/a/26856246/1707651)
    sed -i "s|db/cassandra/data|/tmp/data|g" conf/cassandra/cassandra.yaml
    sed -i "s|db/cassandra/commitlog|/tmp/commitlog|g" conf/cassandra/cassandra.yaml

    install_java
    ./bin/titan.sh start
    popd
}

# install_haproxy() - Function that install HAProxy
function install_haproxy {
    if is_package_installed haproxy; then
        return
    fi
    source /etc/os-release || source /usr/lib/os-release
    case ${ID,,} in
        *suse)
        ;;
        ubuntu|debian)
            install_package software-properties-common
            add-apt-repository -y ppa:vbernat/haproxy-1.7
            update_repos
            install_package haproxy
            cp /var/onap/files/haproxy.cfg /etc/haproxy/
            cp /var/onap/files/aai.pem /etc/ssl/private/
            chmod 640 /etc/ssl/private/aai.pem
            chown root:ssl-cert /etc/ssl/private/aai.pem
            mkdir -p /usr/local/etc/haproxy
            #echo "127.0.0.1 localhost aai-traversal.api.simpledemo.openecomp.org aai-resources.api.simpledemo.openecomp.org" >> /etc/hosts

            service haproxy restart
        ;;
        rhel|centos|fedora)
        ;;
    esac
}