/
install.sh
executable file
·162 lines (139 loc) · 3.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
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
#! /usr/bin/env bash
#
# Configuration
#
TARGET="$HOME"
DOTFILES_LINK=".dotfiles"
SYMLINK_PATH="$DOTFILES_LINK"
PRIVATE_PATH="private"
SYMLINKS=( \
ackrc \
bundle \
coffeelint.json \
emacs.d \
erlang \
gemrc \
gitconfig \
gitignore \
hgrc \
irbrc \
peco \
powconfig \
rspec \
rubocop.yml \
tmux \
tmux.conf \
)
LOAD_FILES=(profile zshrc)
#
# Main Functions
#
install_symlinks () {
# Symlink dotfiles root
symlink "$ROOT_PATH" "$TARGET/$DOTFILES_LINK"
# Setup private dotfiles
if [ -f "$ROOT_PATH/$PRIVATE_PATH/install.sh" ]; then
"$ROOT_PATH/$PRIVATE_PATH/install.sh" links
fi
# Symlink each path
for i in ${SYMLINKS[@]}; do
symlink "$SYMLINK_PATH/$i" "$TARGET/.$i"
done
# Symlink shell init file for bash and zsh
for i in ${LOAD_FILES[@]}; do
symlink "$DOTFILES_LINK/load_shellrc.sh" "$TARGET/.$i"
done
}
install_launch_agents () {
mkdir -p "$HOME/Library/LaunchAgents"
for file in $ROOT_PATH/launch_agents/*.plist; do
symlink "$file" "$HOME/Library/LaunchAgents/$(basename "$file")"
done
# Setup private launch_agents
if [ -f "$ROOT_PATH/$PRIVATE_PATH/install.sh" ]; then
"$ROOT_PATH/$PRIVATE_PATH/install.sh" agents
fi
}
install_homebrew () {
/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
}
install_rbenv () {
git_clone 'git://github.com/sstephenson/rbenv.git' "$TARGET/.rbenv"
git_clone 'git://github.com/sstephenson/ruby-build.git' "$TARGET/.rbenv/plugins/ruby-build"
}
install_nvm () {
git_clone 'https://github.com/creationix/nvm.git' "$TARGET/.nvm"
}
install_virtualenv () {
curl -s https://raw.github.com/brainsik/virtualenv-burrito/master/virtualenv-burrito.sh | bash
}
#
# Initial Setup
#
if [ -n "${BASH_SOURCE[0]}" ] && [ -f "${BASH_SOURCE[0]}" ] ; then
ROOT_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
elif [ -n "$0" ] && [ -f "$0" ]; then
ROOT_PATH=$(cd "$(dirname "$0")" && pwd)
else
echo "[ERROR] Can't determine dotfiles' root path."
exit 1
fi
#
# Helper functions
#
symlink() {
if [ ! -e "$2" ]; then
echo " symlink: $2 --> $1"
ln -s "$1" "$2"
else
echo " exists: $2"
fi
}
git_clone () {
if [ ! -e "$2" ]; then
git clone "$1" "$2"
else
echo "[ERROR] $2 already exists"
fi
}
#
# Argument Handling
#
case "$1" in
symlinks|links)
install_symlinks
;;
homebrew|brew)
install_homebrew
;;
rbenv)
install_rbenv
;;
nvm)
install_nvm
;;
virtualenv|venv)
install_virtualenv
;;
launch_agents|agents)
install_launch_agents
;;
info)
echo "Target directory: $TARGET"
echo "Detected dotfiles root: $ROOT_PATH"
;;
*)
echo 'usage: ./install.sh [command]'
echo ''
echo 'Available commands:'
echo ' info: Target and source directory info.'
echo ' symlinks: Install symlinks for various dotfiles into' \
'target directory.'
echo ' homebrew: Install Homebrew (Mac OS X only).'
echo ' rbenv: Install rbenv, a Ruby version manager.'
echo ' nvm: Install nvm, a Node.js version manager.'
echo ' virtualenv: Install virtualenv-burrito, a Python version and' \
'environment manager.'
echo ' launch_agents: Install launchd plists to ~/Library/LaunchAgents/'
;;
esac