-
Notifications
You must be signed in to change notification settings - Fork 4
/
install.sh
executable file
·247 lines (202 loc) · 6.09 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/bin/sh
# shellcheck disable=SC1117
# Save current directory {{{1
# From https://github.com/dylanaraps/pure-sh-bible
_agkdot_dirname() {
# Usage: dirname "path"
# If '$1' is empty set 'dir' to '.', else '$1'.
dir=${1:-.}
# Strip all trailing forward-slashes '/' from
# the end of the string.
#
# "${dir##*[!/]}": Remove all non-forward-slashes
# from the start of the string, leaving us with only
# the trailing slashes.
# "${dir%%"${}"}": Remove the result of the above
# substitution (a string of forward slashes) from the
# end of the original string.
dir=${dir%%"${dir##*[!/]}"}
# If the variable *does not* contain any forward slashes
# set its value to '.'.
[ "${dir##*/*}" ] && dir=.
# Remove everything *after* the last forward-slash '/'.
dir=${dir%/*}
# Again, strip all trailing forward-slashes '/' from
# the end of the string (see above).
dir=${dir%%"${dir##*[!/]}"}
# Print the resulting string and if it is empty,
# print '/'.
printf '%s\n' "${dir:-/}"
}
AGKDOT_ORIG_DIR="$PWD"
cd "$(_agkdot_dirname "$0")" || exit
unset -f _agkdot_dirname
# }}}1
# Functions {{{1
###########################################################
# Install configuration files only if the program they
# configure is installed.
#
# Arguments:
# $1 Program
# $2, $3, $4, etc. Configuration files
###########################################################
conditional_install() {
if command -v "$1" > /dev/null 2>&1; then
shift
until [ $# = 0 ]; do
if [ ! -e "${HOME}/$1" ]; then
printf 'Installing %s\n' "$1"
elif [ -n "$(find -L "./$1" -prune -newer "${HOME}/$1" > /dev/null 2>&1)" ]; then
printf 'Upgrading %s\n' "$1"
else
printf 'Replacing %s\n' "$1"
fi
cp "$1" "$HOME"
shift
done
fi
}
###########################################################
# Clone a repo or update it with a pull.
#
# Arguments
# [Optional] Command that must exist for installation to
# take place
# Username/Repository
# [Optional] Branch (if other than master)
###########################################################
github_clone_or_update() {
if ! command -v git > /dev/null 2>&1; then
echo 'Install git.' >&2 && return 1
fi
case $1 in
*/*) ;;
*) command -v "$1" > /dev/null 2>&1 && shift || return ;;
esac
AGKDOT_REPO=$(echo "$1" | awk -F/ '{ printf "%s", $2 }')
echo
printf 'GitHub repository %s:\n' "$1"
if [ ! -d "$AGKDOT_REPO" ]; then
AGKDOT_CUR_DIR="$PWD"
git clone https://github.com/"$1".git || return 1
cd "$AGKDOT_REPO" || return 1
[ -n "$2" ] && git checkout "$2"
cd "$AGKDOT_CUR_DIR" || return 1
else
AGKDOT_CUR_DIR="$PWD"
cd "$AGKDOT_REPO" || return 1
git pull || return 1
[ -n "$2" ] && git checkout "$2"
cd "$AGKDOT_CUR_DIR" || return 1
fi
echo
unset AGKDOT_REPO
}
# }}}1
# Main routine {{{1
[ ! -d prompts ] && mkdir prompts
cd prompts || exit
github_clone_or_update agkozak/polyglot develop
github_clone_or_update kubectl jonmosco/kube-ps1
github_clone_or_update kubectl agkozak/polyglot-kube-ps1
cd .. || exit
if [ -d "${HOME}/dotfiles/plugins/bash-z" ]; then
AGKDOT_CUR_DIR="$PWD"
cd "${HOME}/dotfiles/plugins/bash-z" || exit
git pull
cd "$AGKDOT_CUR_DIR" || exit
unset AGKDOT_CUR_DIR
fi
github_clone_or_update dircolors agkozak/dircolors-zenburn &&
cp dircolors-zenburn/dircolors "$HOME/.dircolors"
conditional_install bash .bash_profile .bashrc .inputrc
conditional_install csh .cshrc
echo '.editorconfig'
cp .editorconfig "$HOME"
if command -v emacs > /dev/null 2>&1; then
if [ ! -d "$HOME/.emacs.d" ]; then
mkdir "$HOME/.emacs.d"
fi
echo Installing ~/.emacs.d/init.el
cp ./.emacs.d/init.el "$HOME/.emacs.d"
fi
conditional_install mysql .editrc
if command -v phpstorm > /dev/null 2>&1 ||
[ -d '/c/Program Files/JetBrains' ] ||
[ -d '/cygdrive/c/Program Files/JetBrains' ] ||
[ -d '/mnt/c/Program Files/JetBrains' ]; then
echo Installing .ideavimrc
cp .ideavimrc "$HOME"
fi
if command -v osh > /dev/null 2>&1; then
echo 'Installing ~/.config/oil/oshrc'
mkdir -p "${HOME}/.config/oil"
cp .config/oil/oshrc "$HOME/.config/oil"
fi
conditional_install screen .screenrc
conditional_install sh .profile .shrc
conditional_install tmux .tmux.conf
if command -v vim > /dev/null 2>&1; then
if [ -e "$HOME/.vimrc" ] && ! cmp ./.vimrc "$HOME/.vimrc" > /dev/null 2>&1; then
conditional_install vim .vimrc .exrc
vim PlugInstall qall
else
conditional_install vim .vimrc .exrc
fi
else
case $(ls -al $(command -v vi)) in
*busybox*) ;;
*) conditional_install vi .exrc ;;
esac
fi
if command -v nvim > /dev/null 2>&1; then
echo 'Linking ~/.config/nvim/init.vim to ~/.vimrc'
if ! command -v vim > /dev/null 2>&1; then
cp .vimrc "$HOME"
fi
if [ ! -d "$HOME/.config/nvim" ]; then
ln -s "$HOME/.vim" "$HOME/.config/nvim"
fi
if [ ! -f "$HOME/.config/nvim/init.vim" ]; then
ln -s "$HOME/.vimrc" "$HOME/.config/nvim/init.vim"
fi
fi
if command -v yash > /dev/null 2>&1; then
[ ! -f "$HOME/.yash_profile" ] &&
echo "Linking ~/.yash_profile to ~/.profile" ] &&
ln -s "$HOME/.profile" "$HOME/.yash_profile"
[ ! -f "$HOME/.yashrc" ] &&
echo "Linking ~/.yashrc to ~/.shrc" &&
ln -s "$HOME/.shrc" "$HOME/.yashrc"
fi
conditional_install zsh .zshenv .zshrc .p10k.zsh
case ${AGKDOT_SYSTEMINFO:=$(uname -a)} in
*BSD*|DragonFly*)
conditional_install sh .login_conf
;;
*raspberrypi*)
echo .config/lxterminal
cp .config/lxterminal/lxterminal.conf "$HOME/.config/lxterminal"
;;
*Msys|*Cygwin)
conditional_install mintty .minttyrc
;;
esac
case ${AGKDOT_SYSTEMINFO:=$(uname -a)} in
*Cygwin)
echo .Xresources
cp .Xresources.cygwin ../.Xresources
;;
esac
# Clean up after some frameworks {{{1
rm -f "$HOME/.zlogin" "$HOME/.zlogin.zwc" "$HOME/.zlogout" "$HOME/zlogout.zwc"
# }}}1
# Clean up outdated files {{{1
[ -f "${HOME}/.zprofile" ] && rm "${HOME}/.zprofile"
[ -f "${HOME}/.zlogin" ] && rm "${HOME}/.zlogin"
# Return to original directory {{{1
cd "$AGKDOT_ORIG_DIR" || exit
unset AGKDOT_ORIG_DIR
# }}}1
# vim: ft=sh:fdm=marker:ts=2:sts=2:sw=2:et