-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup
More file actions
executable file
·242 lines (210 loc) · 6.01 KB
/
setup
File metadata and controls
executable file
·242 lines (210 loc) · 6.01 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
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/bin/bash
set -e
sudo -v
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
abspath() {
pushd "$1" &> /dev/null
if [[ $? != 0 ]]; then
return 1;
fi
pwd -P
exit_code=$?
popd &> /dev/null
return ${exit_code}
}
print_error() {
local msg=$1
echo "\033[0;31m${msg}\033[0m"
}
print_blue() {
local msg=$1
echo "\033[1;34m${msg}\033[0m"
}
print_green() {
local msg=$1
echo "\033[0;32m${msg}\033[0m"
}
print_log() {
local msg="$1 "
local status=" [$2]"
columns=$(tput cols)
msg_width="${#msg}"
status_width="${#status}"
adjust=$(( (columns - (msg_width + status_width) ) ))
printf "$msg"
printf '%*s' "$adjust" | tr ' ' '.'
printf "$status"
}
log_skip() {
print_log "$1" 'Skip'
}
log_ok() {
print_log "$1" 'OK'
}
# macos
install_xcode_command_line() {
# check xcode commandline is pre-installed
local xcode_installed=$(xcode-select -p 2>/dev/null)
if [ "$xcode_installed" = "" ]; then
xcode-select --install
echo "Try again after install xcode-select"
exit 1
else
log_skip "Xcode command line tool"
fi
}
install_homebrew() {
local brew_installed=$(brew --version 2>/dev/null)
if [[ "$brew_installed" = "" ]]; then
sudo -u "$(logname)" /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
log_ok "Homebrew"
else
log_skip "Homebrew"
fi
}
install_brew_bundle() {
caffeinate -i sudo -u "$(logname)" brew bundle --file "$(pwd)/brew/Brewfile"
log_ok "Install brew bundles"
}
change_shell() {
if [ $SHELL != "/bin/zsh" ]; then
chsh -s /bin/zsh "$(logname)"
log_ok "Change shell"
else
log_skip "Change shell"
fi
}
install_omz() {
if [[ -d "$HOME/.oh-my-zsh" ]]; then
log_skip "Oh My Zsh"
else
sudo -u "$(logname)" RUNZSH=no sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
log_ok "Oh My Zsh"
fi
}
install_zsh_plugins() {
FAST_SYNTAX_HIGHLIGHTING_PATH="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/fast-syntax-highlighting"
AUTO_SUGGESTIONS_PATH="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions"
if [ -d "$FAST_SYNTAX_HIGHLIGHTING_PATH" ]; then
log_skip "Install zsh - fast syntax highlighting"
else
# fast syntax highlighting
sudo -u "$(logname)" git clone https://github.com/zdharma-continuum/fast-syntax-highlighting.git "$FAST_SYNTAX_HIGHLIGHTING_PATH"
log_ok "Install zsh plugin - fast syntax highlighting"
fi
if [ -d "$AUTO_SUGGESTIONS_PATH" ]; then
log_skip "Install zsh - auto suggestions"
else
# auto suggestions
sudo -u "$(logname)" git clone https://github.com/zsh-users/zsh-autosuggestions "$AUTO_SUGGESTIONS_PATH"
log_ok "Install zsh - auto suggestions"
fi
}
copy_dotfiles() {
sudo -u "$(logname)" find . -name ".*" -maxdepth 1 ! -path . ! -name '.DS_Store' ! -name '.git' -exec cp -r "{}" "$HOME/" \;
log_ok "Copy dotfiles"
}
config_zsh() {
chmod g-w,o-w /opt/homebrew/bin/zsh
chmod g-w,o-w /opt/homebrew/share/zsh/site-functions
log_ok "Config zsh"
}
install_vim_plug() {
if ! [ -d ~/.local/share/nvim/site/pack/packer/start/packer.nvim ]; then
sudo -u "$(logname)" git clone --depth 1 https://github.com/wbthomason/packer.nvim ~/.local/share/nvim/site/pack/packer/start/packer.nvim
else
log_skip "install vim plug"
fi
sudo -u "$(logname)" nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync'
}
install_rosetta() {
if ! (arch -arch x86_64 uname -m > /dev/null) ; then
softwareupdate --install-rosetta --agree-to-license
log_ok "rosetta installed"
else
log_skip "rosetta installed"
fi
}
mkdirs() {
if [ ! -d "$HOME/Projects" ]; then
sudo -u "$(logname)" mkdir "$HOME/Projects"
fi
if [ ! -d "$HOME/Projects/go" ]; then
sudo -u "$(logname)" mkdir "$HOME/Projects/go"
fi
log_ok "Set directories"
}
setup_vscode() {
EXTENSIONS=(
Equinusocio.vsc-community-material-theme
Equinusocio.vsc-material-theme
esbenp.prettier-vscode
golang.go
jpoissonnier.vscode-styled-components
ms-azuretools.vscode-docker
ms-python.isort
ms-python.python
ms-python.vscode-pylance
ms-toolsai.jupyter
ms-toolsai.jupyter-keymap
ms-toolsai.jupyter-renderers
ms-toolsai.vscode-jupyter-cell-tags
ms-toolsai.vscode-jupyter-slideshow
ms-vscode.cmake-tools
ms-vscode.cpptools
ms-vscode.cpptools-extension-pack
ms-vscode.cpptools-themes
ms-vscode.makefile-tools
ms-vscode.sublime-keybindings
peterj.proto
PKief.material-icon-theme
tamasfe.even-better-toml
twxs.cmake
)
for EXT in $EXTENSIONS; do
echo "$EXT"
sudo -u "$(logname)" code --install-extension "$EXT" --force
done
sudo -u "$(logname)" cp './vscode/settings.json' "$HOME/Library/Application Support/Code/User/settings.json"
log_ok "Set up vscode"
}
setup_iterm() {
cp ./iterm/com.googlecode.iterm2.plist ~/Library/Preferences
}
run_macos() {
./macos/.macos
}
setup_macos() {
install_xcode_command_line
export PATH="/opt/homebrew/bin:$PATH"
if [[ $(uname) = "Darwin" ]]; then
install_rosetta
install_homebrew
install_brew_bundle
fi
mkdirs
install_omz
install_zsh_plugins
copy_dotfiles
config_zsh
install_vim_plug
if [[ $(uname) = "Darwin" ]]; then
setup_iterm
setup_vscode
run_macos
killall Dock
killall Finder
fi
change_shell
}
setup() {
if [[ $(uname) = "Darwin" ]]; then
setup_macos
elif [[ $(uname) = "Linux" && -f /etc/arch-release ]]; then
echo "not implemented"
else
print_error "This script only support macOS or Arhclinux"
exit 1
fi
}
setup