Milan Verespej | 91bc226 | 2019-01-21 15:45:42 +0100 | [diff] [blame] | 1 | # 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 |
| 26 | IS_COMMON_FUNCTIONS_SOURCED=YES |
| 27 | |
| 28 | PATH="${PATH}:/usr/local/bin:/usr/local/sbin" |
| 29 | export PATH |
| 30 | |
| 31 | # just self-defense against locale |
| 32 | LANG=C |
| 33 | export LANG |
| 34 | |
| 35 | # default credentials to the repository |
| 36 | NEXUS_USERNAME=admin |
| 37 | NEXUS_PASSWORD=admin123 |
| 38 | NEXUS_EMAIL=admin@onap.org |
| 39 | |
| 40 | # this function is intended to unify the installer output |
| 41 | message() { |
| 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 | } |
| 63 | export 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 |
| 68 | debug() { |
| 69 | [ "$DEBUG" = DEBUG-ONAP ] && message debug "$@" |
| 70 | } |
| 71 | export debug |
| 72 | |
| 73 | fail() { |
| 74 | message error "$@" |
| 75 | exit 1 |
| 76 | } |
| 77 | |
| 78 | retry() { |
| 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áš Levora | 284fbf8 | 2019-04-23 14:28:47 +0200 | [diff] [blame^] | 93 | clean_list() { |
| 94 | sed -e 's/\s*#.*$//' \ |
| 95 | -e '/^\s*$/d' ${1} | |
| 96 | tr -d '\r' | |
| 97 | awk '{ print $1 }' |
| 98 | } |