-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
105 lines (88 loc) · 2.26 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
#!/usr/bin/env bash
{ # This ensures the entire script is downloaded.
set -e
config_file_name=".dotfiles.config"
config_dir=$(dirname $0)
if [ -f "${config_dir}/${config_file_name}" ]; then
source ${config_dir}/${config_file_name}
fi
basedir=${basedir:-$HOME/.dotfiles}
repourl=${repourl:-git://github.com/statico/dotfiles.git}
installdir=${installdir:-$HOME}
bindir=${bindir:-$installdir/bin}
function symlink() {
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.
echo "$dest already exists, renaming to $dest.old"
backup=$dest.old
if [ -e $backup ]; then
echo "Error: $backup already exists. Please delete or rename it."
exit 1
fi
mv -v $dest $backup
fi
fi
ln -sf $src $dest
}
if ! which git >/dev/null ; then
echo "Error: git is not installed"
exit 1
fi
if [ ! -d $basedir/.git ]; then
echo "Checking out dotfiles using git..."
# rm -rf $basedir
git clone --quiet --depth=1 $repourl $basedir
fi
cd $basedir
echo "Creating symlinks..."
for path in .* ; do
case $path in
.|..|.git)
continue
;;
${config_file_name})
continue
;;
.config)
# Handled separately below
continue
;;
*)
symlink $basedir/$path $installdir/$path
;;
esac
done
symlink $basedir/.vim/vimrc $installdir/.vimrc
symlink $basedir/.vim/gvimrc $installdir/.gvimrc
# This method symlinks individual files only.
echo "Symlinking in ${installdir}/.config ..."
for path in $(find .config -type f) ; do
symlink $basedir/$path $installdir/$path
done
symlink $basedir/Taskfile.yaml $installdir/Taskfile.yaml
echo "Adding executables to ~/bin/..."
mkdir -p $bindir
for path in bin/* ; do
symlink $basedir/$path $bindir/$(basename $path)
done
echo "Setting up vim plugins..."
if [ -x .vim/update.sh ]; then
.vim/update.sh
fi
echo "Setting up git..."
cp $basedir/.gitconfig.base $installdir/.gitconfig
postinstall=$HOME/.postinstall
if [ -e $postinstall ]; then
echo "Running post-install..."
. $postinstall
else
echo "No post install script found. Optionally create one at $postinstall"
fi
echo "Done."
} # This ensures the entire script is downloaded.