-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·281 lines (247 loc) · 7.4 KB
/
setup.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/bin/bash
# this script should be run to set up the directory structure
# right after cloning the repo, run with 'sudo -u <username> ./setup.sh'
# default BINDIR. can be set with -b
BINDIR="$HOME/bin"
PATHADD=1
# default config dir. can be set with -c
CONFDIR=$HOME
# `readlink` command
READLINK="$(which readlink)"
# get operating system; only useful for Mac or Arch; not reliable for Ubuntu/Fedora/Debian
uname_v="$(uname -v)"
if [[ -f "$HOME/.local/shared/common.sh" ]]; then
. "$HOME/.local/shared/common.sh"
elif [[ -f "shared/common.sh" ]]; then
. "shared/common.sh"
else
printf "%s\n" "common functions not found. exiting." 1>&2
exit 1
fi
path_check() {
if [[ ! ":$PATH:" == *":$BINDIR:"* ]]; then
printf "%s\n" "adding $BINDIR to PATH..."
printf "export PATH=$PATH:$BINDIR\n" >> ~/.profile
PATHADD=0
else
printf "%s\n" "$BINDIR already exists in PATH"
fi
}
install_vim_pacs() {
apt install libncurses5-dev libgnome2-dev libgnomeui-dev libgtk2.0-dev libatk1.0-dev libbonoboui2-dev libcairo2-dev libx11-dev libxpm-dev libxt-dev python-dev ruby-dev liblua5.1-dev lua5.1 libperl-dev
}
install_vim_final() {
cd $HOME/vim
./configure --with-features=huge --enable-multibyte --enable-rubyinterp=yes --enable-pythoninterp=yes --with-python-config-dir=/usr/lib/python2.7/config-x86_64-linux-gnu --enable-perlinterp=yes --enable-luainterp=yes --enable-gui=gtk2 --enable-cscope --enable-terminal --prefix=/usr
make VIMRUNTIMEDIR=/usr/share/vim/vim81
make install
make_editor
}
make_editor() {
update-alternatives --install /usr/bin/editor editor /usr/bin/vim 1
update-alternatives --set editor /usr/bin/vim
update-alternatives --install /usr/bin/vi vi /usr/bin/vim 1
update-alternatives --set vi /usr/bin/vim
}
install_vim() {
while true; do
read -p "install vim? [Y/n] " yn
case $yn in
[Yy])
grep -q 'Ubuntu' <<< "$uname_v"
if [[ $? -eq 0 ]]; then
install_vim_pacs
git clone https://github.com/vim/vim.git $HOME/vim
install_vim_final
apt install python3-pip
elif grep -q 'Arch' <<< "$uname_v"; then
pacman -S vim
elif [[ -f /etc/system-release ]]; then
dnf update && dnf upgrade && dnf install vim
fi
break
;;
[Nn])
printf "%s\n" "not installing vim"
break
;;
*)
printf "%s\n" "Please enter [Yy] or [Nn]"
;;
esac
done
}
install_scripts() {
mkdir -p $BINDIR
if grep -q "Arch" <<< "$uname_v"; then
if ! hash yaourt 2>/dev/null; then
printf "Installing yaourt...\n"
pacman -S --needed base-devel git wget yajl
cd $HOME
git clone https://aur.archlinux.org/package-query.git
cd package-query/
makepkg -si
cd ..
git clone https://aur.archlinux.org/yaourt.git
cd yaourt/
makepkg -si
cd ../ && rm -rf yaourt/ package-query/
fi
fi
if ! hash wal 2>/dev/null; then
if grep -q "Arch" <<< "$uname_v"; then
yaourt -S python-pywal-git
else
pip3 install pywal
fi
fi
printf "%s\n" "installing scripts..."
cp scripts/* $BINDIR
if [[ $PATHADD -eq 0 ]]; then
export PATH=$PATH:$BINDIR
source ~/.profile
fi
}
install_configs() {
printf "%s\n" "linking configs..."
cd $HOME/dotfiles
ln -fs "$($READLINK -f .vim)" "$CONFDIR/.vim"
mkdir -p $CONFDIR/.config
#ln -fs "$($READLINK -f cava)" "$CONFDIR/.config/cava"
#ln -fs "$($READLINK -f config/i3)" "$CONFDIR/.config/i3"
#ln -fs "$($READLINK -f config/polybar)" "$CONFDIR/.config/polybar"
#ln -fs "$($READLINK -f config/lemonbar)" "$CONFDIR/.config/lemonbar"
# ln -fs "$($READLINK -f .bash_aliases)" "$CONFDIR/.bash_aliases"
# ln -fs "$($READLINK -f .bashrc)" "$CONFDIR/.bashrc"
# ln -fs "$($READLINK -f .profile)" "$CONFDIR/.profile"
ln -fs "$($READLINK -f .tmux.conf)" "$CONFDIR/.tmux.conf"
#ln -fs "$($READLINK -f .xinitrc)" "$CONFDIR/.xinitrc"
#ln -fs "$($READLINK -f .Xresources)" "$CONFDIR/.Xresources"
#cp -f "$($READLINK -f .muttrc)" "$CONFDIR/.muttrc"
# ln -fs "$($READLINK -f .zshrc)" "$CONFDIR/.zshrc"
# have to do something different for alacritty
mkdir -p "$CONFDIR/.config/alacritty"
if grep -q "Darwin" <<< "$uname_v"; then
ln -fs "$($READLINK -f config/alacritty/alacritty-mac.yml)" "$CONFDIR/.config/alacritty/alacritty.yml"
else
ln -fs "$($READLINK -f config/alacritty/alacritty.yml)" "$CONFDIR/.config/alacritty/alacritty.yml"
fi
vim +PlugClean +qall
vim +PlugInstall +qall
}
install_fzf() {
git clone --depth 1 git@github.com:junegunn/fzf ~/.fzf
~/.fzf/install
}
install_fd() {
if grep -q "Darwin" <<< "$uname_v"; then
brew install fd
elif grep -q "Arch" <<< "$uname_v"; then
pacman -S fd
elif hash apt 2>/dev/null; then
# latest version as of 3/10/2020
# unfortunately it's only in the repos as of 19.10
wget https://github.com/sharkdp/fd/releases/download/v7.4.0/fd_7.4.0_amd64.deb
sudo dpkg -i fd_7.4.0_amd64.deb
rm fd_7.4.0_amd64.deb
elif hash dnf 2>/dev/null; then
dnf install fd-find
fi
}
install_neofetch() {
if grep -q "Arch" <<< "$uname_v"; then
yaourt -S neofetch-git
elif hash apt 2>/dev/null; then
sudo apt install neofetch
elif hash dnf 2>/dev/null; then
dnf copr enable konimex/neofetch
dnf install neofetch
elif grep -q "Darwin" <<< "$uname_v"; then
brew install neofetch
fi
}
install_ag() {
if grep -q "Arch" <<< "$uname_v"; then
pacman -S the_silver_searcher
elif hash apt 2>/dev/null; then
sudo apt install silversearcher-ag
elif hash dnf 2>/dev/null; then
dnf install the_silver_searcher
elif grep -q "Darwin" <<< "$uname_v"; then
brew install the_silver_searcher
fi
}
install_brew() {
if ! hash brew 2> /dev/null ; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
fi
brew install coreutils
READLINK="$(which greadlink)"
}
usage() {
printf "%s\n" "Usage: ./setup.sh [OPTIONS]"
printf "%s\n" "Examples: ./setup.sh -b $HOME/bin"
printf "%s\n" " ./setup.sh"
printf "%s\n" "Options:"
printf "%s\n" "-b /path/to/bin Install dir. Default is $HOME/bin."
printf "%s\n" "-c /config/dir Directory for configs. Default is $HOME."
printf "%s\n" "-h Print this help."
printf "%s\n" "NOTE: This script may need to be run with 'sudo' if"
printf "%s\n" "you are not root."
}
get_args() {
bin_set=0
conf_set=0
while getopts ":c:b:h" opt; do
case $opt in
b)
if [[ $bin_set -eq 0 ]]; then
bin_set=1
BINDIR=$OPTARG
printf "%s\n" "install location: $OPTARG"
else
error_trig "'-b' provided too many times. Run with '-h' for help"
fi
;;
c)
if [[ $conf_set -eq 0 ]]; then
conf_set=1
CONFDIR=$OPTARG
printf "%s\n" "config location: $OPTARG"
else
error_trig "'-c' provided too many times. Run with '-h' for help"
fi
;;
h)
usage
exit 0
;;
\?)
error_trig "Invalid option: $OPTARG. Run with '-h' for help"
;;
:)
error_trig "$OPTARG must be run with a directory name. Run with '-h' for help"
;;
esac
done
}
main() {
#error_trig "uncomment the functions that should be run for this machine"
get_args "$@"
path_check
# uncomment everything that should be done with this script
# if on a mac, need to install some utilities that don't come default
if grep -q "Darwin" <<< "$uname_v"; then
install_brew
fi
#install_scripts
#install_vim
#install_vim_final
install_configs
# install_ag
# install_fzf
# install_neofetch
# install_fd
printf "done.\n"
}
main "$@"