-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·146 lines (116 loc) · 3.22 KB
/
bootstrap.sh
File metadata and controls
executable file
·146 lines (116 loc) · 3.22 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
#!/usr/bin/env bash
#-----------------------------------------------------------------------------
# Functions
#-----------------------------------------------------------------------------
# Notice title
notice() { echo -e "\033[1;32m=> $1\033[0m"; }
# Error title
error() { echo -e "\033[1;31m=> Error: $1\033[0m"; }
# List item
c_list() { echo -e " \033[1;32m✔\033[0m $1"; }
# Error list item
e_list() { echo -e " \033[1;31m✖\033[0m $1"; }
verify_shell_startup() {
local startup_log
local suspicious_output_pattern
startup_log=$(mktemp)
suspicious_output_pattern='(^[A-Za-z_][A-Za-z0-9_]*=[^[:space:]]{16,}$|gh[pousr]_|github_pat_|nfp_)'
TERM_PROGRAM=Apple_Terminal VSCODE_USER_TERMINAL=1 zsh -lic 'exit' > "$startup_log" 2>&1
local status=$?
if [ $status -ne 0 ]; then
e_list "shell startup"
cat "$startup_log"
rm -f "$startup_log"
return $status
fi
if grep -Eq "$suspicious_output_pattern" "$startup_log"; then
e_list "shell startup"
cat "$startup_log"
rm -f "$startup_log"
return 1
fi
rm -f "$startup_log"
c_list "shell startup"
}
# Check for dependency
dep() {
type -p $1 &> /dev/null
local installed=$?
if [ $installed -eq 0 ]; then
c_list $1
else
e_list $1
fi
return $installed
}
install() {
local files=( $(ls -a) )
for file in "${files[@]}"; do
in_array $file "${excluded[@]}"
should_install=$?
if [ $should_install -gt 0 ]; then
[ -d "$HOME/$file" ] && rm -rf "$HOME/$file"
cp -Rf "$file" "$HOME/$file"
fi
done
}
in_array() {
local hay needle=$1
shift
for hay; do
[[ $hay == $needle ]] && return 0
done
return 1
}
#-----------------------------------------------------------------------------
# Initialize
#-----------------------------------------------------------------------------
dotfiles_root=$PWD
dependencies=(git zsh)
excluded=(. .. .git bootstrap.sh LICENSE.md README.md .DS_Store .vscode configs docs Brewfile Brewfile.lock.json)
#-----------------------------------------------------------------------------
# Dependencies
#-----------------------------------------------------------------------------
notice "Checking dependencies"
not_met=0
for need in "${dependencies[@]}"; do
dep $need
met=$?
not_met=$(echo "$not_met + $met" | bc)
done
if [ $not_met -gt 0 ]; then
error "$not_met dependencies not met!"
exit 1
fi
#-----------------------------------------------------------------------------
# Install
#-----------------------------------------------------------------------------
# Assumes $dotfiles_root is *ours*
if [ -d $dotfiles_root ]; then
pushd $dotfiles_root
# Install
notice "Installing"
install
else
# Clone Repo
notice "Downloading"
git clone --recursive git@github.com:sourcier/dotfiles.git $dotfiles_root
pushd $dotfiles_root
# Backup
notice "Backup up old files ($backupdir)"
backup
# Install
notice "Installing"
install
fi
notice "Verifying shell startup"
if ! verify_shell_startup; then
error "shell startup verification failed"
exit 1
fi
#-----------------------------------------------------------------------------
# Finished
#-----------------------------------------------------------------------------
popd
notice "Done"
#source "$HOME/.zshrc"