/
fancyinstall.sh
executable file
·170 lines (148 loc) · 3.75 KB
/
fancyinstall.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
#!/bin/bash -e
#
# Shamelessly stolen and adopted from github.com/Klowner/dotfiles which says
# it is shamelessly stolen and adopted from github.com/statico/dotfiles
#
# Mark's dotfile installer. Usage:
#
# curl https://raw.github.com/Klowner/dotfiles/master/install.sh | bash
# or:
# curl -L http://tinyurl.com/klownerdot | bash
# or:
#
# ~/.dotfiles/install.sh
#
# (It doesn't descend into directories.)
basedir=$HOME/.dotfiles
bindir=$HOME/bin
gitbase=git://github.com/laydros/homefiles.git
tarball=http://github.com/laydros/homefiles/tarball/master
function has() {
return $( which "$1" >/dev/null )
}
function note() {
echo "[32;1m * [0m$*"
}
function warn() {
echo "[31;1m * [0m$*"
}
function die() {
warn "$*"
exit 1
}
function link() {
src=$1
dest=$2
if [ -e "$dest" ]; then
if [ -L "$dest" ]; then
# Already symlinked -- I'll assume correctly.
return
else
# Rename files with a ".old" extension.
warn "$dest file already exists, renaming to $dest.old"
backup=$dest.old
if [ -e "$backup" ]; then
die "$backup already exists. Aborting."
fi
mv -v "$dest" "$backup"
fi
fi
# Update existing or create new symlinks.
$(which ln) -vsf "$src" "$dest"
}
function unpack_tarball() {
note "Downloading tarball..."
mkdir -vp "$basedir"
cd "$basedir"
tempfile=TEMP.tar.gz
if has curl; then
curl -L $tarball >$tempfile
elif has wget; then
wget -O $tempfile $tarball
else:
die "Can't download tarball."
fi
tar --strip-components 1 -zxvf $tempfile
rm -v $tempfile
}
if [ -e "$basedir" ]; then
# Basedir exists. Update it.
cd "$basedir"
if [ -e .git ]; then
note "Updating dotfiles from git..."
git pull --rebase origin master
else
unpack_tarball
fi
else
# .dotfiles directory needs to be installed. Try downloading first with
# git, then use tarballs.
if has git; then
note "Cloning from git..."
git clone "$gitbase" "$basedir"
cd "$basedir"
git submodule init
git submodule update
else
warn "Git not installed."
unpack_tarball
fi
fi
note "Installing oh-my-zsh..."
if [[ ! -e ~/.oh-my-zsh ]]; then
curl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | sh
fi
note "Installing dotfiles..."
for path in .* ; do
case $path in
.|..|.git)
continue
;;
*)
link "$basedir"/"$path" "$HOME"/"$path"
;;
esac
done
note "Installing bin/ directory..."
mkdir -v -p "$bindir"
if [ -d bin ]; then
for path in bin/* ; do
relpath=$( basename "$path" )
link "$basedir"/"$path" "$bindir"/"$relpath"
done
fi
#note "Installing neobundle..."
# if has git; then
# if [[ ! -d ~/.vim/bundle/neobundle.vim ]]; then
# $basedir/neobundle.sh
# fi
# fi
note "Symlinking vim configurations..."
for rc in vim gvim; do
link "$basedir"/.vim/${rc}rc "$HOME"/.${rc}rc
if [ ! -e "$HOME"/.${rc}local ]; then
touch "$HOME"/.${rc}local
fi
done
note "Installing git submodules..."
if has git; then
git submodule init
git submodule update
fi
note "Initializing tools..."
if has git; then
# Post-install scripts might customize this further.
cp -v "$basedir"/.gitconfig.base "$HOME"/.gitconfig
fi
#note "Installing vim bundles..."
#if has vim; then
# cd $basedir
# ~/.vim/bundle/neobundle.vim/bin/neoinstall
#fi
note "Running post-install script, if any..."
postinstall=$HOME/.postinstall
if [ -e "$postinstall" ]; then
# A post-install script can the use functions defined above.
. $postinstall
fi
note "Done."