forked from davidosomething/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mac
executable file
·158 lines (129 loc) · 4.99 KB
/
mac
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
#!/usr/bin/env zsh
#
# Idempotently set up macOS
#
# ============================================================================
# initialize script and dependencies
# ============================================================================
if [[ -z "$DOTFILES" ]]; then
cd -- "$(dirname "$0")/.." || exit 1
DOTFILES="$PWD"
fi
. "${DOTFILES}/lib/helpers.sh"
. "${DOTFILES}/lib/pretty.bash"
export PATH="${DOTFILES}/bin:${PATH}"
[[ "$OSTYPE" == *'arwin'* ]] || {
__dko_err "This script is for Darwin only"
exit 1
}
# ============================================================================
# check prereqs
# ============================================================================
__dko_require 'brew' || {
__dko_err "Missing brew, install as on https://brew.sh"
exit 1
}
"${DOTFILES}/bootstrap/symlink" || exit 1
"${DOTFILES}/bootstrap/cleanup" || exit 1
# ============================================================================
# zsh fixes
# ============================================================================
# compaudit will detect these
__dko_status "Fixing zsh directory perms (sudo)"
sudo chmod g-w /usr/local/share/zsh/site-functions
sudo chmod g-w /usr/local/share/zsh
# See https://github.com/postmodern/chruby/issues/196#issuecomment-23826171
if [ -f /etc/zshenv ] && [ ! -f /etc/zprofile ]; then
__dko_status "Moving /etc/zshenv to /etc/zprofile (sudo)"
sudo mv /etc/zshenv /etc/zprofile
else
__dko_ok "/etc/zshenv not present"
fi
# ============================================================================
# vendor
# ============================================================================
_bootstrap_brew() {
__dko_status "Brewing"
[ -z "$HOMEBREW_PREFIX" ] && . "${DOTFILES}/shell/interactive-darwin.zsh"
# prefer homebrew/cask-fonts
brew untap caskroom/fonts 2>/dev/null
(
cd "${DOTFILES}/mac" || exit 1
GNUPGHOME="${HOME}/.config/gnupg" TERM=xterm256-color \brew bundle
)
}
_bootstrap_brew
__dko_status "Installing fzf shell extensions"
"${DOTFILES}/bin/dot" fzf
# ============================================================================
# use zsh
# the /etc/shells method is for TTY users, Darwin can just read from dscl
# https://rick.cogley.info/post/use-homebrew-zsh-instead-of-the-osx-default/
# ============================================================================
_bootstrap_shell() {
local usershell
local zshpath="${HOMEBREW_PREFIX}/bin/zsh"
[ -x "$zshpath" ] || return 1
grep "$zshpath" /etc/shells || {
__dko_status "Add brewed zsh to /etc/shells (sudo)"
sudo echo "$zshpath" >> /etc/shells
}
grep "$zshpath" /etc/shells || return 1
__dko_status "Set user shell to brewed zsh using chsh"
chsh -s "$zshpath" || return 1
__dko_status "Set user shell to brewed zsh using dscl (sudo)"
usershell="$(dscl . -read "/Users/${USER}" UserShell)"
if [[ "$usershell" != "UserShell: ${zshpath}" ]]; then
__dko_ok "Already using brewed zsh"
else
sudo dscl . -create "/Users/${USER}" UserShell "${zshpath}"
fi
}
_bootstrap_shell || {
__dko_warn "Could not update the user's shell to ${zshpath}"
__dko_warn_ "Check the brew installation and refer to"
__dko_warn_ "https://rick.cogley.info/post/use-homebrew-zsh-instead-of-the-osx-default/"
}
# ============================================================================
__dko_status "Restart your terminal"
# ============================================================================
# sdks
# ============================================================================
# open -Ra 'Xcode' || {
# __dko_err "Missing Xcode, install from App Store"
# exit 1
# }
__dko_require 'xcrun' || {
__dko_err "Missing Xcode Command Line Tools, install via Xcode"
exit 1
}
_bootstrap_sdks() {
local clitools="/Library/Developer/CommandLineTools"
[ -d "$clitools" ] &&
__dko_status "Found CLI tools. If headers are missing, try deleting ${clitools} and redownload with xcode-seelct --install"
# See https://github.com/pyenv/pyenv/issues/1219#issuecomment-428700763
# Xcode Command Line tools no longer installs needed headers in /include
# https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes
local sdk
sdk=$(xcrun --show-sdk-path)
if [ ! -d "$sdk" ]; then
local product_version
product_version="$(sw_vers -productVersion)"
local product_minor
product_minor="${product_version%.*}"
local headers_pkg="${clitools}/Packages/macOS_SDK_headers_for_macOS_${product_minor}.pkg"
if [ ! -f "$headers_pkg" ]; then
__dko_err "Incomplete installation of xcode command line tools detected."
__dko_err_ "Download from https://developer.apple.com/download/more/"
return 1
fi
__dko_status "Installing SDK headers... (sudo)"
sudo installer -allowUntrusted -verbose -pkg "$headers_pkg" -target / || {
__dko_warn "Could not install SDK headers"
}
else
__dko_ok "Found SDK headers"
fi
}
__dko_status "Re-bootstrapping SDKs (required to install python on 10.14+)"
_bootstrap_sdks || exit 1