Commit | Line | Data |
---|---|---|
01654d69 JR |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) - 2019 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com> | |
4 | # | |
5 | # This library is free software; you can redistribute it and/or modify it under | |
6 | # the terms of the GNU Lesser General Public License as published by the Free | |
7 | # Software Foundation; version 2.1 of the License. | |
8 | # | |
9 | # This library is distributed in the hope that it will be useful, but WITHOUT | |
10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
11 | # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | |
12 | # details. | |
13 | # | |
14 | # You should have received a copy of the GNU Lesser General Public License | |
15 | # along with this library; if not, write to the Free Software Foundation, Inc., | |
16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 | ||
18 | function get_env_value () | |
19 | { | |
20 | local env_file=$1 | |
21 | local key=$2 | |
22 | local result | |
23 | local ret | |
24 | ||
25 | result=$(grep "$key" < "$env_file") | |
26 | ret=$? | |
27 | if [ $ret -eq 1 ]; then | |
28 | echo "invalid_value_extraction" | |
29 | return 1 | |
30 | else | |
31 | # Strip the key using bash substring removal. | |
32 | # This remove all leading chars until the actual value. | |
33 | result=${result#* = } | |
34 | ||
35 | # Remove the trailing ';' | |
36 | result=${result:0:-1} | |
37 | ||
38 | # Remove enclosing '"' if present | |
39 | if [ "${result:0:1}" == '"' ]; then | |
40 | result=${result:1:-1} | |
41 | fi | |
42 | ||
43 | echo "$result" | |
44 | return 0 | |
45 | fi | |
46 | } | |
47 | ||
48 | function iso8601_to_lttng_dir_datetime () | |
49 | { | |
50 | local result=$1 | |
51 | ||
52 | result=${result/T/-} | |
53 | ||
54 | # Remove trailing timezone information including the '-'. | |
55 | result=${result:0:-5} | |
56 | ||
57 | echo "$result" | |
58 | return 0 | |
59 | } |