1 # COPYRIGHT NOTICE STARTS HERE
3 # Copyright 2018 © Samsung Electronics Co., Ltd.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # COPYRIGHT NOTICE ENDS HERE
20 # this file contains shared variables and functions for the onap installer
23 # any script which needs this file can check this variable
24 # and it will know immediately if the functions and variables
25 # are loaded and usable
26 IS_COMMON_FUNCTIONS_SOURCED=YES
28 # setting of the path variables
29 if [ -z "$APROJECT_DIR" ] ; then
30 INCLUDE_PATH="${LOCAL_PATH}"/"${RELATIVE_PATH}"
31 APROJECT_DIR=$(readlink -f "$INCLUDE_PATH"/../..)
34 RESOURCES_DIR="$APROJECT_DIR/resources"
35 BASH_SCRIPTS_DIR="$APROJECT_DIR/bash"
36 NEXUS_DATA="$RESOURCES_DIR/nexus_data"
37 CERTS_TARGET_PATH="$APROJECT_DIR/live/certs"
38 NGINX_LOG_DIR="$APROJECT_DIR/live/nginx_logs"
39 GEN_CFG_PATH="$APROJECT_DIR/live/cfg"
40 GIT_REPOS="$RESOURCES_DIR/git-repo"
41 NGINX_HTTP_DIR="$RESOURCES_DIR/http"
42 RHEL_REPO="$RESOURCES_DIR/pkg/rhel"
44 PATH="${PATH}:/usr/local/bin:/usr/local/sbin"
47 # just self-defense against locale
55 registry-1.docker.io \
62 www.springframework.org \
63 registry.hub.docker.com \
66 repo.maven.apache.org"
68 # default credentials to the repository
70 NEXUS_PASSWORD=admin123
71 NEXUS_EMAIL=admin@onap.org
73 # this function is intended to unify the installer output
80 echo 'DEBUG:' "$@" >&2
83 echo 'WARNING [!]:' "$@" >&2
86 echo 'ERROR [!!]:' "$@" >&2
90 echo 'UNKNOWN [?!]:' "$@" >&2
98 # if the environment variable DEBUG is set to DEBUG-ONAP ->
99 # -> this function will print its arguments
100 # otherwise nothing is done
102 [ "$DEBUG" = DEBUG-ONAP ] && message debug "$@"
115 if [ $n -lt $max ]; then
117 message warning "Command ${@} failed. Attempt: $n/$max"
118 message info "waiting 10s for another try..."
121 fail "Command ${@} failed after $n attempts. Better to abort now."
127 # extract and untar to the current directory
128 sed '0,/^# PAYLOAD BELOW #$/d' "$0" | tar -xvpf - ;
132 if grep -q "^[^#]\+\s$SIMUL_HOSTS\s*\$" /etc/hosts ; then
133 message info "simulated domains already in /etc/hosts"
135 echo "$LOCAL_IP $SIMUL_HOSTS" >> /etc/hosts
136 message info "simulated domains added to /etc/hosts (please check it)"
139 if grep -q "^[^#]\+\s$NEXUS_FQDN\s*\$" /etc/hosts ; then
140 message info "nexus FQDN already in /etc/hosts"
142 echo "$LOCAL_IP $NEXUS_FQDN" >> /etc/hosts
143 message info "Nexus FQDN added to /etc/hosts (please check it)"
146 if grep -q "^[^#]\+\srepo.install-server\s*\$" /etc/hosts ; then
147 message info "custom repo FQDN already in /etc/hosts"
149 echo "$LOCAL_IP repo.install-server" >> /etc/hosts
150 message info "Nexus FQDN added to /etc/hosts (please check it)"
159 value=$(eval "echo \$${name}")
160 if [ -z "$value" ]; then
161 while [ -z "$value" ] ; do
165 value=$(eval "echo \$${name}")
167 echo "${name}='${value}'" >> ./local_repo.conf
171 get_configuration() {
172 if [ -f ./local_repo.conf ]; then
176 if [ -z "${NEXUS_FQDN}" ]; then
177 NEXUS_FQDN="nexus.$HOSTNAME"
178 echo "NEXUS_FQDN='${NEXUS_FQDN}'" >> ./local_repo.conf
181 if [ -z "${ONAP_SCALE}" ]; then
183 echo "ONAP_SCALE='${ONAP_SCALE}'" >> ./local_repo.conf
186 # nexus should be configured using those default entries
187 # if it was not put the correct inputs instead
188 if [ -z "${NPM_USERNAME}" ]; then
189 NPM_USERNAME="${NEXUS_USERNAME}"
190 echo "NPM_USERNAME='${NPM_USERNAME}'" >> ./local_repo.conf
193 if [ -z "${NPM_PASSWORD}" ]; then
194 NPM_PASSWORD="${NEXUS_PASSWORD}"
195 echo "NPM_PASSWORD='${NPM_PASSWORD}'" >> ./local_repo.conf
198 if [ -z "${NPM_EMAIL}" ]; then
199 NPM_EMAIL="$NEXUS_EMAIL"
200 echo "NPM_EMAIL='${NPM_EMAIL}'" >> ./local_repo.conf
211 if [ -z "$LOCAL_IP" ] ; then
213 echo "======= Mandatory configuration ======="
215 message info "fill in these mandatory configuration values"
216 get_cfg_val "LOCAL_IP" "Enter the public IPv4 used for this '$HOSTNAME' install machine," \
217 "\nDO NOT USE LOOPBACK! (for example: 10.0.0.1): "
221 enable_local_repo() {
222 sed -r "s%PATH%file://$APROJECT_DIR/resources/pkg/rhel%" "$APROJECT_DIR/resources/pkg/rhel/onap.repo" > /etc/yum.repos.d/onap.repo
228 message info "Installing packages"
232 yum -y install "$APROJECT_DIR/resources/pkg/centos/*.rpm"
236 yum -y install docker-ce dnsmasq icewm firefox tigervnc-server
237 systemctl enable docker
238 systemctl start docker
241 dpkg -i "$APROJECT_DIR/resources/pkg/ubuntu/*.deb"
244 message error "OS release is not supported: $os_id"
245 message info "ABORTING INSTALLATION"
252 message info "installation of external binaries"
253 for binary in kubectl helm rancher jq ; do
254 cp "$APROJECT_DIR/resources/downloads/${binary}" /usr/local/bin/
255 chmod 755 "/usr/local/bin/${binary}"
261 mkdir -p ~/.vnc ~/.icewm
262 echo "onap" | vncpasswd -f > ~/.vnc/passwd
263 chmod 0600 ~/.vnc/passwd
265 cat > ~/.vnc/xstartup <<EOF
268 unset SESSION_MANAGER
269 unset DBUS_SESSION_BUS_ADDRESS
274 chmod +x ~/.vnc/xstartup
276 cat > ~/.icewm/menu <<EOF
277 prog Firefox firefox firefox
284 update_docker_cfg() {
285 if [ -f "/etc/docker/daemon.json" ]; then
286 jq '.dns += ["172.17.0.1"]' /etc/docker/daemon.json > /tmp/daemon.json
287 mv /tmp/daemon.json /etc/docker/daemon.json
289 echo '{"dns": ["172.17.0.1"]}' > /etc/docker/daemon.json
294 echo "** Generate certificates **"
295 openssl genrsa -out $CERTS_TARGET_PATH/rootCA.key 4096
297 echo "** Generate self signed ***"
298 openssl req -config $GEN_CFG_PATH/cacert.cnf -key $CERTS_TARGET_PATH/rootCA.key -new -x509 -days 7300 -sha256 -extensions v3_ca \
299 -out $CERTS_TARGET_PATH/rootCAcert.pem
303 openssl x509 -in $CERTS_TARGET_PATH/rootCAcert.pem -inform PEM -out $CERTS_TARGET_PATH/rootCAcert.crt
308 echo "** Publishing root CA **"
309 if [ "$os" == "redhat" ]; then
311 update-ca-trust force-enable
312 cp $CERTS_TARGET_PATH/rootCAcert.crt /etc/pki/ca-trust/source/anchors/
313 update-ca-trust extract
314 elif [ "$os" == "ubuntu" ]; then
315 mkdir -p /usr/local/share/ca-certificates/extra
316 cp $CERTS_TARGET_PATH/rootCAcert.crt /usr/local/share/ca-certificates/extra
317 update-ca-certificates
319 echo "OS \"$os\" is not supported"
323 echo "** Restart docker (because of reload new CA) **"
324 systemctl restart docker
331 openssl genrsa -out $CERTS_TARGET_PATH/${server_name}_server.key 4096
332 echo "** Generate sig request ***"
333 openssl req -new -config $GEN_CFG_PATH/${server_name}_cert.cnf -key $CERTS_TARGET_PATH/${server_name}_server.key -out $CERTS_TARGET_PATH/${server_name}_server.csr
335 # v3.ext must be in separate file , because of bug in openssl 1.0
337 openssl x509 -req -in $CERTS_TARGET_PATH/${server_name}_server.csr\
338 -extfile $GEN_CFG_PATH/v3.ext\
339 -CA $CERTS_TARGET_PATH/rootCAcert.crt\
340 -CAkey $CERTS_TARGET_PATH/rootCA.key\
341 -CAcreateserial -out $CERTS_TARGET_PATH/${server_name}_server.crt -days 3650 -sha256
350 #firewall-cmd --permanent --add-port=53/udp
351 #firewall-cmd --permanent --add-port=53/tcp
352 #firewall-cmd --permanent --add-port=10001/tcp
353 #firewall-cmd --permanent --add-port=80/tcp
354 #firewall-cmd --permanent --add-port=443/tcp
358 distribute_root_CA() {
360 scp $APROJECT_DIR/install_cacert.sh $targetip:.
361 ssh $targetip ./install_cacert.sh
362 echo "** Add DNS record to remote host **"
363 ssh $targetip "echo nameserver $LOCAL_IP > /etc/resolv.conf"
366 upload_ansible_pkgs() {
369 #if [[ $os == "ubuntu" ]]; then
370 # those deb & whl packages are needed for sdnc-ansible-server pod
371 # independently on host OS distros
372 echo "** Copy required packages for sdnc-ansible-pod to kubernetes node $targetip **"
373 scp -r $APROJECT_DIR/resources/pkg/ubuntu/ansible_pkg $targetip:.
377 remote_setup_nfs_server() {
381 scp $APROJECT_DIR/bash/tools/setup_nfs_server_${os}.sh $targetip:setup_nfs_server.sh
382 if [[ $os == "ubuntu" ]]; then
383 scp -r $APROJECT_DIR/resources/pkg/ubuntu/nfs-common-pkg/* $targetip:.
384 ssh $targetip dpkg -i *.deb
387 ssh $targetip /bin/bash ./setup_nfs_server.sh "$@"
390 remote_setup_nfs_mount() {
394 scp $APROJECT_DIR/bash/tools/setup_nfs_mount.sh $targetip:.
395 if [[ $os == "ubuntu" ]]; then
396 scp -r $APROJECT_DIR/resources/pkg/ubuntu/nfs-common-pkg/* $targetip:.
397 ssh $targetip dpkg -i *.deb
399 ssh $targetip /bin/bash ./setup_nfs_mount.sh $nfsip
402 enable_remote_repo() {
404 sed -r "s%PATH%http://repo.install-server%" $APROJECT_DIR/resources/pkg/rhel/onap.repo | ssh $targetip 'cat > /etc/yum.repos.d/onap.repo'
407 install_remote_docker() {
410 if [[ $os == "ubuntu" ]]; then
411 scp -r $APROJECT_DIR/resources/pkg/ubuntu/{docker-ce_17.03.2~ce-0~ubuntu-xenial_amd64.deb,libltdl7_2.4.6-0.1_amd64.deb} $targetip:.
412 ssh $targetip dpkg -i *.deb
413 elif [[ $os == "rhel" ]]; then
414 ssh $targetip yum -y install docker-ce
416 ssh $targetip "mkdir -p /etc/docker"
417 scp "$APROJECT_DIR/resources/downloads/jq" $targetip:/usr/local/bin/
418 ssh $targetip "if [[ -f /etc/docker/daemon.json ]]; then
419 jq '.dns += [\"$LOCAL_IP\"]' /etc/docker/daemon.json > /tmp/daemon.json
420 mv /tmp/daemon.json /etc/docker/daemon.json
422 echo {'\"'dns'\"': ['\"'$LOCAL_IP'\"']} > /etc/docker/daemon.json
425 ssh $targetip 'systemctl enable docker; systemctl restart docker'
429 docker run -d --entrypoint "/bin/bash" --restart=unless-stopped -p 8080:8080 \
430 -v $CERTS_TARGET_PATH:/usr/local/share/ca-certificates/extra:ro \
431 --name rancher_server rancher/server:v1.6.14 \
432 -c "/usr/sbin/update-ca-certificates;/usr/bin/entry /usr/bin/s6-svscan /service"
433 echo "** wait until rancher is ready **"
436 deploy_kubernetes() {
439 for i in `seq 5 -1 1`; do
440 API_RESPONSE=`curl -s 'http://127.0.0.1:8080/v2-beta/apikey' \
441 -d '{"type":"apikey","accountId":"1a1","name":"autoinstall"\
442 ,"description":"autoinstall","created":null,"kind":null,\
443 "removeTime":null,"removed":null,"uuid":null}'`
444 if [[ "$?" -eq 0 ]]; then
445 KEY_PUBLIC=`echo $API_RESPONSE | jq -r .publicValue`
446 KEY_SECRET=`echo $API_RESPONSE | jq -r .secretValue`
449 echo "Waiting for rancher server to start"
453 export RANCHER_URL=http://${LOCAL_IP}:8080
454 export RANCHER_ACCESS_KEY=$KEY_PUBLIC
455 export RANCHER_SECRET_KEY=$KEY_SECRET
458 echo "wait 60 sec for rancher environments can settle before we create the onap kubernetes one"
461 rancher env create -t kubernetes onap > kube_env_id.json
462 PROJECT_ID=$(<kube_env_id.json)
463 echo "env id: $PROJECT_ID"
464 export RANCHER_HOST_URL=http://${LOCAL_IP}:8080/v1/projects/$PROJECT_ID
467 status=$(rancher env ls | grep $PROJECT_ID | awk '{print $4}')
468 if [[ "$status" == "active" ]]; then
469 echo "Check on environments again before registering the URL response"
473 echo "Wait for environment to become active"
477 REG_URL_RESPONSE=`curl -X POST -u $KEY_PUBLIC:$KEY_SECRET -H 'Accept: application/json' -H 'ContentType: application/json' -d '{"name":"$LOCAL_IP"}' "http://$LOCAL_IP:8080/v1/projects/$PROJECT_ID/registrationtokens"`
478 echo "wait for server to finish url configuration - 3 min"
480 # see registrationUrl in
481 REGISTRATION_TOKENS=`curl http://127.0.0.1:8080/v2-beta/registrationtokens`
482 REGISTRATION_DOCKER=`echo $REGISTRATION_TOKENS | jq -r .data[0].image`
483 REGISTRATION_TOKEN=`echo $REGISTRATION_TOKENS | jq -r .data[0].token`
485 # base64 encode the kubectl token from the auth pair
486 # generate this after the host is registered
487 KUBECTL_TOKEN=$(echo -n 'Basic '$(echo -n "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY" | base64 -w 0) | base64 -w 0)
488 echo "KUBECTL_TOKEN base64 encoded: ${KUBECTL_TOKEN}"
489 cat > ~/.kube/config <<EOF
495 insecure-skip-tls-verify: true
496 server: "https://$LOCAL_IP:8080/r/projects/$PROJECT_ID/kubernetes:6443"
503 current-context: "onap"
507 token: "$KUBECTL_TOKEN"
511 if [[ $os == "rhel" ]]; then
512 echo "Upgrade datavolume for RHEL"
513 KUBELET_ID=`curl http://${LOCAL_IP}:8080/v2-beta/projects/${PROJECT_ID}/services/ | jq -r '.data[] | select(.name=="kubelet")'.id`
514 OLD_LAUNCH_CONFIG=`curl http://${LOCAL_IP}:8080/v2-beta/projects/${PROJECT_ID}/services/${KUBELET_ID} | jq '.launchConfig'`
515 NEW_LAUNCH_CONFIG=`echo $OLD_LAUNCH_CONFIG | jq '.dataVolumes[2]="/sys/fs/cgroup:/sys/fs/cgroup:ro,rprivate"'`
518 \"inServiceStrategy\": {
520 \"intervalMillis\": 2000,
521 \"startFirst\": false,
522 \"launchConfig\": ${NEW_LAUNCH_CONFIG},
523 \"secondaryLaunchConfigs\": []
526 curl -s -u $KEY_PUBLIC:$KEY_SECRET -X POST -H 'Content-Type: application/json' -d "${DATA}" "http://${LOCAL_IP}:8080/v2-beta/projects/${PROJECT_ID}/services/${KUBELET_ID}?action=upgrade" > /dev/null
528 echo "Give environment time to update (30 sec)"
531 curl -s -u $KEY_PUBLIC:$KEY_SECRET -X POST "http://${LOCAL_IP}:8080/v2-beta/projects/${PROJECT_ID}/services/${KUBELET_ID}?action=finishupgrade" > /dev/null
535 deploy_rancher_agent() {
537 if [ -z "$REGISTRATION_DOCKER" ]; then
538 echo "ASSERT: Missing REGISTRATION_DOCKER"
541 if [ -z "$RANCHER_URL" ]; then
542 echo "ASSERT: Missing RANCHER_URL"
545 if [ -z "$REGISTRATION_TOKEN" ]; then
546 echo "ASSERT: Missing REGISTRATION_TOKEN"
550 ssh $nodeip "docker run --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/racher:/var/lib/rancher $REGISTRATION_DOCKER $RANCHER_URL/v1/scripts/$REGISTRATION_TOKEN"
551 echo "waiting 2 min for creating kubernetes environment"
558 echo "Deploying node $nodeip"
559 distribute_root_CA $nodeip
560 install_remote_docker $nodeip $os
561 deploy_rancher_agent $nodeip
565 pushd $APROJECT_DIR/resources/oom/kubernetes
566 helm init --upgrade --skip-refresh
569 helm repo remove stable
572 echo "wait a moment before helm will come up ..."
574 helm repo add local http://127.0.0.1:8879
576 #Pass the CA certificate contents directly during installation.
577 helm install local/onap -n dev --namespace onap \
578 --set "global.cacert=$(cat ${CERTS_TARGET_PATH}/rootCAcert.crt)"
584 # print warning if patched file does not exist as some charts
585 # might not be available for some deployments
586 if [ ! -f "$file" ]; then
587 echo "WARNING: Can't patch file $file because this file does not exists."
593 for ivar in "$@" ; do
594 ivalue=$(eval 'echo "$'${ivar}'"')
595 sed -i "s#${ivar}#${ivalue}#g" "$file"
600 if [ -z "$LOCAL_IP" ] ; then
601 echo "ERROR: LOCAL_IP unset"
604 if [ -z "$NEXUS_FQDN" ] ; then
605 echo "ERROR: NEXUS_FQDN unset"
609 UPDATE_HOSTS_FILE="$LOCAL_IP $NEXUS_FQDN"
610 UPDATE_NPM_REGISTRY="npm set registry \"http://${NEXUS_FQDN}/repository/npm-private/\""
612 expand_file $APROJECT_DIR/resources/oom/kubernetes/common/dgbuilder/templates/deployment.yaml \
615 expand_file $APROJECT_DIR/resources/oom/kubernetes/sdnc/charts/sdnc-portal/templates/deployment.yaml \
621 if [ -z "$LOCAL_IP" ] ; then
622 echo "ERROR: LOCAL_IP unset"
626 UPDATE_HOSTS_FILE="$LOCAL_IP www.springframework.org"
627 expand_file $APROJECT_DIR/resources/oom/kubernetes/dmaap/charts/message-router/templates/deployment.yaml \
631 patch_cfy_manager_depl() {
633 file="${APROJECT_DIR}/resources/oom/kubernetes/dcaegen2/charts/dcae-cloudify-manager/templates/deployment.yaml"
637 CERT_PATH="/etc/pki/ca-trust/source/anchors"
640 CERT_PATH="/usr/local/share/ca-certificates/extra"
643 echo "ERROR: missing argument"
647 echo "ERROR: unknown OS: ${os}"
652 expand_file "$file" CERT_PATH
655 copy_onap_values_file() {
656 cp "${APROJECT_DIR}/${CUSTOM_CFG_RELPATH:-cfg}/${ONAP_SCALE}_depl_values.yaml" \
657 "${APROJECT_DIR}/resources/oom/kubernetes/onap/values.yaml"