-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
119 lines (92 loc) · 2.73 KB
/
init.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env bash
if [[ -z "$IS_DOCKER" ]]; then
SOURCE_DIR="$(dirname -- "$0")"
# echo "source dir: $SOURCE_DIR"
# echo "0: $0"
# echo "bash source: $BASH_SOURCE"
if [ ! -z ${BASH_SOURCE[0]} ]; then
SCRIPT_PATH="${BASH_SOURCE[0]}"
else
SCRIPT_PATH="$SOURCE_DIR/init.sh"
fi
export CHI_DIR="$(dirname $SCRIPT_PATH)"
fi
function chiLoadDir() {
for file in "$@"; do
source "$file"
done
}
function autoinitChi() {
if [[ ! -z "$CHI_FAIL_ON_ERROR" ]]; then
set -e
fi
if [[ -z "$ZSH_VERSION" ]]; then
shopt -s globstar
else
setopt ksh_glob
setopt shwordsplit
fi
set -o pipefail
[[ "$CHI_AUTOINIT_DISABLED" = "true" ]] || chiShell
}
function chiShell() {
local startTime=$(date +%s)
# reset envvars if reloading, besides CHI_DIR and CHI_LOG_LEVEL
if [[ ! -z "$CHI_ENV_INITIALIZED" ]]; then
local chiDir=$CHI_DIR
local chiLogLevel=$CHI_LOG_LEVEL
unset $(env | grep "^CHI_" | sed 's/=.*//')
export CHI_DIR=$chiDir
export CHI_LOG_LEVEL=$chiLogLevel
fi
# load init chain
chiLoadDir $CHI_DIR/chains/init/**/*.sh
chiLogInfo "initializing chitin..." init
chiColorInit
chiInitBootstrapDeps
# load meta chain
chiLoadDir $CHI_DIR/chains/meta/**/*.sh
chiConfigUserLoad "$1"
if ! chiToolsLoadFromCache; then
chiLogInfo "tools status cache not found, rebuilding..." meta tools
export CHI_CACHE_TOOLS_REBUILD=true
fi
local isNoCheck="$([[ -n "$IS_DOCKER" ]] || [[ -n "$CHI_NOCHECK" ]] && echo "nocheck")"
# load core chains
chiFiberLoad "$CHI_DIR" "core" "$isNoCheck"
# load dotfiles
if [[ -n "$CHI_DOTFILES_DIR" ]]; then
chiFiberLoad "$CHI_DOTFILES_DIR" dotfiles "$isNoCheck"
fi
chiFiberLoadExternal "$isNoCheck"
export CHI_ENV_INITIALIZED=true
unset CHI_CACHE_TOOLS_REBUILD
if [[ -z "$CHI_FAIL_ON_ERROR" ]]; then
set +e
fi
chiRunInitCommand
if [[ -d "$CHI_INIT_TEMP_DIR" ]]; then
chiLogInfo "cleaning up bootstrap deps" init
chiToolsRemoveDirFromPath "$CHI_INIT_TEMP_DIR"
rm -rf "$CHI_INIT_TEMP_DIR"
fi
local endTime=$(gdate +%s)
local duration=$((endTime - startTime))
chiLogGreen "initialized in $duration seconds" init
if [[ -f "$CHI_LOG_TIME" ]]; then
rm "$CHI_LOG_TIME"
fi
}
function chiShellDebug() {
CHI_LOG_LEVEL=DEBUG chiShell
}
function chiRunInitCommand() {
local initCommand
initCommand="$(chiConfigUserRead core init command)"
if [[ $? -eq 0 ]]; then
$initCommand
fi
# echo "initcommand: $initCommand"
# [[ -z "$initCommand" ]] && return 0
}
autoinitChi