This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
base_functions.sh
85 lines (78 loc) · 2.06 KB
/
base_functions.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
#!/bin/bash
#
# Base functions for install scripts
check_error() {
local msg="$*"
local umsg==`echo $msg | tr '[a-z]' '[A-Z]'` # Upper-case everything to ensure 'error' is detected as well as 'ERROR'
if [ "${umsg//ERROR/}" != "${umsg}" ]; then
if [ -n "${ERROR_FILE:-}" ] && [ -f "$ERROR_FILE" ] && ! grep "$msg" $ERROR_FILE ; then
local tmp=$(mktemp /tmp/error-XXXX)
echo ${msg} >> $tmp
if [ $(wc -c <$ERROR_FILE) -ne 0 ]; then
echo >> $tmp
echo "===============================================================" >> $tmp
echo >> $tmp
cat $ERROR_FILE >> $tmp
fi
mv $tmp $ERROR_FILE
fi
exit 0
fi
}
print_error() {
local error_file="${1:-}"
if [ -f $error_file ]; then
# The word 'error' can be upper or lower case
if grep -q "ERROR\|error" $error_file; then
cat $error_file
fi
rm $error_file
fi
}
#
# Only initialize ERROR_FILE once regardless of how many times
# this file is sourced, ie. its sourced by other scripts directly
# or indirectly when sourced by common_config.sh
#
if [ -z ${ERROR_FILE+x} ]; then
ERROR_FILE="$(mktemp /tmp/syndesis-output-XXXXX)"
trap "print_error $ERROR_FILE" EXIT
fi
get_executable_file_extension() {
local os=$(get_current_os)
if $(is_windows); then
echo ".exe"
fi
}
get_current_os() {
# Check for proper operating system
local os="linux"
if $(is_mac_os); then
os="mac"
elif $(is_windows); then
os="windows"
fi
echo $os
}
is_mac_os() {
if [ -z "${OSTYPE}" ]; then
if [ $(uname) == "Darwin" ]; then
echo "true"
fi
elif [ "${OSTYPE#darwin}" != "${OSTYPE}" ]; then
echo "true"
else
echo "false"
fi
}
is_windows() {
if [ -z "${OSTYPE}" ]; then
if [ $(uname) == "Windows" ]; then
echo "true"
fi
elif [ "${OSTYPE#windows}" != "${OSTYPE}" ]; then
echo "true"
else
echo "false"
fi
}