-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.sh
executable file
·208 lines (177 loc) · 5.91 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
#!/usr/bin/env bash
name=${0##*/}
function print_help() {
echo "usage: $name [options]
optional args:
-p|--pretend print what install will do without doing it.
-t|--tools install useful tools. Use --help-tools to see list.
--help-tools list tools that will be installed.
-h|--help print this help."
}
function print_help_tools() {
echo "Tools:
rmv: Ruby Version Manager https://rvm.io/
nvm: Node Version Manager https://github.com/creationix/nvm
Go based tools:
direnv: Unclutter your .profile https://direnv.net/
gitin: Commmit/branch/workdir explorer for git https://github.com/isacikgoz/gitin
gocomplete: Bash completion for go https://github.com/posener/complete/gocomplete
gotop: A terminal based graphical activity monitor https://github.com/cjbassi/gotop
hclfmt: Format hcl files https://github.com/fatih/hclfmt
hub: Github wrapper for git https://hub.github.com/
wuzz: Interactive cli tool for HTTP inspection https://github.com/asciimoo/wuzz
"
}
pretend=0
tools=0
go_tools="github.com/github/hub github.com/asciimoo/wuzz github.com/fatih/hclfmt github.com/schachmat/wego github.com/posener/complete/gocomplete github.com/isacikgoz/gitin github.com/cjbassi/gotop github.com/direnv/direnv github.com/tmessi/wallpaper/wp"
OPTS=$(getopt -o pht --long pretend,tools,help-tools,help -n "$name" -- "$@")
if [[ $? != 0 ]]; then echo "option error" >&2; exit 1; fi
eval set -- "$OPTS"
while true; do
case "$1" in
-p|--pretend)
pretend=1
shift;;
-t|--tools)
tools=1
shift;;
--help-tools)
print_help_tools
exit 0
;;
-h|--help)
print_help
exit 0
;;
--)
shift; break;;
*)
echo "Internal error!"; exit 1;;
esac
done
pushd $(dirname $0) &> /dev/null
for dot in $(ls); do
if [[ ! $dot == "README.rst" ]] && [[ ! $dot == "install.sh" ]] && [[ ! $dot == "terminfo" ]] && [[ ! $dot == "non-gentoo" ]]; then
target="$HOME/.$dot"
if [[ $pretend -eq 1 ]]; then
echo "Would set $dot"
else
# Make a .bak of a file or dir
if [[ ! -h $target ]]; then
if [[ -d $target ]] || [[ -f $target ]]; then
mv $target $target.bak
fi
fi
echo "Setting $dot"
ln -sf "$PWD/$dot" "$target"
fi
fi
done
# Do non-gentoo stuff if not on gentoo
if [[ ! $(which lsb_release) ]] || [[ "$(lsb_release -si)" != "Gentoo" ]]; then
for dot in $(ls "non-gentoo"); do
target="$HOME/.$dot"
if [[ $pretend -eq 1 ]]; then
echo "Would set $dot"
else
# Make a .bak of a file or dir
if [[ ! -h $target ]]; then
if [[ -d $target ]] || [[ -f $target ]]; then
mv $target $target.bak
fi
fi
echo "Setting $dot"
ln -sf "$PWD/non-gentoo/$dot" "$target"
fi
done
fi
# Terminfo if needed
if [[ -f /usr/share/terminfo/r/rxvt-unicode ]] && [[ -f /usr/share/terminfo/r/rxvt-unicode-256color ]]; then
# No need for local terminfo, lets use the system one
if [[ -d "$HOME/.terminfo" ]]; then
if [[ $pretend -eq 1 ]]; then
echo "Would remove $HOME/.terminfo"
else
echo "Remove $HOME/.terminfo"
rm -rf "$HOME/.terminfo"
fi
fi
else
dot="terminfo"
target="$HOME/.$dot"
if [[ $pretend -eq 1 ]]; then
echo "Would set $dot"
else
# Make a .bak of a file or dir
if [[ ! -h $target ]]; then
if [[ -d $target ]] || [[ -f $target ]]; then
mv $target $target.bak
fi
fi
echo "Setting $dot"
ln -sf "$PWD/$dot" "$target"
fi
fi
# Cleanup
rm -rf "$HOME/.dzen/dzen"
rm -rf "$HOME/.terminfo/terminfo"
if [[ ! -d "$HOME/.bash-git-prompt" ]]; then
if [[ $pretend -eq 1 ]]; then
echo "Would install bash-git-prompt"
else
git clone https://github.com/magicmonty/bash-git-prompt.git "$HOME/.bash-git-prompt"
fi
fi
if [[ $pretend -eq 1 ]]; then
echo "Would make dirs '$HOME/.vim/{swap,backup,undo}"
else
mkdir -p "$HOME/.vim/"{swap,backup,undo}
fi
if [[ $tools -eq 1 ]]; then
curl_bin=$(which curl)
if [[ -n "${curl_bin}" ]]; then
if [[ $pretend -eq 1 ]]; then
echo "Would install rvm"
echo "Would install gcloud"
else
echo "Installing rvm"
${curl_bin} -sSL https://get.rvm.io | bash -s -- stable --ruby --ignore-dotfiles
echo "Installing gcloud"
${curl_bin} -sSL https://sdk.cloud.google.com | bash -s -- --disable-prompts --install-dir="$HOME/.gc"
fi
else
echo "Skipping rmv, gcloud install, curl not found"
fi
if [[ $pretend -eq 1 ]]; then
echo "Would install nvm"
else
echo "Installing nvm"
[[ -d ~/.nvm/.git ]] || git clone https://github.com/creationix/nvm.git ~/.nvm
pushd ~/.nvm &> /dev/null
git checkout `git describe --abbrev=0 --tags`
popd &> /dev/null
fi
go_bin=$(which go)
if [[ -n "${go_bin}" ]]; then
for tool in $go_tools; do
if [[ $pretend -eq 1 ]]; then
echo "Would install $tool"
else
echo "Installing $tool"
go install $tool@latest
fi
done
else
echo "Skipping go based tool installs, go not found"
fi
fi
if [[ $pretend -eq 1 ]]; then
echo "Would remove the following broken links"
find $HOME -xtype l
else
find $HOME -xtype l -delete
fi
# Cleanup oold bundle dir now that vim-plug is being used
[[ -d ~/.vim/bundle ]] && rm -rf ~/.vim/bundle
popd &> /dev/null