-
Notifications
You must be signed in to change notification settings - Fork 0
/
kingpin
executable file
·428 lines (362 loc) · 10.3 KB
/
kingpin
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
#!/bin/bash
# ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★
# P.O.SH - a piece of shcript
# (c) 2012 Mangled Deutz <[email protected]>
# Distributed under the terms of the WTF-PL: do wtf you want with that code
# ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★
# UI helpers
ui::fatal(){
if [ ! -z "$TERM" ]; then
tput setaf 1
fi
for i in "$@"; do
echo "FATAL: $i"
done
if [ ! -z "$TERM" ]; then
tput op
fi
exit 1
}
ui::info(){
if [ ! -z "$TERM" ]; then
tput setaf 2
fi
for i in "$@"; do
echo "INFO: $i"
done
if [ ! -z "$TERM" ]; then
tput op
fi
}
ui::warning(){
if [ ! -z "$TERM" ]; then
tput setaf 3
fi
for i in "$@"; do
echo "WARNING: $i"
done
if [ ! -z "$TERM" ]; then
tput op
fi
}
ui::text(){
for i in "$@"; do
echo "$i"
done
}
ui::code(){
for i in "$@"; do
echo " \$ $i"
done
}
ui::confirm(){
for i in "$@"; do
echo "$i"
done
echo "Press enter now."
if [ ! -z "$TERM" ]; then
read
fi
}
ui::ask(){
echo
read -p "$1" $2
}
ui::section(){
if [[ ! -n "$@" ]]
then
return
fi
if [ ! -z "$TERM" ]; then
tput setaf 2
fi
echo "____________________________________________________________________________________________"
for i in "$@"; do
echo "| $i"
done
echo "____________________________________________________________________________________________"
echo ""
if [ ! -z "$TERM" ]; then
tput op
fi
}
ui::header(){
if [[ ! -n "$@" ]]
then
return
fi
if [ ! -z "$TERM" ]; then
tput setaf 2
fi
echo "★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★"
for i in "$@"; do
echo "★ $i"
done
echo "★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★"
echo ""
if [ ! -z "$TERM" ]; then
tput op
fi
}
# Base system installers / output
if [[ `uname` == "Darwin" ]]; then
export PACKMAN="brew"
elif [[ `uname` == "Linux" ]]; then
export PACKMAN="apt-get"
else
export PACKMAN="nopackman"
fi
system::ensure::nopackman(){
ui::fatal "... but... no supported package manager for platform `uname`. Please install required packages manually."
}
system::ensure::apt-get(){
ui::fatal "... but... unsupported linux (no apt-get!). Please install required packages manually."
}
system::ensure::brew(){
ui::warning "... but... you are missing homebrew."
ui::confirm "We will install it in ~/bin/homebrew."
mkdir -p ~/bin/homebrew
mkdir -p ~/tmp/homebrewcache
mkdir -p ~/tmp/homebrewtemp
cd ~/bin
curl -L https://github.com/mxcl/homebrew/tarball/master | tar xz --strip 1 -C homebrew
cd -
ui::ask "Your github api token for homebrew?" token
echo "" >> ~/.profile
echo "# ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★" >> ~/.profile
echo "# ★ P.O.SH && homebrew ★" >> ~/.profile
echo "# ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★" >> ~/.profile
echo "export PATH=~/bin/homebrew/bin:~/bin/homebrew/sbin:\${PATH}" >> ~/.profile
echo "export HOMEBREW_GITHUB_API_TOKEN=$token" >> ~/.profile
echo "export HOMEBREW_CACHE=~/tmp/homebrewcache" >> ~/.profile
echo "export HOMEBREW_TEMP=~/tmp/homebrewtemp" >> ~/.profile
echo "source \`brew --repository\`/Library/Contributions/brew_bash_completion.sh" >> ~/.profile
source ~/.profile
brew tap homebrew/versions
brew tap josegonzalez/php
}
system::ensure(){
if [ -z "`which $PACKMAN`" ]; then
eval system::ensure::${PACKMAN}
fi
}
system::install(){
$PACKMAN install $1
if [ ! -z "$2" ]; then
eval ${2}
fi
}
system::update(){
$PACKMAN update
$PACKMAN upgrade
$PACKMAN cleanup
}
# Top-level helpers for installation at various layers
require::system(){
binary=$1
package=$2
if [ -z "$package" ]; then
package=$1
fi
ui::info "Checking system package $package"
if [ -z "`which $binary`" ]; then
ui::warning "$binary is missing"
ui::confirm "We will try to \"$PACKMAN install $package\" now."
system::ensure
system::install $package $3
fi
}
# post::flex(){
# # Post installation for flex
# mkdir -p ~/.ant/lib
# ln -s `brew --repository`/Cellar/flex_sdk/*/libexec/ant/lib/flexTasks.jar ~/.ant/lib
# echo "" >> ~/.profile
# echo "# ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★" >> ~/.profile
# echo "# ★ P.O.SH && flex ★" >> ~/.profile
# echo "# ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★" >> ~/.profile
# echo "export PATH=\`brew --repository\`/Cellar/flex_sdk/4.6.0.23201/libexec/bin:\${PATH}" >> ~/.profile
# echo "export FLEX_HOME=\`brew --repository\`/Cellar/flex_sdk/4.6.0.23201/libexec" >> ~/.profile
# source ~/.profile
# }
post::mobile(){
echo "" >> ~/.profile
echo "# ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★" >> ~/.profile
echo "# ★ P.O.SH && mobile ★" >> ~/.profile
echo "# ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★" >> ~/.profile
echo "export ANDROID_HOME=\`brew --repository\`/opt/android-sdk" >> ~/.profile
echo "source \`brew --repository\`/etc/bash_completion.d/adb-completion.bash" >> ~/.profile
source ~/.profile
}
post::node(){
echo "" >> ~/.profile
echo "# ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★" >> ~/.profile
echo "# ★ P.O.SH && node ★" >> ~/.profile
echo "# ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★" >> ~/.profile
echo "export NPM_CONFIG_CACHE=~/tmp/npm" >> ~/.profile
source ~/.profile
}
post::rbenv(){
echo "" >> ~/.profile
echo "# ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★" >> ~/.profile
echo "# ★ P.O.SH && rbenv ★" >> ~/.profile
echo "# ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★" >> ~/.profile
echo "export RBENV_ROOT=\`brew --repository\`/var/rbenv" >> ~/.profile
echo "if which rbenv > /dev/null; then eval \"\$(rbenv init -)\"; fi" >> ~/.profile
source ~/.profile
require::system ruby-build
require::system rbenv-gem-rehash
rbenv install 2.0.0-p353
rbenv global 2.0.0-p353
gem update --system
}
# require::system::flex(){
# require::system mxmlc flex_sdk post::flex
# }
require::system::mobile(){
require::system android android-sdk post::mobile
require::system ndk-build android-ndk
require::system ios-sim
}
require::system::node(){
require::system node node post::node
}
require::system::rbenv(){
require::system rbenv rbenv post::rbenv
}
require::npm(){
npmbinary=$1
npmpackage=$2
if [ -z "$npmpackage" ]; then
npmpackage=$1
fi
ui::info "Checking npm package $npmpackage"
if [ -z "`which $npmbinary`" ]; then
ui::warning "$npmbinary is missing"
ui::confirm "We will try to \"npm install -g $npmpackage\" now."
npm install -g $npmpackage
fi
}
require::gem(){
gembinary=$1
gempackage=$2
if [ -z "$gempackage" ]; then
gempackage=$1
fi
ui::info "Checking gem package $gempackage"
if [ -z "`which $gembinary`" ]; then
ui::warning "$gembinary is missing"
ui::confirm "We will try to \"gem install $gempackage\" now."
gem install $gempackage $3
fi
}
update(){
system::ensure
system::update
if [ ! -z "`which npm`" ]; then
npm update -g > /dev/null
fi
if [ ! -z "`which gem`" ]; then
gem update --system
gem update
fi
if [ ! -z "`which pip`" ]; then
pip freeze --local | cut -d = -f 1 | xargs pip install -U
fi
if [ ! -z "`which pip3`" ]; then
pip3 freeze --local | cut -d = -f 1 | xargs pip install -U
fi
# pip freeze --local | grep -v '^\-e' | grep -v "closure-linter" | grep -v "puke2" | cut -d = -f 1 | xargs pip install -U
# purge
}
init::mobile(){
ui::header "Mobile development"
require::system::mobile
require::system::node
require::npm phonegap
}
init::scaffold(){
ui::header "Scaffolding dev"
require::system::node
require::npm yo
}
init::client(){
ui::header "Client-side web-dev initialization"
require::system::rbenv
require::gem sass "sass --pre"
require::gem compass "compass compass-sourcemaps --pre"
require::gem jsduck
require::system::node
require::npm grunt grunt-cli
require::npm bower
npm install
bower install
}
init::python(){
ui::header "Python development"
require::system pip python
require::system python3
require::system pypy
require::system jython
require::system python24
require::system python31
require::system python32
}
init::cpp(){
ui::header "C++ development"
require::system qmake qt
require::system doxygen
require::system swig
}
help(){
ui::header "P.O.SH help"
ui::section "Purpose and use"
ui::text "The purpose of P.O.SH is to intervene before, or outside the scope of \"regular\" development environments."
ui::text "In other words, it:"
ui::text " - manages the installation and maintenance of package managers (brew)"
ui::text " - manages the agnostic installation and upgrading of development tools"
ui::text " - express system agnostic commands to install more of these tools simply"
ui::text "Put otherwise, it gives you one-liners to setup project specific dev-envs and get you to work."
ui::text "This is not scaffolding, and not here to replace package managers themselves."
ui::text "Usage:"
ui::code "./kingpin COMMAND"
ui::section "Main commands"
ui::text "This help..."
ui::code "./kingpin --help"
ui::text "Update all installed system components"
ui::code "./kingpin update"
ui::text "Call this specific project initialization routine"
ui::code "./kingpin init"
ui::section "Stacks commands"
ui::text "Install QT/cpp dev-env"
ui::code "./kingpin init::cpp"
ui::text "Install python library dev-env"
ui::code "./kingpin init::python"
ui::text "Install client side dev-env"
ui::code "./kingpin init::client"
ui::text "Scaffolding (yo)"
ui::code "./kingpin init::scaffold"
ui::text "Mobile dev env"
ui::code "./kingpin init::mobile"
}
init(){
# Mix and match what you need for this specific project
# init::client
# init::mobile
# init::scaffold
# init::python
# init::cpp
init::client
# Avoid grunt watch hitting the roof
# XXX require root?
# ulimit -n 10480
}
command=${1#-}
command=${command#-}
case $command in
*)
if ! $command || [ -z "$command" ]; then
help
exit 1
fi
;;
esac