-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·266 lines (259 loc) · 6.59 KB
/
setup.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/bin/bash
###
### S E T U P S C R I P T
### Brian Chan (bchanx.com)
###
###
### G L O B A L S
###
SOURCE=~/.bashrc
BASE=~/bchanx
###
### L O G G I N G
###
function log {
echo -e "\033[1;32m--- $@ ---\033[0m"
}
function err {
echo -e "\033[1;31m--- $@ ---\033[0m"
}
###
### U T I L S
###
function ensureExists {
if [[ ! -e $1 ]]; then
touch $1
fi
}
function sourceIfExists {
if [[ -e $1 ]]; then
source $1
fi
}
function addBash {
ensureExists ~/.bashrc
if ! grep -q "$@" ~/.bashrc; then
echo "$@" >> ~/.bashrc 2>&1
fi
}
function addPath {
if [[ ! $(echo $PATH 2>&1) =~ $1 ]]; then
addBash "export PATH=$1:\$PATH"
fi
sourceIfExists $SOURCE
}
###
### S E T U P
###
function setupBashProfile {
SOURCE=~/.bash_profile
ensureExists ~/.bash_profile
if ! grep -q "source ~/.bashrc" ~/.bash_profile; then
echo "if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi" >> ~/.bash_profile
fi
log "[SETUP] .bash_profile"
}
function setupHomebrew {
BREW_VER=$(brew --version 2>&1)
if [[ $BREW_VER =~ "command not found" ]]; then
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
fi
addPath /usr/local/bin
BREW_DOC=$(brew doctor 2>&1)
if [[ ! $BREW_DOC =~ "Your system is ready to brew." ]]; then
if [[ $BREW_DOC =~ "Your Homebrew is outdated." ]]; then
brew update
else
err "Run \`brew doctor\` and fix your system before continuing."
err "If it's a path related issue, consider modifying /etc/paths."
exit 1
fi
fi
brew install wget
brew install tree
brew install postgresql
log "[SETUP] Homebrew $BREW_VER"
}
function setupGit {
# Git/Xcode/GCC
GIT_VER=$(git --version 2>&1)
if [[ ! $GIT_VER =~ "git version" ]]; then
err "Download and install Xcode, then rerun this script."
exit 1
fi
if [[ ! $(git config --get user.name 2>&1) =~ "bchanx" ]]; then
git config --global user.name "bchanx"
fi
if [[ ! $(git config --get user.email 2>&1) =~ "[email protected]" ]]; then
git config --global user.email [email protected]
fi
if [[ ! $(git config --get push.default 2>&1) =~ "simple" ]]; then
git config --global push.default simple
fi
log "[SETUP] $GIT_VER"
}
function setupBashrc {
ensureExists ~/.bashrc
if ! grep -q "function bchanx" ~/.bashrc; then
echo "function bchanx {
if [ -f ~/.bashrc.bchanx ]; then
pushd . > /dev/null
source ~/.bashrc.bchanx
popd > /dev/null
fi
}" >> ~/.bashrc
fi
if ! grep -q "function rebash" ~/.bashrc; then
echo "function rebash {
if [ -f $SOURCE ]; then
source $SOURCE
fi
if [[ \$(python -c \"import sys; print 1 if hasattr(sys, 'real_prefix') else 0\") -eq 1 ]]; then
bchanx
fi
}" >> ~/.bashrc
fi
log "[SETUP] .bashrc"
}
function setupPython {
brew install python
PY_VER=$(python --version 2>&1)
if [[ ! $PY_VER =~ "Python 2.7" ]]; then
err "$PY_VER installed. (requires 2.7.x)"
exit 1
fi
log "[SETUP] $PY_VER"
}
function setupNode {
# Node & npm
brew install node
addPath /usr/local/share/npm/bin
NPM_VER=$(npm --version 2>&1)
if [[ $NPM_VER =~ "command not found" ]]; then
wget -qO- https://npmjs.org/install.sh | sh
fi
if [[ $(lessc --version 2>&1) =~ "command not found" ]]; then
npm install -g [email protected]
npm install -g bower
fi
log "[SETUP] Node $NPM_VER"
}
function setupSSH {
if [[ ! -d ~/.ssh ]]; then
pushd . > /dev/null
cd ~
ssh-keygen
popd > /dev/null
fi
read -p "Make sure you have SSH keys added to Github (press enter to continue)"
}
function setupEnv {
setupSSH
if [[ ! -d $BASE ]]; then
mkdir $BASE;
fi;
cd $BASE
# Github repositories
GITHUB_REPOS=(bchanx misc slidr logos-in-pure-css)
for g in ${GITHUB_REPOS[@]}; do
if [[ ! -d ${g} ]]; then
git clone [email protected]:bchanx/${g}.git
fi
done
# Symlinks
ln -fs $BASE/misc/.bashrc ~/.bashrc.bchanx
ln -fs $BASE/misc/.vimrc ~/.vimrc
rm -rf ~/.vim
ln -fs $BASE/misc/.vim/ ~/.vim
# Closure compiler
if [[ ! -e $BASE/misc/closure-compiler.jar ]]; then
mkdir $BASE/misc/closure
wget http://dl.google.com/closure-compiler/compiler-latest.zip -P $BASE/misc/closure
unzip $BASE/misc/closure/compiler-latest.zip -d $BASE/misc/closure
mv $BASE/misc/closure/compiler.jar $BASE/misc/closure-compiler.jar
rm -rf $BASE/misc/closure
fi
log "[SETUP] $BASE"
}
function setupHeroku {
addPath /usr/local/heroku/bin
HEROKU_VER=$(heroku --version 2>&1)
if [[ $HEROKU_VER =~ "command not found" ]]; then
wget -qO- https://toolbelt.heroku.com/install.sh | sh
fi
cd $BASE/bchanx
if [[ ! $(git remote 2>&1) =~ "heroku" ]]; then
git remote add heroku [email protected]:bchanx.git
fi
heroku plugins:install git://github.com/ddollar/heroku-config.git
heroku keys:add
heroku config --shell > .env
log "[SETUP] $HEROKU_VER"
}
function setupVirtualenv {
cd $BASE
pip install virtualenv
if [[ ! -d venv ]]; then
virtualenv venv
fi
sourceIfExists $SOURCE
bchanx
pip install flask==0.9
pip install flask-sqlalchemy==0.16
pip install alembic==0.4.2
pip install requests
pip install psycopg2
log "[SETUP] virtualenv"
}
SYSTEM=$(uname)
if [ $SYSTEM = "Darwin" ]; then
###
### M A C O S
###
setupBashProfile
setupHomebrew
setupGit
setupBashrc
setupPython
setupNode
setupEnv
setupHeroku
setupVirtualenv
elif [ $SYSTEM = "Linux" ]; then
###
### U B U N T U
###
echo "(TODO): automate this."
# sudo apt-get install python-pip
# sudo apt-get install python-virtualenv
# sudo apt-get install curl
# sudo apt-get install nodejs
# wget https://npmjs.org/install.sh
# sudo sh ./install.sh; rm install.sh
# sudo npm install -g [email protected]
# cd ~; mkdir bchanx; cd bchanx
# git clone [email protected]:bchanx/misc.git
# virtualenv venv
# vim ~/.bashrc, add "alias bchanx='source ~/bchanx/misc/.bashrc'"
# source ~/.bashrc; bchanx
# pip install flask==0.9
# pip install flask-sqlalchemy==0.16
# pip install alembic==0.4.2
# pip install requests
# git clone [email protected]:bchanx/bchanx.git
# git clone [email protected]:bchanx/slidr.git
# git clone [email protected]:bchanx/logos-in-pure-css.git
# wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh
# cd bchanx
# git remote add heroku [email protected]:bchanx.git
# heroku keys:add
# heroku config --shell > .env
# sudo apt-get install python-dev
# sudo apt-get install libpq-dev
# pip install psycopg2
# sudo apt-get install openjdk-7-jre-headless
# bchanx; cd misc; wget http://dl.google.com/closure-compiler/compiler-latest.zip; unzip compiler-latest.zip
# mv compiler.jar closure-compiler.jar; rm compiler-latest.zip; rm COPYING; rm README
fi