-
Notifications
You must be signed in to change notification settings - Fork 6
/
common.sh
44 lines (38 loc) · 1.03 KB
/
common.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
# Common functions shared between scripts
# This file should be sourced
function block-print() {
echo "============================================================"
printf "$@"
echo
echo "============================================================"
}
function ensure-bin() {
if ! "$@" > /dev/null; then
echo "Command '$@' failed. Please install '$1' from your distribution's package manager." >&2
exit 1
fi
}
function ensure-path() {
if [[ ! -d "$1" ]]; then
echo "$2" >&2
exit 1
fi
}
function write-env() {
sed -i "/^$1=/d" "$basedir/common-env"
printf '%s="%s"\n' "$1" "$2" >> "$basedir/common-env"
}
function warn-prompt() {
echo "$@" >&2
if [[ ! "$warn_prompt_headless" = 1 ]]; then
read -n 1 -s -r -p "Press any key to continue, or Ctrl-C to cancel..."
fi
}
function load-env() {
source ./versions
if ! source ./common-env; then
echo "Environment file does not exist!" >&2
echo "Did you run setup.sh?" >&2
exit 1
fi
}