-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·211 lines (191 loc) · 8.1 KB
/
deploy.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
#!/usr/bin/env bash
trap 'exit_code=$?; echo -e "\033[90m[ERR]:\033[35m$BASH_SOURCE:$LINENO:$BASH_COMMAND\033[00m"; exit "$exit_code"' ERR
current_abs_directory_path=$(cd $(dirname $0) && pwd)
cd ${current_abs_directory_path%/}
set -e
DOTPATH=${DOTPATH:-~/dotfiles}
# git submodule
git submodule update -i
# link
dotfiles=(
.cargo/config
.clang-format
.config/git/attributes
.config/git/ignore
.config/litecli/config
.config/peco/config.json
.config/ranger/rc.conf
.config/tilda/style.css
.config/xkeysnail/config.py
.config/gitui/key_config.ron
.config/ecat/config.yaml
.config/espanso/config/default.yml
.config/espanso/match/base.yml
.config/ov/config.yml
.gdbinit
.hammerspoon/init.lua
.inputrc
.myclirc
.omnisharp/omnisharp.json
.replyrc
.screenrc
.textlintrc
.tigrc
.tmux.conf
.tmux.reset.conf
.toprc
.typos.toml
.vimrc
.xbindkeysrc
.zpreztorc
.zprofile
.zshenv
.zshrc
)
for filepath in "${dotfiles[@]}"; do
target_dirpath="$HOME/$(dirname "$filepath")/"
mkdir -p "$target_dirpath"
ln -sf "$DOTPATH/$filepath" "$target_dirpath"
done
[[ ! -d ~/.zsh/ ]] && mkdir -p ~/.zsh
find "$DOTPATH/.zsh" -type f -print0 -name '*.zshrc' | while IFS= read -r -d $'\0' filepath; do
ln -sf "$filepath" ~/.zsh/
done
# cp not ln -f
[[ ! -f ~/.gitconfig ]] && cp "$DOTPATH/.tmpl.gitconfig" ~/.gitconfig
[[ ! -f ~/.local.vimrc ]] && cp "$DOTPATH/.tmpl.local.vimrc" ~/.local.vimrc
[[ ! -d ~/.local.git_template/ ]] && cp -R "$DOTPATH/.local.git_template" ~/
# cp .git_template dirs
find .git_template/hooks -type d -not -name '.*' -print0 | xargs -0 -L 1 -IXXX mkdir -p "$HOME/XXX"
# ln .git_template files
find .git_template/hooks -type f -not -name '.*' -print0 | xargs -0 -L 1 -IXXX ln -sf "$DOTPATH/XXX" "$HOME/XXX"
# -a: enable copy symbolic links
find .git_template/hooks -type l -not -name '.*' -print0 | xargs -0 -L 1 -IXXX cp -a "$DOTPATH/XXX" "$HOME/XXX"
[[ ! -d ~/.vim/ ]] && mkdir -p ~/.vim
# NOTE: windows ln behave like cp (to avoid 'cannot overwrite directory')
if [[ $OS =~ Windows ]]; then
[[ -e ~/.vim/config ]] && rm -rf ~/.vim/config
# TODO: set espanso setting file
fi
ln -fs "$DOTPATH"/.vim/config ~/.vim/
ln -fs "$DOTPATH"/.vim/patch ~/.vim/
# for nvim
mkdir -p ~/.config/nvim/
ln -fs "$DOTPATH"/.vim/runtimepath/after ~/.config/nvim/
# for vim
ln -fs "$DOTPATH"/.vim/runtimepath/after ~/.vim/
[[ -z $XDG_CONFIG_HOME ]] && XDG_CONFIG_HOME=".config"
[[ ! -d "$HOME/$XDG_CONFIG_HOME" ]] && mkdir -p "$HOME/$XDG_CONFIG_HOME"
ln -sf "$DOTPATH"/.config/pep8 "$HOME/$XDG_CONFIG_HOME/pep8"
# NOTE: auto create .config dir
find .config -type d -print0 | xargs -0 -L 1 -IXXX mkdir -p "$HOME/XXX"
ln -sf "$DOTPATH"/.vimrc ~/.config/nvim/init.vim
ln -sf "$DOTPATH"/.config/golfix/*.golfix ~/.config/golfix/
ln -sf "$DOTPATH"/.config/auto_fix/* ~/.config/auto_fix/
ln -sf "$DOTPATH"/.config/autostart/*.desktop ~/.config/autostart/
if [[ $(uname) == "Linux" ]]; then
ln -sf "$DOTPATH"/.config/pip/pip.conf ~/.config/pip/pip.conf
ln -sf "$DOTPATH"/.config/rustfmt/.rustfmt.toml ~/.config/rustfmt/.rustfmt.toml
mkdir -p ~/.config/Code/User/snippets/
ln -sf "$DOTPATH"/.config/Code/User/settings.json ~/.config/Code/User/settings.json
ln -sf "$DOTPATH"/.config/Code/User/keybindings.json ~/.config/Code/User/keybindings.json
ln -sf "$DOTPATH"/.config/Code/User/snippets/* ~/.config/Code/User/snippets/
# mkdir -p "$HOME/.config/Code - Insiders/User/snippets"
# ln -sf "$DOTPATH"/.config/Code/User/settings.json "$HOME/.config/Code - Insiders/User/settings.json"
# ln -sf "$DOTPATH"/.config/Code/User/keybindings.json "$HOME/.config/Code - Insiders/User/keybindings.json"
# ln -sf "$DOTPATH"/.config/Code/User/snippets/* "$HOME/.config/Code - Insiders/User/snippets/"
fi
if [[ $(uname) == "Darwin" ]]; then
# FYI: [User Guide — pip 19\.0\.1 documentation]( https://pip.pypa.io/en/stable/user_guide/#configuration )
mkdir -p "$HOME/Library/Application Support/pip/"
ln -sf "$DOTPATH"/.config/pip/pip.conf "$HOME/Library/Application Support/pip/pip.conf"
mkdir -p "$HOME/Library/Preferences/rustfmt/"
ln -sf "$DOTPATH"/.config/rustfmt/.rustfmt.toml "$HOME/Library/Preferences/rustfmt/.rustfmt.toml"
mkdir -p "$HOME/Library/Application Support/gitui/"
ln -sf "$DOTPATH"/.config/gitui/key_config.ron "$HOME/Library/Application Support/gitui/key_config.ron"
mkdir -p "$HOME/Library/Application Support/Code/User/snippets/"
ln -sf "$DOTPATH"/.config/Code/User/settings.json "$HOME/Library/Application Support/Code/User/settings.json"
ln -sf "$DOTPATH"/.config/Code/User/keybindings.json "$HOME/Library/Application Support/Code/User/keybindings.json"
ln -sf "$DOTPATH"/.config/Code/User/snippets/* "$HOME/Library/Application Support/Code/User/snippets/"
# mkdir -p "$HOME/Library/Application Support/Code - Insiders/User/snippets/"
# ln -sf "$DOTPATH"/.config/Code/User/settings.json "$HOME/Library/Application Support/Code - Insiders/User/settings.json"
# ln -sf "$DOTPATH"/.config/Code/User/keybindings.json "$HOME/Library/Application Support/Code - Insiders/User/keybindings.json"
# ln -sf "$DOTPATH"/.config/Code/User/snippets/* "$HOME/Library/Application Support/Code - Insiders/User/snippets/"
# if [[ -d ~/.vscode-insiders/extensions ]] && [[ ! -L ~/.vscode-insiders/extensions ]]; then
# echo 1>&2 $'\e[93m'"[!] ~/.vscode-insiders/extensions is not symbolic link"$'\e[m'
# echo 1>&2 $'\e[93m'"I recommend that you run the following commands."$'\e[m'
# echo 1>&2 $'\e[93m'"rm -rf ~/.vscode-insiders/extensions"$'\e[m'
# echo 1>&2 $'\e[93m'"ln -s ~/.vscode/extensions ~/.vscode-insiders/extensions"$'\e[m'
# fi
fi
# below config setting is not official location
mkdir -p ~/.config/clangd/
eval "cat <<EOF
$(<"$DOTPATH"/.config/clangd/compile_flags.txt.bash.tmpl)
EOF
" >~/.config/clangd/compile_flags.txt
if [[ -f ~/.local.compile_flags.txt ]]; then
eval "cat <<EOF
$(<~/.local.compile_flags.txt)
EOF
" >>~/.config/clangd/compile_flags.txt
fi
# NOTE: backup original setting file if exists
function safe_ln() {
[[ $# -lt 2 ]] && echo "$(basename "$0") source_file target_file" && return 1
local source_file=$1
local target_file=$2
# NOTE: backup
[[ -f "$target_file" ]] && [[ ! -L "$target_file" ]] && mv "$target_file" "${target_file}~"
# NOTE: target_file -> source_file
ln -sf "$source_file" "$target_file"
}
safe_ln "$DOTPATH"/.config/alacritty/alacritty.yml ~/.config/alacritty/alacritty.yml
safe_ln "$DOTPATH"/.minimal.bashrc ~/.config/oressh/default/.bashrc
safe_ln "$DOTPATH"/.minimal.vimrc ~/.config/oressh/default/.vimrc
safe_ln "$DOTPATH"/.inputrc ~/.config/oressh/default/.inputrc
if [[ -d ~/.config/karabiner/assets/complex_modifications ]]; then
ls "$DOTPATH"/.config/karabiner/assets/complex_modifications/*.json | while read -r filepath || [ -n "${filepath}" ]; do
filename=${filepath##*/}
karabiner_name=${filename#*.}
ln -sf $filepath ~/.config/karabiner/assets/complex_modifications/$karabiner_name
done
fi
# tmux
if type >/dev/null 2>&1 tmux; then
if tmux info >/dev/null 2>&1; then
# install manager
[[ ! -d ~/.tmux/plugins/tpm ]] && git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
tmux source-file ~/.tmux.conf
output=$(~/.tmux/plugins/tpm/scripts/install_plugins.sh 2>&1) || {
echo $'\e[91m'"[✗] tmux plugin install failed."$'\e[m'
echo "$output"
exit 1
}
output=$(~/.tmux/plugins/tpm/scripts/update_plugin.sh all 2>&1) || {
echo $'\e[91m'"[✗] tmux plugin update failed."$'\e[m'
echo "$output"
exit 1
}
else
echo $'\e[93m'"[-] tmux server is not running."$'\e[m'
fi
else
echo $'\e[91m'"[✗] tmux command not found."$'\e[m'
exit 1
fi
mkdir -p ~/local/src/
if [[ $(uname) == "Linux" ]]; then
# only Ubuntu16.04
if cat /etc/os-release | grep -q '^VERSION_ID="16.04"$'; then
if [[ ! -d ~/local/src/glibc-2.23 ]]; then
wget https://ftp.gnu.org/gnu/glibc/glibc-2.23.tar.gz -O - | tar zxvf - -C ~/local/src/
fi
fi
if cat /etc/os-release | grep -q '^VERSION_ID="18.04"$'; then
if [[ ! -d ~/local/src/glibc-2.27 ]]; then
wget https://ftp.gnu.org/gnu/glibc/glibc-2.27.tar.gz -O - | tar zxvf - -C ~/local/src/
fi
fi
fi
echo $'\e[92m'"[✔] Succeeded."$'\e[m'