-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon
More file actions
33 lines (26 loc) · 1.21 KB
/
Copy pathcommon
File metadata and controls
33 lines (26 loc) · 1.21 KB
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
#!/bin/bash
# Common functionality library imported by all other scripts in this directory
# Quit on any error (must be set per-shell, even if already initialized in a parent)
set -e
# Skip the rest of setup if INIT has already been defined in this shell.
# Checking the function directly (rather than an env-var flag) is reliable across
# newer bash versions where exported functions don't always propagate to subshells.
declare -F INIT >/dev/null && return 0
# Force all scripts to use non-interactive DPKG prompts on install
export DEBIAN_FRONTEND=noninteractive
# Import the config (resolve via BASH_SOURCE so CWD doesn't matter)
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config"
export INIT_HOME INIT_SRC INIT_CMD_PATH INIT_AUTO_TMUX
# Call a utility function as sourced within the current shell
function INIT {
UTIL="$1"
shift
# Special case for go-* where these scripts need including as source so we can change dir (rather than isolating them to their own Bash process)
if [[ "$UTIL" == go-* ]]; then
source "$INIT_HOME/utils/$UTIL" "$@"
else
"$INIT_HOME/utils/$UTIL" "$@"
fi
}
# Expose INIT to all sub-shells (best-effort; the guard above handles the case where it doesn't propagate)
export -f -- INIT