-
Notifications
You must be signed in to change notification settings - Fork 2
/
update.sh
executable file
·231 lines (181 loc) · 5.13 KB
/
update.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
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
#!/bin/sh
# shellcheck disable=SC3043
set -eu
#################################
# update.sh is a GENERATED FILE #
#################################
# All changes should be made to installers/update.sh
# and included files therin, as the root one is compiled
export DOTFILES_INSTALLER=""
# BEGIN included from installers/prelude.sh
# Prelude which includes necessary scripts for the dotfiles installer to run
# BEGIN included from installers/configure.sh
# Initialize DOTFILES and related configuration variables
GITHUB_REPO="${GITHUB_REPO:-alexrudy/dotfiles}"
GIT_BRANCH="main"
export GITHUB_REPO GIT_BRANCH
DOTFILES_INSTALLER=${DOTFILES_INSTALLER:-}
DOTFILES="${DOTFILES:-${HOME}/.dotfiles/}"
if [ "$DOTFILES" = "/" ]; then
DOTFILES="${HOME}/.dotfiles/"
fi
if test -z "${DOTFILES_INSTALLER}"; then
if ! test -d "${DOTFILES}"; then
DOTFILES=$(readlink -f "$(dirname "$0")")
if test "${DOTFILES}" -eq "${HOME}"; then
echo "ERROR: DOTFILES cannot be found."
exit 1
fi
export DOTFILES
fi
fi
NONINTERACTIVE=1
export NONINTERACTIVE
DEBIAN_FRONTEND=noninteractive
export DEBIAN_FRONTEND
TERM="${TERM:-dumb}"
export TERM
if test -z "${DOTFILES_INSTALLER}"; then
cd "${DOTFILES}"
fi
# END included from installers/configure.sh
# BEGIN included from installers/functions.sh
# Library of functions useful for installing.
# Everything here should be POSIX sh
# Allow shellcheck to ignore unused functions
LOGFILE="${LOGFILE:-${HOME}/.dotfiles-install.log}"
LEVEL=${LEVEL:-0}
DEBUG=${DEBUG:-0}
_spacer() {
spacer=""
j=0
while [ $j -lt "$LEVEL" ]; do
spacer="$spacer "
j=$(( j + 1 ))
done
echo "$spacer"
}
_log_timestamp() {
date +%H:%M:%S
}
_log_init() {
printf "$(_log_timestamp) [%-10.10s]: %s\n" "init" "$1" > "$LOGFILE"
printf "$(_log_timestamp) [%-10.10s]: %s\n" "init" "$(date)" >> "$LOGFILE"
printf "$(_log_timestamp) [%-10.10s]: %s\n" "init" "installing in ${DOTFILES}" >> "$LOGFILE"
}
_log() {
local message
message=$(echo "$2" | perl -pe's/[[:space:]]*[[:^ascii:]]+[[:space:]]*//' )
printf "$(_log_timestamp) [%-10.10s]: %s\n" "$1" "${message}" >> "$LOGFILE"
}
_print() {
local message color
message="$1"
color="$2"
if [ -t 1 ]; then
printf "$(_spacer)$(tput setaf "$color")%s$(tput sgr0)\n" "$message" 2> /dev/null
else
printf "$(_spacer)%s\n" "$message" 2> /dev/null
fi
}
_debug() {
local message color
message="$*"
_log "debug" "$message"
if [ "$DEBUG" -eq "1" ]; then
_print "$message" "4"
fi
}
_message() {
local message color
message="$*"
color=$(_color_code "$message")
_log "debug" "$message"
_print "$message" "7"
}
_process() {
message="$*"
_log "start(${LEVEL})" "$message"
_print "$message" "7"
LEVEL=$(( LEVEL + 1))
trap '_cleanup "$message"' EXIT
}
_finished() {
message="$*"
LEVEL=$(( LEVEL - 1))
color=$(_color_code "$message")
_log "finish(${LEVEL})" "$message"
_print "$message" "$color"
trap - EXIT
}
_error() {
message="$*"
LEVEL=$(( LEVEL - 1))
_log "error" "$message"
_print "$message" "1"
}
_cleanup() {
_error "⛔️ Install step $1 encountered an error"
}
_color_code() {
case "$*" in
✅*)
echo 2;;
⚠️*)
echo 3;;
⛔️*)
echo 1;;
❌*)
echo 1;;
*)
echo 7;;
esac
}
command_exists () {
type "$1" > /dev/null 2>&1
}
# END included from installers/functions.sh
# END included from installers/prelude.sh
update () {
_log_init "$0"
if ! test -d "${DOTFILES}/.git"; then
# BEGIN included from installers/git-overlay.sh
# Already included installers/prelude.sh
# shellcheck source=installers/prelude.sh
git_overlay() {
if ! test -d "${DOTFILES}/.git"; then
_process "🎛️ Adding git repository overlay"
git init --quiet
git remote add origin "https://github.com/${GITHUB_REPO}/"
git fetch --quiet
git checkout --quiet -ft "origin/${GIT_BRANCH}"
_finished "✅ Converted ${DOTFILES} to a git repository"
fi
}
git_overlay
# END included from installers/git-overlay.sh
fi
# BEGIN included from installers/downloaders/download-git-pull.sh
# Already included installers/prelude.sh
# shellcheck source=installers/prelude.sh
download_git_pull() {
if test -d "${DOTFILES}" ; then
if command_exists git; then
_message "🐙 Pull latest dotfiles from github"
if git -C "$DOTFILES" pull --quiet --recurse-submodules > /dev/null 2>&1 ; then
_message "🐙 Updated dotfiles git repo"
else
# Not a hard failure
_message "⚠️ Failed to update git repo"
fi
fi
else
exit 1
fi
}
download_git_pull
# END included from installers/downloaders/download-git-pull.sh
# shellcheck source=installers/installer.sh # no-include
. "${DOTFILES}/installers/installer.sh"
}
update "$@"