-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathkaishi-linux
executable file
·592 lines (494 loc) · 16.5 KB
/
kaishi-linux
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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
#!/bin/bash
##
# Filename: kaishi-linux.sh
# Author: Icalia Labs
# Github: https://github.com/IcaliaLabs
#
# ========================================
# Kaishi
# ========================================
#
# A script to set up your linux for full web stack Rails development.
#
##
# To include a new package to install:
# 1) Add it to their respective associative array
# 2) If is a program, also add it to programs_ordered
# 3) Specify extra installation process (if needed)
# Put an underscore to programs that require more than an: apt-get install
declare -A programs=(
# Utilities
["git"]=true # Git
["curl"]=true # cUrl
["wget"]=true # Wget
["zsh"]=true # Zsh
["_ohMyZsh"]=true # Oh my Zsh
["vim-gtk"]=true # Vim
["_spf13-vim"]=true # Vim plugins and resources
["_heroku-toolbelt"]=true # Heroku command line client
["imagemagick"]=true # ImageMagick
["vlc"]=true # VLC
["_fpp"]=true # Path Picker
# Software Development
["nodejs"]=true # Node.js
["npm"]=true # JavaScript package manager
["_postgreSQL"]=true # PostgreSQL
["_rbenv"]=true # Ruby environment
["_prax"]=true # Ruby alternative to Pow
# Extra
["_slack"]=true # Slack
["_spotify"]=true # Spotify
["_remarkable"]=true # Markdown editor
["_sublimeText"]=true # Sublime Text 3
["_dropbox"]=true # Dropbox
["_rescueTime"]=true # RescueTime
)
declare -A gems=(
["bundler"]=true # Bundler
["rails"]=true # Ruby on Rails
["platter"]=true # Platter @IcaliaLabs
["foreman"]=true # Foreman
)
declare -A js_packages=(
["grunt"]=true # Grunt
)
declare -a programs_ordered=(
# Utilities
"git"
"curl"
"wget"
"zsh"
"_ohMyZsh"
"vim-gtk"
"_spf13-vim"
"_heroku-toolbelt"
"imagemagick"
"vlc"
"_fpp"
# Software Developmentp
"nodejs"
"npm"
"_postgreSQL"
"_rbenv"
"_prax"
# Extra
"_slack"
"_spotify"
"_remarkable"
"_sublimeText"
"_dropbox"
"_rescueTime"
)
write_log()
{
echo $1 | tee -a $LOG
}
ask_to_install()
{
echo "What do you want to do with: $1?"
select answer in "Install them all" \
"Select which to install" \
"Do not select anything"
do
case $answer in
Install* )
show_selected_for_installation $1
break
;;
Select* )
select_to_install $1
break
;;
"Do not"* )
dont_select_anything $1
break
;;
esac
done
}
select_to_install()
{
eval packages='${!'$1'[@]}'
while true
do
for package in $packages
do
echo "Do you wish to install: ${package#_} ?"
echo "Description: $(apt-cache search ${package#_} | \
grep "${package#_} -" | head -n1 | cut -d ':' -f2)"
select answer in "Yes" "No"
do
case "$answer" in
Yes)
eval $1["$package"]=true
break
;;
No)
eval $1["$package"]=false
break
;;
*)
echo "Press 1 for Yes and 2 for No"
;;
esac
done
done
show_selected_for_installation $1
echo "Are you OK with that?"
select answer in "Yes" "No"
do
case "$answer" in
Yes)
return
;;
No)
break
;;
*)
echo "Press 1 for Yes and 2 for No"
;;
esac
done
done
}
dont_select_anything()
{
eval packages='${!'$1'[@]}'
for package in $packages
do
eval $1["$package"]=false
done
}
show_selected_for_installation()
{
eval packages='${!'$1'[@]}'
for package in $packages
do
eval value='${'$1'['$package']}'
echo "Selected ${package#_}:" $value
done
}
ask_to_install programs
ask_to_install gems
ask_to_install js_packages
###############################################################################
# Install Software
###############################################################################
# Install <packages> with <method>:
install()
{
if [ "$1" == "programs" ]
then
packages=${programs_ordered[@]}
else
eval packages='${!'$1'[@]}'
fi
method=$2
for package in $packages
do
eval is_selected_to_be_installed='${'$1'['$package']}'
if [[ $package != _* ]] &&
[ $is_selected_to_be_installed == true ]
then
write_log "Installing: $package"
eval $method' '$package
fi
done
}
# Determine machine architecture
if [ $(arch) = 'x86_64' ]
then
ARCH='x86_64'
else
ARCH='x86'
fi
echo 'Creating logfile...'
LOG="$HOME/logfile-kaishi.txt"
> $LOG
echo "Logfile located at $LOG"
install programs 'sudo apt-get -y install'
is_npm_installed=$(whereis npm | cut -d ':' -f2)
if [ -z "$is_npm_installed" ]
then
write_log "Canceling js_packages installation..."
write_log "You need npm to install javascript packages"
else
install js_packages 'sudo npm install'
fi
###############################################################################
# Oh my Zsh
###############################################################################
if [ ${programs['_ohMyZsh']} == true ]
then
is_zsh_installed=$(whereis zsh | cut -d ':' -f2)
if [ -z "$is_zsh_installed" ]
then
write_log 'You need to have "zsh" installed'
write_log 'Cancelling Oh my Zsh installation'
else
write_log 'Installing Oh my Zsh'
curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
write_log 'Set Zsh as the default shell'
chsh -s /bin/zsh
fi
fi
###############################################################################
# SPF13-Vim
###############################################################################
if [ ${programs['_spf13-vim']} == true ]
then
is_git_installed=$(whereis git | cut -d ':' -f2)
is_vim_installed=$(whereis vim | cut -d ':' -f2)
if [ -z "$is_git_installed" ] || [ -z "$is_vim_installed" ]
then
write_log 'You need to have "git" and "vim" installed'
write_log 'Cancelling SPF13-Vim installation'
else
write_log 'Installing SPF13-Vim'
sh <(curl https://j.mp/spf13-vim3 -L)
> $HOME/.vimrc.bundles.local
fi
fi
###############################################################################
# Heroku Toolbelt
###############################################################################
if [ ${programs['_heroku-toolbelt']} == true ]
then
write_log 'Installing Heroku Toolbelt'
wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh
fi
###############################################################################
# PostgreSQL
###############################################################################
if [ ${programs['_postgreSQL']} == true ]
then
write_log "Installing PostgreSQL"
sudo apt-get install -y postgresql postgresql-server-dev-all libpq-dev
fi
###############################################################################
# RbEnv
###############################################################################
if [ ${programs['_rbenv']} == true ]
then
is_git_installed=$(whereis git | cut -d ':' -f2)
if [ -z "$is_git_installed" ]
then
write_log 'You need to have "git" installed'
write_log 'Cancelling rbenv installation'
else
write_log "Installing rbenv"
if [[ ! -d "$HOME/.rbenv" ]]
then
git clone git://github.com/sstephenson/rbenv.git $HOME/.rbenv
if ! grep -qs "rbenv init" ~/.zshrc
then
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> $HOME/.zshrc
echo 'eval "$(rbenv init - --no-rehash)"' >> $HOME/.zshrc
fi
export PATH="$HOME/.rbenv/bin:$PATH"
fi
if [[ ! -d "$HOME/.rbenv/plugins/rbenv-gem-rehash" ]]
then
write_log 'Installing rbenv-gem-rehash...'
git clone https://github.com/sstephenson/rbenv-gem-rehash.git $HOME/.rbenv/plugins/rbenv-gem-rehash
fi
if [[ ! -d "$HOME/.rbenv/plugins/ruby-build" ]]
then
write_log "Installing ruby-build, to install Rubies ..."
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
# Resolve https://github.com/sstephenson/ruby-build/issues/690
# Resolve http://stackoverflow.com/questions/4385549/no-such-file-to-load-readline
sudo apt-get install libffi-dev libreadline-dev
fi
ruby_version="$(curl -sSL https://raw.githubusercontent.com/IcaliaLabs/kaishi/master/latest_ruby)"
write_log "Installing Ruby $ruby_version ..."
rbenv install -s "$ruby_version"
write_log "Setting $ruby_version as global default Ruby ..."
rbenv global "$ruby_version"
rbenv rehash
rbenv init
fi
fi
###############################################################################
# Prax
###############################################################################
if [ ${programs['_prax']} == true ]
then
is_git_installed=$(whereis git | cut -d ':' -f2)
if [ -z "$is_git_installed" ]
then
write_log 'You need to have "git" and "vim" installed'
write_log 'Cancelling Prax installation'
else
is_prax_installed=$(whereis prax | cut -d ':' -f2)
if [ -z "$is_prax_installed" ]
then
write_log "Installing prax..."
sudo git clone git://github.com/ysbaddaden/prax.git /opt/prax
cd /opt/prax/ && ./bin/prax install
cd $HOME
echo 'prax start' >> ~/.zshrc
else
write_log 'Prax already installed'
fi
fi
fi
###############################################################################
# Slack
###############################################################################
if [ ${programs['_slack']} == true ]
then
write_log 'Adding repository for Slack...'
sudo apt-add-repository -y ppa:rael-gc/scudcloud
sudo apt-get -y update
write_log 'Installing Slack'
sudo apt-get -y install scudcloud
echo "alias slack='scudcloud'" >> $HOME/.bashrc
fi
###############################################################################
# Spotify
###############################################################################
if [ ${programs['_spotify']} == true ]
then
write_log 'Adding repository for Spotify...'
sudo apt-add-repository -y "deb http://repository.spotify.com stable non-free"
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 94558F59
sudo apt-get -y update
sudo apt-get -y install spotify-client
fi
###############################################################################
# Remarkable
###############################################################################
if [ ${programs['_remarkable']} == true ]
then
write_log 'Adding repository for Remarkable...'
wget http://remarkableapp.net/files/remarkable_1.41_all.deb
write_log 'Installing Remarkable dependencies'
sudo apt-get -y install python3-markdown python3-bs4 wkhtmltopdf
write_log 'Installing Remarkable'
sudo dpkg -i remarkable_1.41_all.deb
rm remarkable_1.41_all.deb
fi
###############################################################################
# Sublime Text 3
###############################################################################
if [ ${programs['_sublimeText']} == true ]
then
sublime_config="$HOME/.config/sublime-text-3/"
write_log 'Adding repository for Sublime Text 3...'
sudo add-apt-repository -y ppa:webupd8team/sublime-text-3
sudo apt-get -y update
write_log 'Installing Sublime Text 3'
sudo apt-get -y install sublime-text-installer
if [[ ! -d "$sublime_config" ]]
then
mkdir "$sublime_config"
fi
# Add package controller
wget https://packagecontrol.io/Package%20Control.sublime-package
mv "Package Control.sublime-package" "$sublime_config"
# Add extra packages
sublime_packages='{
"installed_packages":
[
"SideBarEnhancements",
"SublimeLinter"
]
}'
touch "$sublime_config""Packages/User/Package Control.sublime-settings"
echo "$sublime_packages" > "$sublime_config""Packages/User/Package Control.sublime-settings"
fi
###############################################################################
# Dropbox
###############################################################################
if [ ${programs['_dropbox']} == true ]
then
sudo apt-key adv --keyserver pgp.mit.edu --recv-keys 5044912E
write_log "Adding Dropbox repository"
sudo add-apt-repository -y "deb http://linux.dropbox.com/ubuntu $(lsb_release -sc) main"
sudo apt-get -y update
write_log "Installing Dropbox"
sudo apt-get -y install dropbox
dropbox start -i &
fi
###############################################################################
# RescueTime
###############################################################################
if [ ${programs['_rescueTime']} == true ]
then
if [ $ARCH == 'x86_64' ]
then
wget https://www.rescuetime.com/installers/rescuetime_current_i386.deb -O rescuetime.deb
else
wget https://www.rescuetime.com/installers/rescuetime_current_amd64.deb -O rescuetime.deb
fi
write_log 'Installing RescueTime dependencies'
sudo apt-get install -y gtk2-engines-pixbuf sqlite3
write_log 'Installing RescueTime'
sudo dpkg -i rescuetime.deb
rm rescuetime.deb
fi
###############################################################################
# Path Picker (fpp)
###############################################################################
if [ ${programs['_fpp']} == true ]
then
write_log 'Installing Path Picker (fpp)'
cd /usr/local/
git clone [email protected]:facebook/PathPicker.git
cd PathPicker
ln -s "$(pwd)/fpp" /usr/local/bin/fpp
cd $HOME
fi
###############################################################################
# Configuration
###############################################################################
if [ ${programs['git']} == true ]
then
write_log 'Configure git'
echo "Enter your github user.name"
read git_name
git config --global user.name $git_name
echo "Enter your github user.email"
read git_email
git config --global user.email $git_email
fi
if [ ${programs['_heroku-toolbelt']} == true ]
then
write_log 'Configure Heroku'
heroku login
fi
###############################################################################
# Gems
###############################################################################
echo 'gem: --no-document' > $HOME/.gemrc
if [ ${gems['rails']} == true ]
then
write_log "Installing Rails dependencies"
sudo apt-get install -y libxslt1-dev libcurl4-openssl-dev libksba8 libksba-dev libqtwebkit-dev libyaml-dev libsqlite3-dev
fi
is_ruby_installed=$(whereis ruby | cut -d ':' -f2)
is_rbenv_installed=$(whereis rbenv | cut -d ':' -f2)
if [ -z "$is_ruby_installed" ]
then
write_log 'You need to have "ruby" installed'
write_log 'Cancelling Gems installation'
else
if [ -z "$is_rbenv_installed" ]
then
install gems 'sudo gem install'
else
install gems 'gem install'
fi
write_log "Updating gems..."
gem update --system
if [ ${gems['bundler']} == true ]
then
write_log "Parallel bundler gem installation..."
number_of_cores=$(nproc)
bundle config --global jobs $((number_of_cores - 1))
fi
fi
write_log 'Autoremove all the shit...'
sudo apt-get autoremove
write_log 'Thanks for using Kaishi !'