-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwrapper.sh
executable file
·38 lines (35 loc) · 1.14 KB
/
wrapper.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash
function envManager() {
local verb TMPFILE exitCode tmpValue
# get the first parameter (= verb like load, unload or debug)
verb=$1
# get a temporary file where the stderr will be stored. The file has mode 600 by default.
TMPFILE=$(mktemp -t "XXXXXXXXXXXXXX")
# call the binary and redirect its stderr into TMPFILE. If the binary is not in your PATH, put an absolute path here.
envManager-bin "$@" 2> "$TMPFILE"
# collect the exit code of the envManager-bin call
exitCode=$?
# read and destroy the TMPFILE
tmpValue=$(cat "$TMPFILE"; rm -f "$TMPFILE")
# write the error message to stderr if the binary returned a non-zero exit code
if [[ $exitCode -ne 0 ]]; then
echo "$tmpValue" 1>&2
return $exitCode
fi
case "$verb" in
# the output of these verbs should be eval'ed
load|unload)
eval "$tmpValue"
return $exitCode
;;
# the stderr output of the __complete verbs is to be discarded
__complete*)
return $exitCode
;;
# for all other cases, just show what the binary returned in stderr
*)
echo "$tmpValue" 1>&2
return $exitCode
;;
esac
}