-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.zsh
executable file
·180 lines (137 loc) · 3.85 KB
/
configure.zsh
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
#!/usr/bin/env zsh
set -euo pipefail
bail_if_email_not_set() {
if [[ -z $EMAIL ]]; then
echo 'Please set $EMAIL to your email address and try again.'
exit 1
fi
}
bail_if_op_env_vars_not_set() {
if [[ -z $OP_SECRET_KEY ]]; then
echo 'Please set $OP_SECRET_KEY and try again.'
echo 'The secret key is 40 uppercase alphanumeric characters and hyphens.'
exit 1
fi
if [[ -z $OP_MASTER_PASSWORD ]]; then
echo 'Please set $OP_MASTER_PASSWORD and try again.'
exit 1
fi
}
update_macos() {
# Install MacOS software updates
softwareupdate -iar
# Install command line tools
if ! command -v clang; then
xcode-select --install
fi
}
install_brew_pkgs() {
# Install brew
if ! command -v brew; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
else
brew update
fi
brew bundle install --no-lock
}
enable_docker_completions() {
ln -sf /Applications/Docker.app/Contents/Resources/etc/docker.zsh-completion /opt/homebrew/share/zsh/site-functions/_docker
}
log_in_to_1password() {
if ! op whoami &>/dev/null; then
if ! eval $(echo $OP_MASTER_PASSWORD | op account add --address=boehning.1password.com --email=$EMAIL --secret-key=$OP_SECRET_KEY --signin); then
echo 'Invalid $OP_MASTER_PASSWORD or $OP_SECRET_KEY'
exit 1
fi
fi
}
github_cli_login() {
if ! gh auth status; then
local GITHUB_PAT=$(op read op://Private/GitHub/commandline/personalaccesstoken)
echo $GITHUB_PAT | gh auth login --git-protocol=https --with-token
fi
}
# create_ssh_key_if_necessary() {
# # Create this directory so multiple SSH sessions can share a single
# # connection.
# mkdir -p ~/.ssh/sockets
# op signin
# # TODO: creating an SSH key using op currently isn't possible
# MACBOOK_MODEL="$(sysctl -n hw.model)"
# op item create --category=sshkey --title="$MACBOOK_MODEL SSH Key" --generate-password=20,letters,digits 'Key Type=ed25519'
# }
fetch_dotfiles() {
# Clone all the dotfiles
rm -rf /tmp/dotfiles
git clone --depth 1 https://github.com/ryboe/dotfiles.git /tmp
# Fetch configs from ryboe/dotfiles
if [[ ! -d ~/.config ]]; then
cp -R /tmp/.config "$HOME"
fi
if [[ ! -f ~/.config/git/config ]]; then
cp /tmp/.config/git/config ~/.config/git/config
fi
if [[ ! -f ~/.config/git/ignore ]]; then
cp /tmp/.config/git/ignore ~/.config/git/ignore
fi
if [[ ! -f ~/.ssh/config ]]; then
cp /tmp/.ssh/config ~/.ssh/config
fi
if [[ ! -f ~/.CFUserTextEncoding ]]; then
cp /tmp/.CFUserTextEncoding ~/.CFUserTextEncoding
fi
}
install_rust() {
if ! command -v rustup; then
rustup-init
rustup toolchain install stable
else
rustup update
fi
}
reduce_permissions_on_zsh_dirs() {
# Avoid warning from compaudit
chmod go-w /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions
}
load_zsh_shell_config() {
# Load shell config
cp /tmp/.zshrc ~/.zshrc
source ~/.zshrc
}
make_code_dir() {
mkdir -p ~/code
}
set_screenshots_to_jpg() {
# Save screenshots in ~/Downloads instead of ~/Desktop
defaults write com.apple.screencapture location "$HOME/Screenshots"
# JPEG screenshots
if defaults read com.apple.screencapture type != "jpeg"; then
defaults write com.apple.screencapture type jpeg
killall SystemUIServer
fi
}
download_chrome_installer() {
# There is no brew cask for Chrome.
curl -ssL --retry 3 --max-time 180 --progress -O https://dl.google.com/chrome/mac/universal/stable/GGRO/googlechrome.dmg
}
main() {
bail_if_email_not_set
bail_if_op_env_vars_not_set
update_macos
install_brew_pkgs
enable_docker_completions
log_in_to_1password
# TODO: enable this when SSH keys can be created through the 1password CLI
# create_ssh_key_if_necessary
github_cli_login
fetch_dotfiles
add_seedbox_to_ssh_config
install_rust
make_code_dir
reduce_permissions_on_zsh_dirs
install_gitprompt
load_zsh_shell_config
download_chrome_installer
download_bypass_paywalls_chrome
}
main