-
Notifications
You must be signed in to change notification settings - Fork 4
/
bee
executable file
·93 lines (81 loc) · 2.66 KB
/
bee
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
92
93
#!/usr/bin/env bash
#
# 🐝 bee - plugin-based bash automation
#
# Shell Style Guide
# https://google.github.io/styleguide/shell.xml
#
# "bash strict mode"
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
#
# shellcheck disable=SC1090,SC1091
set -euo pipefail
IFS=$'\n\t'
: "${BEE_RC:="${HOME}/.beerc"}"
: "${BEE_RESOURCES:=.bee}"
: "${BEE_ORIGIN:=https://github.com/sschmid/bee.git}"
: "${BEE_CACHES_PATH:="${HOME}/.bee/caches"}"
: "${BEE_OSTYPE:=${OSTYPE%%[[:digit:]]*}}"
: "${BEE_COLOR_SUCCESS:=\033[0;32m}"
: "${BEE_COLOR_WARN:=\033[0;33m}"
: "${BEE_COLOR_FAIL:=\033[0;31m}"
: "${BEE_COLOR_RESET:=\033[0m}"
: "${BEE_LINE_RESET:=\r\033[2K}"
: "${BEE_CHECK_SUCCESS:="✔"}"
: "${BEE_CHECK_FAIL:="✗"}"
: "${BEE_RESULT:="➜"}"
: "${BEE_ICON:="🐝"}"
: "${BEE_WARN:="🟠"}"
: "${BEE_ERR:="🔴"}"
declare -ig BEE_QUIET=0
bee::log_echo() { ((BEE_QUIET)) || echo "$*"; }
bee::log() { bee::log_echo "${BEE_ICON} $*"; }
bee::log_info() {
bee::log_echo "################################################################################"
bee::log "$*"
bee::log_echo "################################################################################"
}
bee::log_func() { bee::log_info "${FUNCNAME[1]} $*"; }
bee::log_warn() { echo "${BEE_WARN} $*" >&2; }
bee::log_error() { echo "${BEE_ERR} $*" >&2; }
bee::env() { for v in "$@"; do echo "${!v}"; done; }
BEE_SYSTEM_HOME="${BASH_SOURCE[0]}"
while [[ -L "${BEE_SYSTEM_HOME}" ]]; do
BEE_SYSTEM_HOME="$(readlink "${BEE_SYSTEM_HOME}")"
done
BEE_SYSTEM_HOME="$(cd "$(dirname "${BEE_SYSTEM_HOME}")/.." && pwd)"
[[ ! -f "${BEE_RC}" ]] && cat << 'EOF' > "${BEE_RC}"
BEE_HUBS=(https://github.com/sschmid/beehub.git)
EOF
source "${BEE_RC}"
if [[ -v BEE_FILE ]]; then source "${BEE_FILE}"
elif [[ -f "Beefile" ]]; then BEE_FILE="Beefile"; source "${BEE_FILE}"; fi
if [[ -v BEE_VERSION ]]; then
BEE_HOME="${BEE_CACHES_PATH}/bee/${BEE_VERSION}"
[[ ! -d "${BEE_HOME}" ]] &&
git -c advice.detachedHead=false clone -q --depth 1 --branch "${BEE_VERSION}" "${BEE_ORIGIN}" "${BEE_HOME}"
else
BEE_HOME="${BEE_SYSTEM_HOME}"
fi
bee_migration_1000() {
if [[ -v BEE_VERSION ]]; then
local major="${BEE_VERSION%%.*}"
if [[ "${major}" -eq 0 ]]; then
"${BEE_HOME}/src/bee" "$@"
exit
fi
fi
}
bee_migration_1000 "$@"
bee::load_os() {
local path="$1"
if [[ -f "${path}/os/${BEE_OSTYPE}.bash" ]]; then
source "${path}/os/${BEE_OSTYPE}.bash"
elif [[ -f "${path}/os/generic.bash" ]]; then
source "${path}/os/generic.bash"
# bee::log_warn "Missing platform support for ${BEE_OSTYPE} (${OSTYPE})"
fi
}
bee::load_os "${BEE_HOME}/src"
source "${BEE_HOME}/src/bee-run.bash"
[[ "${BASH_SOURCE[0]}" != "$0" ]] || bee::run "$@"