-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·101 lines (90 loc) · 2.25 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
#!/bin/bash
# Default configurations
dir=~/dotfiles
olddir=~/dotfiles_old
# Optionally override the files to be set up, e.g. ./install.sh -f .vimrc
files=".bashrc .vimrc .zshrc .oh-my-zsh .tmux.conf .fonts .font-config"
viminit=true
sys="ubuntu"
noinstall=1
function usage () {
cat <<EOF
Usage: $0 [-d source dotfiles dir] [-f dotfile list to apply ] [-o backup dir ] [-i]
-d set a custom source directory for the dotfiles [~/dotfiles]
-f a list of the dotfiles to include in setup, overriding defaults
Default: $files
-o where to put existing dotfiles for backup [~/dotfiles_old]
-s specify the system to install for [ubuntu]
-i install all expected programs using the install_$system.sh script
}
EOF
exit 0
}
# Loop the flags setting or overwriting defaults
while getopts d:o:f:s:ih opt; do
case $opt in
d)
dir=$OPTARG
;;
o)
olddir=$OPTARG
;;
f)
files=$OPTARG
;;
s)
sys=$OPTARG
;;
i)
noinstall=0
;;
h) usage ;;
\?) usage ;;
esac
done
shift $(($OPTIND - 1))
if [ $noinstall -eq 0 -a -f "$dir/install_$sys.sh" ] ; then
echo "Running installer"
. $dir/install_$sys.sh
fi
# Expected Commands
# Print out any not present before exiting on absent
expectedCommands="zsh git vim tmux powerline"
allExpectedPresent=1
for cmd in $expectedCommands ; do
if ! type "$cmd" 2> /dev/null; then
echo "$cmd is not present."
allExpectedPresent=0
fi
done
if [ $allExpectedPresent -eq 0 ] ; then
echo "Non-existent command found. Exiting..."
exit 0
fi
git config --global core.editor vim
#initialise Vundle folder
if [ ! -d ~/.vim/bundle/Vundle.vim ] ; then
if ! type git 2> /dev/null ; then
echo "Git is not installed for cloning Vundle."
exit 0
fi
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
fi
if [ ! -d "$olddir" ] ; then
mkdir -p $olddir
fi
# Move into the source directory
cd $dir
for file in $files; do
if [ -f ~/$file -a ! -h ~/$file ] ; then
mv ~/$file $olddir
fi
if [ -h ~/$file ] ; then
echo "Unlinking $file"
unlink ~/$file
fi
if [ -f $dir/$file ] ; then
echo "Symlinking from $dir/$file to $file"
ln -s $dir/$file ~/$file
fi
done