-
Notifications
You must be signed in to change notification settings - Fork 0
/
maintain.sh
executable file
·98 lines (81 loc) · 2.09 KB
/
maintain.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
#!/usr/bin/env bash
##### This script simply updates what is installed.
##### For changing what is installed, run the main installer.
##### That makes this safe to run anytime
##### and more likely to keep the main installer up to date.
# Set the local repo
REPO=~/github/mac-init/
BREW_FILE_PATH="${REPO}/brew/macOS.Brewfile"
# TODOs: use cli options for mac updates, esp XCode, and restarting
main() {
get_sudo # need for software update
update_homebrew
update_mas
update_pip
update_softwareupdate # Apple system and apps
}
function get_sudo() {
info "Sudo password"
if sudo --validate; then
# Keep-alive
while true; do sudo --non-interactive true; \
sleep 10; kill -0 "$$" || exit; done 2>/dev/null &
else
error "Fail get sudo password"
exit 1
fi
}
function update_homebrew() {
info "Homebrew"
brew outdated
brew upgrade --display-times
}
function update_mas() {
info "MAS"
mas outdated
mas upgrade
}
function update_softwareupdate() {
info "Softwareupdate"
sudo softwareupdate --install --recommended --restart #sudo needed to restart
}
function update_pip() {
info "Pip packages"
python3 -m pip install --upgrade pip
pip3 list --outdated | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U
}
### Helper functions
function coloredEcho() {
local exp="$1";
local color="$2";
local arrow="$3";
if ! [[ $color =~ '^[0-9]$' ]] ; then
case $(echo $color | tr '[:upper:]' '[:lower:]') in
black) color=0 ;;
red) color=1 ;;
green) color=2 ;;
yellow) color=3 ;;
blue) color=4 ;;
magenta) color=5 ;;
cyan) color=6 ;;
white|*) color=7 ;; # white or invalid color
esac
fi
tput bold;
tput setaf "$color";
echo "$arrow $exp";
tput sgr0;
}
function info() {
coloredEcho "$1" blue "========>"
}
function substep() {
coloredEcho "$1" magenta "===="
}
function success() {
coloredEcho "$1" green "========>"
}
function error() {
coloredEcho "$1" red "========>"
}
main "$@"