-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.sh
70 lines (54 loc) · 1.72 KB
/
setup.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
#!/usr/bin/env bash
set -e
BELT_REPO="https://github.com/belt-project/belt.sh"
BELT_VERSION="master"
BELT_PATH_PREFIX="${BELT_ENV_PATH_PREFIX:-"/usr/local/lib"}"
BELT_PATH="$BELT_PATH_PREFIX/belt/$BELT_VERSION"
BELT_TOOLBOX_REPO="${BELT_ENV_TOOLBOX_REPO:-"https://github.com/belt-project/toolbox"}"
BELT_TOOLBOX_TOOLS="$BELT_ENV_TOOLBOX_TOOLS"
BELT_TOOLBOX_PATH="$BELT_PATH_PREFIX/belt/toolbox"
bootstrap_abort() {
local msg="$1"
echo "belt: $msg"
exit 1
}
bootstrap_clone() {
[[ -n "$BELT_ENV_DEBUG" ]] && echo "Cloning belt.sh..."
git clone -b "$BELT_VERSION" "$BELT_REPO" "$BELT_PATH" &>/dev/null || bootstrap_abort "git clone failed for belt"
}
bootstrap_update() {
[[ -n "$BELT_ENV_DEBUG" ]] && echo "Updating belt.sh..."
git -C "$BELT_PATH" pull &>/dev/null || bootstrap_abort "git pull failed for belt"
}
bootstrap_toolbox_clone() {
[[ -n "$BELT_ENV_DEBUG" ]] && echo "Cloning toolbox..."
git clone "$BELT_TOOLBOX_REPO" "$BELT_TOOLBOX_PATH" &>/dev/null || bootstrap_abort "git clone failed for toolbox"
}
bootstrap_toolbox_update() {
[[ -n "$BELT_ENV_DEBUG" ]] && echo "Updating toolbox..."
git -C "$BELT_TOOLBOX_PATH" pull &>/dev/null || bootstrap_abort "git pull failed for toolbox"
}
bootstrap() {
if [[ ! -x "$(command -v git)" ]]; then
bootstrap_abort "git not found"
fi
if [[ -d "$BELT_PATH" ]]; then
if [[ "$BELT_VERSION" = "master" || ! "$BELT_VERSION" =~ ^v ]]; then
bootstrap_update
fi
fi
if [[ ! -d "$BELT_PATH" ]]; then
bootstrap_clone
fi
if [[ -n "$BELT_TOOLBOX_TOOLS" ]]; then
if [[ -d "$BELT_TOOLBOX_PATH" ]]; then
bootstrap_toolbox_update
fi
if [[ ! -d "$BELT_TOOLBOX_PATH" ]]; then
bootstrap_toolbox_clone
fi
fi
}
bootstrap
# shellcheck disable=SC1090
source "$BELT_PATH/belt.sh"