blob: 04ea20173711eab494a1486448da74d654ace01a [file] [log] [blame]
Milan Verespej91bc2262019-01-21 15:45:42 +01001# COPYRIGHT NOTICE STARTS HERE
2#
3# Copyright 2018 © Samsung Electronics Co., Ltd.
4#
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
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
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.
16#
17# COPYRIGHT NOTICE ENDS HERE
18
19#
20# this file contains shared variables and functions for the onap installer
21#
22
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
26IS_COMMON_FUNCTIONS_SOURCED=YES
27
28PATH="${PATH}:/usr/local/bin:/usr/local/sbin"
29export PATH
30
31# just self-defense against locale
32LANG=C
33export LANG
34
35# default credentials to the repository
36NEXUS_USERNAME=admin
37NEXUS_PASSWORD=admin123
38NEXUS_EMAIL=admin@onap.org
39
40# this function is intended to unify the installer output
41message() {
42 case "$1" in
43 info)
44 echo 'INFO:' "$@"
45 ;;
46 debug)
47 echo 'DEBUG:' "$@" >&2
48 ;;
49 warning)
50 echo 'WARNING [!]:' "$@" >&2
51 ;;
52 error)
53 echo 'ERROR [!!]:' "$@" >&2
54 return 1
55 ;;
56 *)
57 echo 'UNKNOWN [?!]:' "$@" >&2
58 return 2
59 ;;
60 esac
61 return 0
62}
63export message
64
65# if the environment variable DEBUG is set to DEBUG-ONAP ->
66# -> this function will print its arguments
67# otherwise nothing is done
68debug() {
69 [ "$DEBUG" = DEBUG-ONAP ] && message debug "$@"
70}
71export debug
72
73fail() {
74 message error "$@"
75 exit 1
76}
77
78retry() {
79 local n=1
80 local max=5
81 while ! "$@"; do
82 if [ $n -lt $max ]; then
83 n=$((n + 1))
84 message warning "Command ${@} failed. Attempt: $n/$max"
85 message info "waiting 10s for another try..."
86 sleep 10s
87 else
88 fail "Command ${@} failed after $n attempts. Better to abort now."
89 fi
90 done
91}
92
Tomáš Levora284fbf82019-04-23 14:28:47 +020093clean_list() {
94 sed -e 's/\s*#.*$//' \
95 -e '/^\s*$/d' ${1} |
96 tr -d '\r' |
97 awk '{ print $1 }'
98}