-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·123 lines (106 loc) · 2.85 KB
/
Copy pathupdate.sh
File metadata and controls
executable file
·123 lines (106 loc) · 2.85 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
#!/usr/bin/env zsh
# No -e on purpose: each updater is tracked and failures are summarized
# at the end instead of aborting the remaining ones.
set -uo pipefail
readonly SCRIPT_DIR="${0:A:h}"
readonly REPO_DIR="${SCRIPT_DIR:h}"
readonly BREWFILE="$REPO_DIR/Backup/Brewfile"
readonly RED=$'\033[31m'
readonly GREEN=$'\033[32m'
readonly YELLOW=$'\033[33m'
readonly BLUE=$'\033[34m'
readonly BOLD=$'\033[1m'
readonly CLEAR=$'\033[0m'
SUCCEEDED=()
FAILED=()
SKIPPED=()
println() {
printf '\n%s==> %s%s\n' "$GREEN" "$*" "$CLEAR"
}
print_err() {
printf '%s%s%s\n' "$RED" "$*" "$CLEAR" >&2
}
print_skip() {
printf '%s--> skip: %s (%s not found)%s\n' "$YELLOW" "$1" "$2" "$CLEAR"
SKIPPED+=("$1")
}
track() {
local name="$1"; shift
if "$@"; then
SUCCEEDED+=("$name")
else
print_err "$name update failed"
FAILED+=("$name")
fi
}
if command -v brew >/dev/null 2>&1; then
println "Updating Brew Packages"
ok=true
brew update && brew upgrade --greedy || ok=false
brew cleanup || true
brew autoremove || true
if $ok; then
SUCCEEDED+=("Brew")
else
print_err "Brew update failed"
FAILED+=("Brew")
fi
else
print_skip "Brew" "brew"
fi
if command -v npm >/dev/null 2>&1; then
println "Updating NPM Packages"
track "NPM" npm update --location=global
else
print_skip "NPM" "npm"
fi
if command -v pipx >/dev/null 2>&1; then
println "Updating Pipx Packages"
track "Pipx" pipx upgrade-all --include-injected
else
print_skip "Pipx" "pipx"
fi
if command -v cargo >/dev/null 2>&1; then
println "Updating Rust Packages"
crates=( ${(f)"$(cargo install --list | grep -E '^[a-z0-9_-]+ v[0-9.]+:$' | cut -f1 -d' ')"} )
if (( ${#crates[@]} > 0 )); then
track "Rust" cargo install "${crates[@]}"
else
SUCCEEDED+=("Rust")
fi
else
print_skip "Rust" "cargo"
fi
if command -v fish >/dev/null 2>&1; then
println "Updating Fish Packages"
track "Fish" fish -c "fisher update"
else
print_skip "Fish" "fish"
fi
if command -v mas >/dev/null 2>&1; then
println "Updating Mac Apps"
track "Mac Apps" mas upgrade
else
print_skip "Mac Apps" "mas"
fi
if [ -x "$HOME/.config/tmux/plugins/tpm/bin/update_plugins" ]; then
println "Updating Tmux Plugins"
track "Tmux" "$HOME/.config/tmux/plugins/tpm/bin/update_plugins" all
else
print_skip "Tmux" "tpm"
fi
if command -v brew >/dev/null 2>&1; then
println "Refreshing Brewfile"
track "Brewfile" brew bundle dump --force --file="$BREWFILE"
fi
printf '\n%s%s==> Summary%s\n' "$BLUE" "$BOLD" "$CLEAR"
for s in "${SUCCEEDED[@]}"; do
printf ' %s✓%s %s\n' "$GREEN" "$CLEAR" "$s"
done
for s in "${SKIPPED[@]}"; do
printf ' %s-%s %s (skipped)\n' "$YELLOW" "$CLEAR" "$s"
done
for s in "${FAILED[@]}"; do
printf ' %s✗%s %s\n' "$RED" "$CLEAR" "$s"
done
[ ${#FAILED[@]} -eq 0 ]