-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunctions.inc.sh
91 lines (75 loc) · 1.67 KB
/
functions.inc.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
abortbuildmsg="Aborting documentation build process."
if [ "${OSTYPE}" == "msys" ]; then
MSYS_TMPDIR="$(mount | egrep "^[^ ]+ on /tmp type" | cut -f1 -d" ")"
if [ -z "${MSYS_TMPDIR}" ]; then
fail "unable to query MSYS mounted /tmp/ directory. Current mtab:
$(mount)
----
${abortbuildmsg}"
fi
function cf_path() {
local linuxpath="${@}"
local drivepath
if [ "${linuxpath::1}" != "/" ]; then
#relative path
echo "${linuxpath}"
return 0
else
drivepath="${linuxpath::3}"
if [ -z "${drivepath/\/[a-zA-Z]\/}" ]; then
echo "${drivepath:1:1}:${linuxpath#/?}"
return 0
elif [ "${linuxpath::5}" == "/tmp/" ]; then
echo "${MSYS_TMPDIR}/${linuxpath#/*/}"
else
# could be a network drive, something we don't support or suppose will ever
# be used as absolute path under windows.
return 1
fi
fi
}
else
function cf_path() {
echo "${@}"
return 0
}
fi
function fail() {
local msg="${@}"
>&2 echo "::error::${msg}"
exit 1
}
function fail_nl() {
local msg="${@}"
echo "error."
fail "${msg}"
}
function fail_cmd() {
local nl="${1}" msg="${2}" cmd="${3}" output="${4}"
local multiline_msg
multiline_msg="${msg}.
Failed command and output:
\$ ${cmd}
${output}
----
${abortbuildmsg}"
if [ "${nl}" == comma ]; then
echo -n ", "
fail_nl "${multiline_msg}"
elif [ "${nl}" == true ]; then
fail_nl "${multiline_msg}"
else
fail "${multiline_msg}"
fi
}
if [ "${OSTYPE::6}" == "darwin" ]; then
function inplace_sed() {
sed -Ei '' "${@}"
return ${?}
}
else
function inplace_sed() {
sed -Ei "${@}"
return ${?}
}
fi