-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·222 lines (201 loc) · 6.85 KB
/
install.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
#!/usr/bin/env bash
# Configure installed applications
# Author: Dario Blanco (dblancoit@gmail.com)
set -o errexit
set -o nounset
set -o pipefail
# shellcheck source=utils.sh
source utils.sh
cwd=$(pwd)
trap exit_gracefully INT
function install_xcode_clt() {
if xcode-select -p > /dev/null; then
print_yellow "XCode Command Line Tools already installed"
else
print_blue "Installing XCode Command Line Tools..."
xcode-select --install
print_green "XCode installed successfully"
fi
}
function install_homebrew() {
export HOMEBREW_CASK_OPTS="--appdir=/Applications"
if hash brew &>/dev/null; then
print_yellow "Homebrew already installed. Getting updates and package upgrades..."
brew update
brew upgrade
else
print_blue "Installing homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
(echo; echo "eval \"$(/opt/homebrew/bin/brew shellenv)\"") >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
brew update
print_green "Homebrew installed successfully"
fi
brew bundle install --no-lock --file="${cwd}/Brewfile"
print_green "Homebrew apps installed successfully"
}
function install_python() {
if hash python &>/dev/null; then
print_yellow "Default Python binary already configured."
else
print_blue "Configuring Python binary from Python3 (requires sudo)..."
# Symlink python to python3 so poetry can get the proper binary
sudo ln -s /opt/homebrew/bin/python3 /opt/homebrew/bin/python
print_green "Python binary configured successfully"
fi
}
function install_rust() {
export PATH="$HOME/.cargo/bin:$PATH"
if hash rustup &>/dev/null; then
print_yellow "Rust already installed"
else
print_blue "Installing Rust..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
print_green "Rust installed successfully"
fi
print_blue "Checking for Rust updates..."
rustup -q update
print_blue "Installing essential Rust components..."
rustup component add clippy rustfmt
print_green "Rust components installed successfully"
}
function configure_docker() {
colima start --runtime docker
mkdir -p ~/.docker/cli-plugins
ln -sfn /opt/homebrew/opt/docker-buildx/bin/docker-buildx ~/.docker/cli-plugins/docker-buildx
}
function configure_zsh() {
if [[ ! -f ~/.zshrc ]]; then
print_blue "Configuring zsh + and configure oh-my-zsh and its bundles via antigen..."
cp files/.zshrc ~/.zshrc
cp files/.antigenrc ~/.antigenrc
chsh -s /bin/zsh
else
print_yellow "zsh + antigen + oh my zsh already installed"
fi
}
function configure_iterm() {
read -r -p "👉 Do you want to configure iTerm? [y/n]: " configure_iterm
if [[ $configure_iterm =~ ^[yY] ]]; then
if [[ ! -f ~/Library/Application\ Support/iTerm2/DynamicProfiles/iTermProfiles.json ]]; then
print_blue "Copying iTerm2 profiles..."
mkdir -p ~/Library/Application\ Support/iTerm2/DynamicProfiles/
cp files/iTermProfiles.json ~/Library/Application\ Support/iTerm2/DynamicProfiles/
else
print_yellow "iTerm2 custom profile is already installed"
fi
else
print_yellow "iTerm configuration skipped"
fi
}
function configure_vscode() {
read -r -p "👉 Do you want to configure VSCode? [y/n]: " configure_vscode
if [[ $configure_vscode =~ ^[yY] ]]; then
if hash code &>/dev/null; then
print_blue "Installing Visual Studio Code extensions..."
while IFS="" read -r i || [ -n "$i" ]
do
if code --list-extensions | grep "$i" > /dev/null; then
print_yellow "Extension $i is already installed"
else
code --install-extension "$i"
fi
done < "${cwd}/vscode-extensions.txt"
fi
if [[ ! -f ~/Library/Application\ Support/Code/User/settings.json ]]; then
print_blue "Creating Visual Studio Code user settings..."
cp files/CodeSettings.json ~/Library/Application\ Support/Code/User/settings.json
else
print_yellow "Visual Studio Code user settings are already defined"
fi
else
print_yellow "VSCode configuration skipped"
fi
}
function configure_macos_defaults() {
read -r -p "👉 Do you want to configure MacOS defaults? [y/n]: " configure_macos
if [[ $configure_macos =~ ^[yY] ]]; then
print_blue "Configuring MacOS settings (requires a logout/restart to be reflected)..."
# Show hidden files inside the finder
defaults write com.apple.Finder "AppleShowAllFiles" -bool true
# Show all file extensions inside the finder
defaults write NSGlobalDomain "AppleShowAllExtensions" -bool true
# Do not show warning when changing the file extension
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
# Show path bar
defaults write com.apple.finder ShowPathbar -bool true
# Have the Dock show only active apps
defaults write com.apple.dock static-only -bool true
# Tap to click
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true
defaults write com.apple.AppleMultitouchTrackpad Clicking -bool true
# Drag without drag lock (tap and a half to drag)
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Dragging -int 1
defaults write com.apple.AppleMultitouchTrackpad Dragging -int 1
# Three finger drag
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadThreeFingerDrag -bool true
defaults write com.apple.AppleMultitouchTrackpad TrackpadThreeFingerDrag -bool true
# Secondary click in external mouse
defaults write com.apple.AppleMultitouchMouse MouseButtonMode -string "TwoButton"
print_green "MacOS settings configured successfully"
else
print_yellow "MacOS settings configuration skipped"
fi
}
function configure_ssh() {
if [[ ! -d ~/.ssh ]]; then
print_blue "Defining SSH folder structure..."
mkdir ~/.ssh
cp files/sshconfig ~/.ssh/config
chmod 700 ~/.ssh
chmod 644 ~/.ssh/config
touch ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
ssh-keygen -t ed25519 -f ~/.ssh/id_rsa -C "$(whoami)@$(hostname)"
ssh-add --apple-use-keychain ~/.ssh/id_rsa
eval "$(ssh-agent -s)"
else
print_yellow "SSH folder structure already defined"
fi
}
function configure_vim() {
if [[ ! -f ~/.vimrc ]]; then
print_blue "Applying vimrc configuration..."
cp files/.vimrc ~/.vimrc
else
print_yellow "Vimrc configuration already applied"
fi
}
function configure_git() {
if [[ ! -f ~/.gitconfig ]]; then
print_blue "Applying Git configuration..."
cp files/.gitconfig ~/.gitconfig
else
print_yellow "Git configuration already applied"
fi
}
function main() {
echo ""
echo "🚀 MacOS Config - Darío Blanco Iturriaga"
echo ""
echo " To stop the script at any time press Ctrl+C"
echo " 👉 Press Enter to start!"
echo ""
read -r _
install_xcode_clt
install_homebrew
install_python
install_rust
configure_zsh
configure_ssh
configure_vim
configure_git
configure_docker
configure_iterm
configure_vscode
configure_macos_defaults
echo ""
echo "Success! 🥳🥳🥳🥳🥳"
echo "🏁 Restart your terminal to reload your updated shell profile (or just type 'zsh')"
}
main