-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall
executable file
·256 lines (196 loc) · 5.74 KB
/
install
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
#!/bin/bash
# Major changes:
# Git
# The script does no longer help with installing git, since this might be
# different accross systems. Moreover, most of our (Jack + Joe) base
# systems all have git installed, so this is no longer an option.
# If you do not have git installed, the script will abort with exit status 1
#
# Not interactive
# All interactive commands have been replaced with arguments, making it
# easier to integrate with automation. Also the script does not provide
# the change to zsh anymore.
SCRIPT=`basename ${BASH_SOURCE[0]}`
# Colors
COL_GREEN="\x1b[32;01m"
COL_BLUE="\x1b[34;01m"
COL_RESET="\x1b[39;49;00m"
COL_RED="\x1b[31;01m"
COL_YELLOW="\x1b[33;01m"
COL_GRAY="\x1b[0;37m"
# Temp dir for installs
temp_dir='/tmp/termieter/src'
mkdir -p $temp_dir
function _usage {
cat <<EOF
$*
Usage: ./install [options]
Options:
-h --help Show this message
-u, --update Update local setup (no cloning, no removing)
-d, --directory Install directory [~/.termieter]
Remote usage:
bash <( curl -s https://raw.github.com/pierot/termieter/master/install.sh ) [-d '.termieter']
EOF
exit 0
}
# Print helpers
_print_h1() {
printf $COL_GREEN"\n🤴 $1\n"$COL_RESET
}
_print_info() {
printf $COL_YELLOW"× $1\n"$COL_RESET
}
_print() {
printf $COL_BLUE"$1\n"$COL_RESET
}
_error() {
_print $COL_RED"Error:\n\t$1\n"
}
_contains_element() {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
# variables
install_dir="$HOME/.termieter"
update=0
# parse opts
OPTSPEC="d:h-:u"
while getopts "$OPTSPEC" FLAG; do
case $FLAG in
-)
case "$OPTARG" in
directory) install_dir=$OPTARG;;
update) skip_clone=1
esac;;
d)
install_dir=$OPTARG
;;
h)
_usage
;;
u)
update=1
;;
\?) #unrecognized option - show help
printf \\n"Option -${BOLD}$OPTARG${OFF} not allowed."
_usage
;;
esac
done
##################################################
# Check for git
hash git 2>&- || { _error "I require git but it's not installed!"; exit 1; }
##################################################
git config --global url."https://".insteadOf git://
# Remove previous termieter installation if present at the same location as $install_dir
cd ~
_print_h1 "Install termieter"
if [ "$update" -eq 0 ]; then
_print "Checking for existing termieter installation.."
if [ -d "$install_dir" ]; then
_print_info "Existing installation found, removing..."
rm -rf "$install_dir"
_print_info "Previous version removed"
fi
_print "Cloning termieter.."
if [ ! -d "$install_dir" ]; then
if ! (git clone -q [email protected]:pierot/termieter.git "$install_dir") then
_print_info "Cloning termieter from https.."
git clone -q https://github.com/pierot/termieter.git "$install_dir"
fi
fi
fi
##################################################
_print_h1 "Install user files"
mkdir -p ~/.bash_backup
_back_install() {
_print "Installing $1"
if [ ! -n "$1" ]; then
_error "Error in install script. Aborting"
exit 1
fi
if [ -f "$HOME/.$1" ]; then
mv "$HOME/.$1" "$HOME/.bash_backup/.$1"
fi
if [ -f "$install_dir/symlinks/$1" ]; then
if [ -n "$2" ]; then
ln -sf "$install_dir/symlinks/$1" "$HOME/.$2"
else
ln -sf "$install_dir/symlinks/$1" "$HOME/.$1"
fi
fi
}
for sym_file in $install_dir/symlinks/*; do
_back_install $(basename $sym_file)
done
_back_install_user() {
_print "Installing $USER $1"
if [ ! -n "$1" ]; then
_error "Error in install script. Aborting"
exit 1
fi
if [ -f "$HOME/.$1.local" ]; then
mv "$HOME/.$1.local" "$HOME/.bash_backup/.$1.local"
fi
if [ -d "$install_dir/users/$USER/$1" ]; then
if [[ "$1" == "bin" && ! -L "$HOME/$1" ]]; then
echo ""
printf "link $install_dir/users/$USER/$1 -> $HOME/$1"
ln -sf "$install_dir/users/$USER/$1" "$HOME/$1"
fi
fi
if [ -f "$install_dir/users/$USER/$1" ]; then
locals=("base.sh" "vimrc.plugs" "vimrc" "gvimrc" "gitconfig" "zshrc" "tmux.conf")
if _contains_element "$1" "${locals[@]}"; then
echo "local file $1"
ln -sf "$install_dir/users/$USER/$1" "$HOME/.$1.local"
elif [ -n "$2" ]; then
ln -sf "$install_dir/users/$USER/$1" "$HOME/.$2"
else
ln -sf "$install_dir/users/$USER/$1" "$HOME/.$1"
fi
fi
}
for sym_file in $install_dir/users/$USER/*; do
_back_install_user $(basename $sym_file)
done
# ~/.config install
if [ -d "$HOME/.config" ]; then
mv "$HOME/.config" "$HOME/.config.backup"
rm -rf "$HOME/.config"
fi
ln -sf "$install_dir/users/$USER/config" "$HOME/.config"
##################################################
_print_h1 "Init paq-nvim (https://github.com/savq/paq-nvim)"
paq_dir="${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/pack/paqs/opt/paq-nvim
if [ -d "$paq_dir" ]; then
rm -rf "$paq_dir"
fi
git clone -q https://github.com/savq/paq-nvim.git $paq_dir
##################################################
if [ -d "$install_dir" ]; then
cd $install_dir
_print_h1 "Init submodules"
git submodule update --init -q
_print_h1 "Init custom plugins"
if [ ! -d "zsh/oh-my-zsh/custom/plugins" ]; then
mkdir "zsh/oh-my-zsh/custom/plugins"
fi
if [ ! -d "zsh/oh-my-zsh/functions" ]; then
mkdir "zsh/oh-my-zsh/functions"
fi
_print_h1 "Init tmix-resurrect"
if [ -d "$install_dir/tmux/tmux-resurrect" ] ; then
_print "tmux-resurrect is already installed"
else
git clone -q https://github.com/tmux-plugins/tmux-resurrect $install_dir/tmux/tmux-resurrect
fi
fi
##################################################
_print_h1 "Installation finished"
_print " Do not forget to switch to zsh as the default shell"
_print_info " \$ sudo chsh -s /bin/zsh $USER"
_print ""