blob: 2a1156dea92ebe539fd4c8e7e43ed4c05e1afe6f [file] [log] [blame]
garciadeblas8d8cd992024-05-21 16:04:14 +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
18function goodbye() {
19 local DURATION=$(date --date=@$(( "$(date +%s)" - "$TRAP_START_TIME" )) --utc +%T)
20 local CODE=$1
21 cd "$TRAP_DIR"
22 if [ "$CODE" == 0 ]; then
23 m "$(realpath --relative-to="$HERE" "$0") succeeded! $DURATION" "$GREEN"
24 elif [ "$CODE" == abort ]; then
25 m "Aborted $(realpath --relative-to="$HERE" "$0")! $DURATION" "$RED"
26 else
27 m "Oh no! $(realpath --relative-to="$HERE" "$0") failed! $DURATION" "$RED"
28 fi
29}
30
31function trap_EXIT() {
32 local ERR=$?
33 goodbye "$ERR"
34 exit "$ERR"
35}
36
37function trap_INT() {
38 goodbye abort
39 trap - EXIT
40 exit 1
41}
42
43TRAP_DIR=$PWD
44TRAP_START_TIME=$(date +%s)
45
46trap trap_INT INT
47
48trap trap_EXIT EXIT