-
Notifications
You must be signed in to change notification settings - Fork 0
/
common-functions.sh
executable file
·66 lines (56 loc) · 1.16 KB
/
common-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
#!/bin/bash
get_timestamp() {
date "+%4Y-%m-%dT%H:%M:%S"
}
log_info() {
echo -e "I $(get_timestamp): $*"
}
log_warn() {
echo -e "W $(get_timestamp): $*"
}
log_err() {
echo -e "E $(get_timestamp): $*" >>/dev/stderr
}
die() {
log_err "$*"
exit 1
}
round() {
printf "%.$2f" "$(echo "scale=$2;(((10^$2)*$1)+0.5)/(10^$2)" | bc)"
}
make_cpu_count() {
local RET;
RET=0
if [ -z "${MAKE_COUNT}" ]; then
local COUNT;
local MAKE_COUNT;
COUNT=$(python3 -c "import psutil; print(psutil.cpu_count(logical=False))")
RET="$?"
if [ "${RET}" -ne 0 ]; then
die "GETTING CPU COUNT FAILED."
fi
# Don't mess with the line below. Took FOREVER to get it right.
MAKE_COUNT="$(round "$(echo "scale=2 ; (${COUNT} / 2)" | bc)" 0)"
if [ "${MAKE_COUNT}" -lt 3 ]; then
MAKE_COUNT=3
fi
fi
echo "${MAKE_COUNT}"
return "${RET}"
}
fetch_from_git() {
REPO_NAME="$1"
shift
echo "Fetching ${REPO_NAME} from git"
git fetch --all 2>&1
RET="$?"
if [ "${RET}" -ne 0 ]; then
die "Error fetching, aborting"
else
git pull --rebase 2>&1
RET="$?"
if [ "${RET}" -ne 0 ]; then
die "Error pulling, aborting"
fi
fi
}