-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstall.sh
executable file
·220 lines (190 loc) · 5.12 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
#!/usr/bin/env bash
cd "${BASH_SOURCE%/*}" || exit
declare thisdir="$PWD"
declare verbose
declare -a errors
declare -a configs_avail
declare -a configs_chosen
declare -a args
declare process=4
source "./bash_utils"
err() {
errors+=( " $*" )
}
echo_cmd() {
if (( verbose > 0 )); then
echo "$*"
"$@" &>/dev/null
else
"$@" &>/dev/null
fi
}
curl() {
command curl -s "$@"
}
export -f curl
mkd() {
mkdir ${verbose:+-v} -p "$@" || die 'failed to mkdir $*'
}
install_dots() {
local f src dest
for f; do
src=$(realpath "${thisdir}/${f}")
dest="$HOME/.${f}"
if [[ ! -e "$src" ]]; then
err "$src does not exist"
break
fi
if [[ -e "$dest" && ! -L "$dest" ]]; then
echo_cmd mv "$dest" "${dest%/*}/old-${dest##*/}"
fi
mkdir -p "${dest%/*}/"
echo_cmd ln ${verbose:+-v} -s "$src" "$dest"
done
}
library() {
local repo path flags
flags=()
if (( $# < 2 )); then
err 'library() needs repo and path to clone to'
return 1
fi
case "$1" in
http*|https*|git*|ssh*) repo="$1" ;;
*) repo="ssh://[email protected]/danielfgray/$1" ;;
esac
path="$2"
shift 2
flags+=( "$@" )
if [[ -d "$path" ]]; then
if [[ -d "${path}/.git" ]]; then
echo_cmd git -C "$path" pull
else
err "no .git found in ${path}, could not update"
fi
fi
if [[ ! -d "$path" ]]; then
mkd "${path%/*}"
echo_cmd git clone "${flags[@]}" "$repo" "$path"
fi
}
config_base() {
install_dots profile bashrc bash_aliases bash_utils inputrc gitconfig
}
config_scripts() {
library bin ~/.local/bin
library api-helper ~/build/api-helper
library fzf-scripts ~/build/fzf-scripts
library yaxg ~/build/yaxg
mkd ~/.local/bin
find ~/build/{yaxg,fzf-scripts,api-helper} -maxdepth 1 -executable -type f -exec ln ${verbose:+-v} -s -t "$HOME/.local/bin" {} \;
}
has vim && config_vim() {
install_dots vimrc
mkdir ${verbose:+-v} -p ~/.vim/{autoload,bundle,cache,undo,backups,swaps}
curl -fLo ~/.vim/autoload/plug.vim https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
vim +PlugInstall +qa &> /dev/null
}
has nvim && config_neovim() {
if [[ ! -e ~/.config/nvim ]]; then
ln -s ~/.vim ~/.config/nvim
ln -s ~/.vimrc ~/.config/nvim/init.lua
fi
}
has zsh && config_zsh() {
install_dots zsh zshrc zshenv zlogin
}
has fzf || config_fzf() {
library https://github.com/junegunn/fzf.git ~/.fzf
if [[ ! -x ~/.fzf/install ]]; then
err 'failed to install fzf'
return 1
fi
~/.fzf/install --all &> /dev/null
}
has tmux && config_tmux() {
install_dots tmux.conf
library https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
[[ -x ~/.tmux/plugins/tpm/bin/install_plugins ]] && echo_cmd ~/.tmux/plugins/tpm/bin/install_plugins
}
has gem && config_gem() {
install_dots gemrc
}
has X && config_x11() {
has -v startx && install_dots xinitrc
has -v xmodmap && install_dots xmodmap
has -v xrdb && install_dots Xresources
# if has -v fc-cache; then
# [[ -f ~/.local/share/fonts/FantasqueSansMono-Regular.ttf ]] && return 0
# mkdir -p ~/.local/share/fonts
# if [[ ! -f ~/downloads/fantasque-sans-mono.zip ]]; then
# echo_cmd curl -L --create-dirs -o ~/downloads/fantasque-sans-mono.zip \
# 'https://fontlibrary.org/assets/downloads/fantasque-sans-mono/db52617ba875d08cbd8e080ca3d9f756/fantasque-sans-mono.zip'
# fi
# if ! has -v unzip; then
# err 'downloaded Fantasque Sans Mono but unzip is unavailable'
# return 1
# fi
# if [[ -f ~/downloads/fantasque-sans-mono.zip ]]; then
# echo_cmd unzip ~/downloads/fantasque-sans-mono.zip '*.ttf' -d ~/.local/share/fonts
# else
# err 'failed to download font Fantasque Sans Mono'
# fi
# fi
}
has yarn || config_yarn() {
echo_cmd curl -L https://yarnpkg.com/install.sh | bash
~/.yarn/bin/yarn config set init-version 0.0.1
~/.yarn/bin/yarn config set init-author-email [email protected]
~/.yarn/bin/yarn config set init-author-name DanielFGray
~/.yarn/bin/yarn config set init-license GPL-3.0
}
has n || config_n() {
echo_cmd curl -L https://raw.githubusercontent.com/creationix/nvm/master/install.sh | sh
}
config() {
has "config_$1" || {
err ":: FAILED $1: does not exist"
return 1
}
color blue ":: STARTING $1"
if "config_$1"; then
color green ":: FINISHED $1"
else
err ":: FAILED $1"
fi
}
finish() {
tput sgr0
exit
}
trap finish SIGHUP SIGINT SIGTERM
while getopts ":hvp:" opt; do
case "$opt" in
h) usage; exit ;;
v) (( ++verbose )) ;;
p) process="$OPTARG" ;;
esac
done
shift $(( OPTIND - 1 ))
unset opt OPTARG OPTIND OPTERR
mapfile -t configs_avail < <(compgen -A function | awk '/^config_/{ sub(/^config_/, "", $0); print }')
if [[ $1 = '--all' ]]; then
configs_chosen=( "${configs_avail[@]}" )
else
printf 'will install the following groups:\n'
read -r -e -p '> ' -i "${configs_avail[*]}" -a configs_chosen
fi
(( ${#configs_chosen[@]} > 0 )) || die
for f in "${configs_chosen[@]}"; do
(( count++ >= process )) && wait -n
config "$f" &
done
wait
if (( "${#errors[@]}" > 0 )); then
color red 'The following errors occured'
color red "${errors[@]}"
else
color green 'success!'
fi
finish