forked from spf13/spf13-vim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·169 lines (137 loc) · 3.99 KB
/
bootstrap.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
#!/usr/bin/env bash
############################ SETUP PARAMETERS
app_name='spf13-vim'
app_dir="$HOME/.spf13-vim-3"
[ -z "$git_uri" ] && git_uri='https://github.com/AlanSherman/spf13-vim.git'
git_branch='3.0'
debug_mode='0'
fork_maintainer='0'
[ -z "$VUNDLE_URI" ] && VUNDLE_URI="https://github.com/gmarik/vundle.git"
############################ BASIC SETUP TOOLS
msg() {
printf '%b\n' "$1" >&2
}
success() {
if [ "$ret" -eq '0' ]; then
msg "\e[32m[✔]\e[0m ${1}${2}"
fi
}
error() {
msg "\e[31m[✘]\e[0m ${1}${2}"
exit 1
}
debug() {
if [ "$debug_mode" -eq '1' ] && [ "$ret" -gt '1' ]; then
msg "An error occurred in function \"${FUNCNAME[$i+1]}\" on line ${BASH_LINENO[$i+1]}, we're sorry for that."
fi
}
program_exists() {
local ret='0'
type $1 >/dev/null 2>&1 || { local ret='1'; }
# throw error on non-zero return value
if [ ! "$ret" -eq '0' ]; then
error "$2"
fi
}
############################ SETUP FUNCTIONS
lnif() {
if [ -e "$1" ]; then
ln -sf "$1" "$2"
fi
ret="$?"
debug
}
do_backup() {
if [ -e "$2" ] || [ -e "$3" ] || [ -e "$4" ]; then
today=`date +%Y%m%d_%s`
for i in "$2" "$3" "$4"; do
[ -e "$i" ] && [ ! -L "$i" ] && mv "$i" "$i.$today";
done
ret="$?"
success "$1"
debug
fi
}
upgrade_repo() {
msg "trying to update $1"
if [ "$1" = "$app_name" ]; then
cd "$app_dir" &&
git pull origin "$git_branch"
fi
if [ "$1" = "vundle" ]; then
cd "$HOME/.vim/bundle/vundle" &&
git pull origin master
fi
ret="$?"
success "$2"
debug
}
clone_repo() {
program_exists "git" "Sorry, we cannot continue without GIT, please install it first."
if [ ! -e "$app_dir" ]; then
git clone --recursive -b "$git_branch" "$git_uri" "$app_dir"
ret="$?"
success "$1"
debug
else
upgrade_repo "$app_name" "Successfully updated $app_name"
fi
}
clone_vundle() {
if [ ! -e "$HOME/.vim/bundle/vundle" ]; then
git clone $VUNDLE_URI "$HOME/.vim/bundle/vundle"
else
upgrade_repo "vundle" "Successfully updated vundle"
fi
ret="$?"
success "$1"
debug
}
create_symlinks() {
endpath="$app_dir"
if [ ! -d "$endpath/.vim/bundle" ]; then
mkdir -p "$endpath/.vim/bundle"
fi
lnif "$endpath/.vimrc" "$HOME/.vimrc"
lnif "$endpath/.vimrc.bundles" "$HOME/.vimrc.bundles"
lnif "$endpath/.vimrc.before" "$HOME/.vimrc.before"
lnif "$endpath/.vim" "$HOME/.vim"
# Useful for fork maintainers
touch "$HOME/.vimrc.local"
if [ -e "$endpath/.vimrc.fork" ]; then
ln -sf "$endpath/.vimrc.fork" "$HOME/.vimrc.fork"
elif [ "$fork_maintainer" -eq '1' ]; then
touch "$HOME/.vimrc.fork"
touch "$HOME/.vimrc.bundles.fork"
touch "$HOME/.vimrc.before.fork"
fi
if [ -e "$endpath/.vimrc.bundles.fork" ]; then
ln -sf "$endpath/.vimrc.bundles.fork" "$HOME/.vimrc.bundles.fork"
fi
if [ -e "$endpath/.vimrc.before.fork" ]; then
ln -sf "$endpath/.vimrc.before.fork" "$HOME/.vimrc.before.fork"
fi
ret="$?"
success "$1"
debug
}
setup_vundle() {
system_shell="$SHELL"
export SHELL='/bin/sh'
vim -u "$HOME/.vimrc.bundles" +BundleInstall! +BundleClean +qall
export SHELL="$system_shell"
success "$1"
debug
}
############################ MAIN()
program_exists "vim" "To install $app_name you first need to install Vim."
do_backup "Your old vim stuff has a suffix now and looks like .vim.`date +%Y%m%d%S`" \
"$HOME/.vim" \
"$HOME/.vimrc" \
"$HOME/.gvimrc"
clone_repo "Successfully cloned $app_name"
create_symlinks "Setting up vim symlinks"
clone_vundle "Successfully cloned vundle"
setup_vundle "Now updating/installing plugins using Vundle"
msg "\nThanks for installing $app_name."
msg "© `date +%Y` http://vim.spf13.com/"