-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall
More file actions
executable file
·239 lines (217 loc) · 7.44 KB
/
Copy pathinstall
File metadata and controls
executable file
·239 lines (217 loc) · 7.44 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/env bash
set -eo pipefail
# --------------------------------------------------------------------
# Script to run all install scripts contained in install.d
#
if [[ -t 1 && -n "$TERM" && "$TERM" != "dumb" ]]; then
# Theme detection: explicit > COLORFGBG > macOS appearance > dark
if [[ -z "${DOTS_THEME:-}" ]]; then
if [[ -n "${COLORFGBG:-}" ]]; then
_bg="${COLORFGBG##*;}"
if (( _bg >= 7 )); then DOTS_THEME=light; else DOTS_THEME=dark; fi
unset _bg
elif [[ "$OSTYPE" == darwin* ]]; then
# AppleInterfaceStyle exists only in Dark mode; its absence means Light.
if [[ "$(defaults read -g AppleInterfaceStyle 2>/dev/null)" == Dark ]]; then
DOTS_THEME=dark
else
DOTS_THEME=light
fi
else
DOTS_THEME=dark
fi
fi
if [[ "$DOTS_THEME" == light ]]; then
# Darker, saturated tones for legibility on light backgrounds
TEAL=$'\033[38;2;26;120;100m'
TEAL_BOLD=$'\033[1;38;2;26;120;100m'
RED=$'\033[38;2;176;64;16m'
GREEN=$'\033[38;2;60;92;148m'
YELLOW=$'\033[38;2;148;96;0m'
GREY=$'\033[38;2;96;96;96m'
else
TEAL=$'\033[38;2;44;180;148m'
TEAL_BOLD=$'\033[1;38;2;44;180;148m'
RED=$'\033[38;2;248;140;20m'
GREEN=$'\033[38;2;114;144;184m'
YELLOW=$'\033[38;2;252;252;56m'
GREY=$'\033[38;2;128;128;128m'
fi
NC=$'\033[0m'
else
TEAL=""
TEAL_BOLD=""
RED=""
GREEN=""
YELLOW=""
GREY=""
NC=""
fi
# Log functions
log_info() { echo -e "${TEAL}[INFO]${NC} $*"; }
log_pass() { echo -e "${GREEN}[PASS]${NC} $*"; }
log_skip() { echo -e "${GREY}[SKIP]${NC} $*"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
log_error() { echo -e "${RED}[FAIL]${NC} $*"; }
log_debug() { echo -e "${TEAL}$*${NC}"; }
log_quote() { sed "s/^/ ${GREY}│ /" | sed "s/$/${NC}/"; }
log_indent() { sed "s/^/ │ /"; }
# Export log functions
export -f log_info log_pass log_skip log_warn log_error log_debug log_quote log_indent
printf "\n\t${TEAL} <<< ${TEAL_BOLD}dots${TEAL} >>> ${NC}\n"
printf "\t${GREY}==============${NC}\n\n"
# High-resolution time helpers
if date +%s%N 2>/dev/null | grep -qE '^[0-9]+$'; then
now_ns() { date +%s%N; }
else
now_ns() { echo $(( $(date +%s) * 1000000000 )); }
fi
# Prevent running as root
if [[ $EUID -eq 0 && -z "$SKIP_SUDO_CHECK" ]]; then
echo -e "${RED}Failed: Running as sudo. Please run as user${NC}\n"
exit 1
fi
# Ensure sudo credentials are cached
if [[ -z "$SKIP_SUDO_CHECK" ]]; then
if ! sudo -n true 2>/dev/null; then
log_warn "Requesting sudo authentication..."
sudo -v
fi
fi
# Set up environment
export DOTS_OS=""
export DOTS_PKG=""
export DOTS_ENV=""
if [[ -n "${CODESPACES:-}" ]]; then
DOTS_ENV="codespaces"
fi
case "$OSTYPE" in
darwin*) DOTS_OS="macos"; DOTS_PKG="brew" ;;
linux*)
DOTS_OS="linux"
if command -v apt-get &>/dev/null; then
DOTS_PKG="apt"
elif command -v pacman &>/dev/null; then
DOTS_PKG="pacman"
elif command -v apk &>/dev/null; then
DOTS_PKG="apk"
elif command -v dnf &>/dev/null; then
DOTS_PKG="dnf"
fi
;;
esac
# Detect enforced Microsoft Defender (endpoint AV). Its per-file open() scan
# makes ripgrep slow on huge repos, so the csearch tooling (30-mise.sh binaries,
# 33-csearch.sh watcher) is gated on this — managed/work Macs only.
export DOTS_DEFENDER=""
if [[ "$DOTS_OS" == "macos" ]] && { [[ -d "/Applications/Microsoft Defender.app" ]] || command -v mdatp &>/dev/null; }; then
DOTS_DEFENDER="1"
fi
# Set up Homebrew environment
if [[ "$DOTS_PKG" == "brew" ]]; then
export NONINTERACTIVE=1
export HOMEBREW_NO_ANALYTICS=1
export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
export HOMEBREW_NO_ENV_HINTS=1
export HOMEBREW_NO_AUTO_UPDATE=1
export HOMEBREW_NO_INSTALL_CLEANUP=1
fi
# Set up directory variables
if [ -L "$0" ]; then
dir=$(dirname $(readlink -f "$0"))
else
dir=$(dirname "$0")
fi
export DOTFILES=$(dirname "$dir")
install_dir="$DOTFILES/install.d"
# Set up log destination
if [[ -z "$LOG_TARGET" ]]; then
timestamp=$(date +%Y-%m-%dT%H:%M:%S)
uuid=$(
uuidgen 2> /dev/null \
|| cat /proc/sys/kernel/random/uuid 2> /dev/null \
|| echo $RANDOM
)
log_dir="$dir/logs"
mkdir -p "$log_dir"
log_target=${LOG_TARGET:-"$log_dir/$uuid.log"}
else
log_target="$LOG_TARGET"
fi
touch "$log_target"
if [[ ! -f "$log_target" ]]; then
echo -e "${RED}Failed: Unable to create log file \"$log_target\"${NC}\n"
exit 1
fi
log_abs_target=$(readlink -f "$log_target")
# Set up targets
targets=($@)
# Run install scripts
run() {
{
echo "Running \"$(basename "$0")\" at \"$(date)\""
echo "Running as \"$(whoami)\" on \"$(hostname)\""
if [[ -n "$targets" ]]; then
echo "Running ${#targets[@]} install target(s): ${targets[*]}"
else
echo "Running all install targets"
fi
} | log_quote
# Cache brew package lists (avoid repeated slow brew queries in install scripts)
if [[ "$DOTS_PKG" == "brew" ]]; then
log_info "Caching brew package lists..."
local cask_versions_tmp=$(mktemp)
local formula_versions_tmp=$(mktemp)
brew list --cask --versions 2>/dev/null > "$cask_versions_tmp" &
local cask_pid=$!
brew list --versions 2>/dev/null > "$formula_versions_tmp" &
local formula_pid=$!
wait "$cask_pid" "$formula_pid" 2>/dev/null || true
export BREW_CASK_VERSIONS=$(cat "$cask_versions_tmp")
export BREW_FORMULA_VERSIONS=$(cat "$formula_versions_tmp")
export BREW_CASKS=$(awk '{print $1}' <<< "$BREW_CASK_VERSIONS")
export BREW_FORMULAE=$(awk '{print $1}' <<< "$BREW_FORMULA_VERSIONS")
rm -f "$cask_versions_tmp" "$formula_versions_tmp"
fi
scripts=("$install_dir"/*.sh)
for script in "${scripts[@]}"; do
if [[ -n "$targets" ]]; then
script_name=$(basename "$script" .sh)
script_name=${script_name#*-}
if [[ ! " ${targets[*]} " =~ " $script_name " ]]; then
continue
fi
fi
local script_name=$(basename "$script")
local label=" ${script_name} "
local rule_width=40
local label_len=${#label}
local pad_len=$(( rule_width - label_len - 2 ))
(( pad_len < 2 )) && pad_len=2
local pad=$(printf '─%.0s' $(seq 1 "$pad_len"))
printf "\n${GREY}──${label}${pad}${NC}\n"
local start_ns=$(now_ns)
source "$script"
local end_ns=$(now_ns)
local execution_ms=$(( (end_ns - start_ns) / 1000000 ))
local execution_ms_formatted=$(printf "%'d" "$execution_ms")
local time_color="$GREY"
if (( execution_ms < 2000 )); then
time_color="$GREEN"
elif (( execution_ms < 5000 )); then
time_color="$YELLOW"
else
time_color="$RED"
fi
printf "${GREY}── ${time_color}${execution_ms_formatted}ms${NC}\n"
done
}
log_info "Logging to \"$log_abs_target\""
total_start_ns=$(now_ns)
run 2>&1 | tee "$log_abs_target"
total_end_ns=$(now_ns)
total_ms=$(( (total_end_ns - total_start_ns) / 1000000 ))
total_s=$(( total_ms / 1000 ))
total_ms_rem=$(( total_ms % 1000 ))
printf "\n${TEAL}Thank you!${NC}\n"
printf "Total time: ${GREEN}%d.%03ds${NC}\n\n" "$total_s" "$total_ms_rem"