forked from yous/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·140 lines (133 loc) · 3.4 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
#!/bin/bash
DIRNAME="$(dirname "$0")"
DIR="$(cd "$DIRNAME" && pwd)"
function echoerr() {
echo "$@" 1>&2
}
function init_submodules() {
(cd "$DIR" && git submodule init)
(cd "$DIR" && git submodule update)
}
function git_clone() {
if [ ! -e "$HOME/$2" ]; then
echo "Cloning '$1'..."
git clone "$1" "$HOME/$2"
else
echoerr "~/$2 already exists."
fi
}
function replace_file() {
DEST=${2:-.$1}
# http://www.tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html
# File exists and is a directory.
[ ! -d "$(dirname "$HOME/$DEST")" ] && mkdir -p "$(dirname "$HOME/$DEST")"
# FILE exists and is a symbolic link.
if [ -h "$HOME/$DEST" ]; then
if rm "$HOME/$DEST" && ln -s "$DIR/$1" "$HOME/$DEST"; then
echo "Updated ~/$DEST"
else
echoerr "Failed to update ~/$DEST"
fi
# FILE exists.
elif [ -e "$HOME/$DEST" ]; then
if mv --backup=number "$HOME/$DEST" "$HOME/$DEST.old"; then
echo "Renamed ~/$DEST to ~/$DEST.old"
if ln -s "$DIR/$1" "$HOME/$DEST"; then
echo "Created ~/$DEST"
else
echoerr "Failed to create ~/$DEST"
fi
else
echoerr "Failed to rename ~/$DEST to ~/$DEST.old"
fi
else
if ln -s "$DIR/$1" "$HOME/$DEST"; then
echo "Created ~/$DEST"
else
echoerr "Failed to create ~/$DEST"
fi
fi
}
case "$1" in
link)
init_submodules
for FILENAME in \
'bashrc' \
'gemrc' \
'gitattributes_global' \
'gitconfig' \
'gitignore_global' \
'ideavimrc' \
'inputrc' \
'irbrc' \
'profile' \
'screenrc' \
'tmux.conf' \
'vimrc' \
'weechat' \
'zprofile' \
'zshrc'
do
replace_file "$FILENAME"
done
replace_file 'Gdbinit/gdbinit' '.gdbinit'
replace_file 'tpm' '.tmux/plugins/tpm'
for FILENAME in bin/*
do
replace_file "$FILENAME" "$FILENAME"
done
echo 'Done.'
;;
brew)
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
;;
formulae)
while read COMMAND; do
trap 'break' INT
[[ -z "$COMMAND" || ${COMMAND:0:1} == '#' ]] && continue
brew $COMMAND
done < "$DIR/Brewfile" && echo 'Done.'
;;
npm)
if ! which npm &> /dev/null; then
echoerr 'command not found: npm'
else
for PACKAGE in \
'csslint' \
'jshint' \
'jslint' \
'jsonlint'
do
if which $PACKAGE &> /dev/null; then
echoerr "$PACKAGE is already installed."
else
echo "npm install -g $PACKAGE"
npm install -g "$PACKAGE"
fi
done
fi
;;
pyenv)
curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
;;
rbenv)
git_clone https://github.com/sstephenson/rbenv.git .rbenv
git_clone https://github.com/sstephenson/ruby-build.git .rbenv/plugins/ruby-build
echo 'Done.'
;;
rvm)
\curl -sSL https://get.rvm.io | bash -s stable
;;
*)
echo "usage: $(basename "$0") <command>"
echo ''
echo 'Available commands:'
echo ' link Install symbolic links'
echo ' brew Install Homebrew'
echo ' formulae Install Homebrew formulae using Brewfile'
echo ' npm Install global Node.js packages'
echo ' pyenv Install pyenv with pyenv-virtualenv'
echo ' rbenv Install rbenv'
echo ' rvm Install RVM'
;;
esac