forked from statico/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·142 lines (126 loc) · 2.97 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
#!/bin/bash -e
#
# Ian's dotfile installer. Usage:
#
# curl http://github.com/statico/dotfiles/raw/master/install.sh | sh
#
# or:
#
# ~/.dotfiles/install.sh
#
# (It doesn't descend into directories.)
basedir=$HOME/.dotfiles
bindir=$HOME/bin
gitbase=git://github.com/statico/dotfiles.git
tarball=http://github.com/statico/dotfiles/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.
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 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
for path in bin/* ; do
relpath=$( basename $path )
link $basedir/$path $bindir/$relpath
done
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 "Initializing tools..."
if has git; then
# Post-install scripts might customize this further.
cp -v $basedir/.gitconfig.base $HOME/.gitconfig
fi
if has vim; then
cd $basedir
./.vim/update.sh all
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."