blob: b61ec6509cd39a01527ff876ce03b5ab2e9e4958 [file] [log] [blame]
garciadeblasde0c2882024-09-10 18:10:53 +02001#######################################################################################
2# Copyright ETSI Contributors and Others.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13# implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#######################################################################################
17
18
19# Helper function to monitor progress of a condition
20function monitor_condition() {
21 local CONDITION="$1" # Function with the condition
22 local MESSAGE="${2:-}" # Message during each check
23 local TIMEOUT="${3:-300}" # Timeout, in seconds (default: 5 minutes)
24 local STEP="${4:-2}" # Polling period (default: 2 seconds)
25
26 "${CONDITION}"
27 RET=$?
28 until [ ${RET} -eq 0 ] || [ ${TIMEOUT} -le 0 ]
29 do
30 echo -en "${MESSAGE}"
31
32 ((TIMEOUT-=${STEP}))
33 sleep "${STEP}"
34
35 "${CONDITION}"
36 RET=$?
37 done
38
39 return ${RET}
40}