-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource_shell_scripts.bash
83 lines (79 loc) · 3.42 KB
/
source_shell_scripts.bash
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
#!/usr/bin/env bash
## <script src="https://get-fig-io.s3.us-west-1.amazonaws.com/readability.js"></script>
## <link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.16.0/themes/prism-okaidia.min.css" rel="stylesheet" />
## <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.16.0/components/prism-core.min.js" data-manual></script>
## <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.16.0/components/prism-bash.min.js"></script>
## <style>body {color: #272822; background-color: #272822; font-size: 0.8em;} </style>
# Parent Repository Directory
SHELL_SCRIPTS_GITHUB_REPOSITORY="bitflight-devops/shell-scripts"
BASE_INSTALL_DIR="${HOME}/.config/${SHELL_SCRIPTS_GITHUB_REPOSITORY}"
SCRIPTS_LIB_DIR_FOUND=0
is_scripts_lib_dir() { [[ -f "${1}/.scripts.lib.md" ]]; }
# Current Script Directory
if [[ -n ${BFD_REPOSITORY:-} ]] && [[ -x ${BFD_REPOSITORY} ]]; then
SCRIPTS_LIB_DIR="${BFD_REPOSITORY}/lib"
fi
if [[ -z ${SCRIPTS_LIB_DIR:-} ]]; then
if grep -q 'zsh' <<<"$(ps -c -ocomm= -p $$)"; then
# shellcheck disable=SC2296
SCRIPTS_LIB_DIR="${0:a:h}"
SCRIPTS_LIB_DIR="$(cd "${SCRIPTS_LIB_DIR}" >/dev/null 2>&1 && pwd -P)"
else
SCRIPTS_LIB_DIR="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd -P)"
fi
fi
: "${BFD_REPOSITORY:=${SCRIPTS_LIB_DIR%/lib}}"
# Check if the SCRIPTS_LIB_DIR is actually in the lib repository folder
if is_scripts_lib_dir "${SCRIPTS_LIB_DIR}"; then
SCRIPTS_LIB_DIR_FOUND=1
else
# Are we in the root of the repo directory?
if is_scripts_lib_dir "${SCRIPTS_LIB_DIR}"/lib; then
SCRIPTS_LIB_DIR="${SCRIPTS_LIB_DIR}"/lib
SCRIPTS_LIB_DIR_FOUND=1
else
# Or are we in a child directory of the git repository?
if command_exists git; then
GIT_BASE_DIR="$(git rev-parse --show-toplevel 2>/dev/null)"
command_exists readlink && GIT_BASE_DIR="$(readlink -f "${GIT_BASE_DIR}" 2>/dev/null)"
elif [[ -f ${SCRIPTS_LIB_DIR}/.git/config ]] && grep -q "$(basename "${SHELL_SCRIPTS_GITHUB_REPOSITORY}")" "${SCRIPTS_LIB_DIR}/.git/config"; then
# No git binary, but still in the git repository folder?
GIT_BASE_DIR="${SCRIPTS_LIB_DIR}"
fi
if [[ -n ${GIT_BASE_DIR:-} ]] && is_scripts_lib_dir "${GIT_BASE_DIR}/lib"; then
SCRIPTS_LIB_DIR="${GIT_BASE_DIR}/lib"
SCRIPTS_LIB_DIR_FOUND=1
fi
fi
fi
REQUIRES_INSTALLING=0
if [[ ${SCRIPTS_LIB_DIR_FOUND} -eq 0 ]]; then
if is_scripts_lib_dir "${BASE_INSTALL_DIR}"/lib; then
SCRIPTS_LIB_DIR="${BASE_INSTALL_DIR}"/lib
SCRIPTS_LIB_DIR_FOUND=1
else
REQUIRES_INSTALLING=1
fi
fi
if [[ ${REQUIRES_INSTALLING} -eq 1 ]]; then
if [[ -z ${AUTO_INSTALL:-} ]]; then
echo "The shell-scripts library is not installed."
echo "Please run the following command to install it:"
echo " curl -sL \"https://raw.githubusercontent.com/${SHELL_SCRIPTS_GITHUB_REPOSITORY}/main/install.sh\" | bash"
exit 1
else
echo "Installing shell-scripts library..."
if ! curl -sL "https://raw.githubusercontent.com/${SHELL_SCRIPTS_GITHUB_REPOSITORY}/main/install.sh" | bash; then
echo "Failed to install shell-scripts library."
exit 1
fi
fi
fi
# ------------------------------------------
# Notes
# ------------------------------------------
#
# This script contains hidden JavaScript which is used to improve
# readability in the browser (via syntax highlighting, etc), right-click
# and "View source" of this page to see the entire bash script!
# -- style code from https://fig.io/install