forked from vanderhoop/installfest_script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathubuntu-rubyonly
More file actions
299 lines (236 loc) · 9.8 KB
/
ubuntu-rubyonly
File metadata and controls
299 lines (236 loc) · 9.8 KB
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
#!/usr/bin/env bash
#-------------------------------------------------------------------------------
# Handle Command Line Options
#-------------------------------------------------------------------------------
while getopts "vf" FLAG; do
case $FLAG in
f ) FORCE=true;;
v ) VERBOSE=true;;
? ) exit 2;;
esac
done
#-------------------------------------------------------------------------------
# Logging
#-------------------------------------------------------------------------------
# set up logfile
LOGFOLDER="$HOME/.wdi"; mkdir -p $LOGFOLDER
LOGFILE="$LOGFOLDER/install.log"
# if we are logging verbosely
# echo_log() & assert_that() -> stderr -> stdout -> *logfile* -> console
# else we are only logging assertions ([- n "$verbose" ] == false)
# echo_log() & assert_that() -> stderr -> *logfile* -> stdout -> console
# this is done by:
# a. directing echo_log() & assert_that() to stderr, via
# {echo "" >&2}, and ...
echo_log() {
echo "$1\n" >&2
}
if [ -n "$VERBOSE" ]; then
# b. executing the script so that stdout 'tee's to logfile, via
# {exec 1> >(tee logfile)} | {exec > >(tee logfile)}
# c. executing the script so that stderr redirects to stdout, via
# {exec 2>&1}
exec > >(tee $LOGFILE); exec 2>&1
else
# b. executing the script so that stderr 'tee's to logfile, via
# {exec 2> >(tee logfile)}
exec 2> >(tee $LOGFILE)
fi
echo_log
echo_log "Script execution begun: $(date)"
if [ -n "$FORCE" ]; then
echo_log " Force option set to true: will continue script despite failed assertions."
else
echo_log " Script will exit on failed assertions. Use -f option to force completion."
fi
if [ -n "$VERBOSE" ]; then
echo_log " Verbose logging option set to true: will log all output, not just errors, log statements and assertions."
else
echo_log " Script will log errors, log statements and assertions only. Use -v option to log verbosely."
fi
echo_log
#-------------------------------------------------------------------------------
# Set text formatting
#-------------------------------------------------------------------------------
# set 256 color profile where possible
if [[ $COLORTERM == gnome-* && $TERM == xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM=gnome-256color
elif infocmp xterm-256color >/dev/null 2>&1; then
export TERM=xterm-256color
fi
# Reset formatting
RESET=$( tput sgr0)
# Foreground color
BLACK=$( tput setaf 0)
RED=$( tput setaf 1)
GREEN=$( tput setaf 2)
YELLOW=$( tput setaf 3)
BLUE=$( tput setaf 4)
MAGENTA=$( tput setaf 5)
CYAN=$( tput setaf 6)
WHITE=$( tput setaf 9)
# Background color
BG_BLACK=$( tput setab 0)
BG_RED=$( tput setab 1)
BG_GREEN=$( tput setab 2)
BG_YELLOW=$( tput setab 3)
BG_BLUE=$( tput setab 4)
BG_MAGENTA=$( tput setab 5)
BG_CYAN=$( tput setab 6)
BG_WHITE=$( tput setab 9)
# Style
UNDERLINE=$( tput smul)
NOUNDERLINE=$(tput rmul)
BOLD=$( tput bold)
ITALIC=$( tput sitm)
# set FORCE (do not quit on error) to true if it is not loaded, as a default
: ${FORCE=true} # TODO (h4w5) since we are testing for null, this will always happen
# switch to true/false
echo_log() {
echo "$1" >&2
}
# ex: assert_that "`gem` is installed" "gem"
# ex: assert_that "`gem` is shimmed by rbenv" "which gem" "$HOME/.rbenv/shims/gem"
# ex: assert_that "pg gem is installed" "gem list pg -i" "true"
# log the success or failure of the file...
# if only two arguments, then success is running second arg without an error
# if three, then success is the above, and when the output of running the second is equal to the third
assert_that() {
# test for a simple error by evaling the second argument, and redirecting only
# STDERR to a variable named ERR
ERR=$( (eval "$2") 2>&1 >/dev/null )
OUT=$( (eval "$2") 2>/dev/null )
if [ -n "$ERR" ]; then # if ERR is not null, then...
# echo failure to STDERR & STDOUT
echo_log "${RED}$1: failure! Error: ${ERR}${RESET}"
[ -n "$FORCE" ] || exit 1; # exit on failure if not 'forcing'
elif [ -n "$3" ]; then # else, if there is a third argument...
if [ "$OUT" == "$3" ]; then # and they equal
# echo success to STDERR & STDOUT
echo_log "${GREEN}$1...${RESET}"
else
# echo failure to STDERR & STDOUT if second and third arguments do not match
echo_log "${RED}$1: failure! '$OUT' does not equal '$3'.${RESET}"
[ -n "$FORCE" ] || exit 1; # exit on failure if not 'forcing'
fi
else
# echo success to STDERR & STDOUT
echo_log "${GREEN}$1...${RESET}"
fi
}
# ex: assert_package_installed "git"
# ex: packagelist=( libssl-dev; libcurl4-openssl-dev; git; git-core ); assert_package_installed ${packagelist[@]}
# only works when packages share a name across OSs, otherwise easiest to write
# two assertions...
assert_package_installed() {
for package in "$@"; do
if [ "$OSTYPE" == "darwin" ]; then
assert_that "${package} package is installed" "brew ls --versions ${package}" "${package}"
elif [ "$OSTYPE" == "linux-gnu" ]; then
assert_that "${package} package is installed" "dpkg -s ${package}"
else
echo_log "${RED}OS Type unknown in assertions...${RESET}" && exit 1;
fi
done
}
BELOVED_RUBY_VERSION="2.1.2"
CURRENT_STABLE_RUBY_VERSION="2.1.2"
# TODO (phlco) set this in env vars or create_student_folders?
# STUDENT_FOLDER_SETUP="$HOME/src/wdi"
# TODO backport this into master and mac...
SRC_DIR=~/.wdi/installfest
SETTINGS=$SRC_DIR/settings
INSTALL_REPO=https://github.com/amadden80/installfest_script.git
# Standard Bash Variables
# `OSTYPE` A string describing the operating system Bash is running on.
# `MACHTYPE` system type in cpu-company-system
# `SECONDS` number of seconds since the shell was started.
# This refers to the branch of our repo that we are using (for cloning).
BRANCH=master
# capture the user's password
sudo -p "Enter your computer's password so that we can make the necessary changes: " echo "Thank you."
# uninstall rvm, so that we can use rbenv
# http://stackoverflow.com/questions/3950260/howto-uninstall-rvm
if hash rvm 2>/dev/null || [ -d ~/.rvm ]; then
yes | rvm implode
rm -rf ~/.rvm
fi
assert_that "RVM has been removed or was not installed" "command -v rvm" ""
# this is a subset of the install_system_packages script for the purpose of
# setting up an ubuntu-rubyonly install
sudo apt-get -y update
# a reference for all the packages needed to compile a debian package
# generally includes the gcc/g++ compilers an libraries and some other utils
sudo apt-get -y install build-essential
# Packages required for compilation of some stdlib modules
sudo apt-get -y install tklib
# Extras for RubyGems and Rails:
sudo apt-get -y install zlib1g-dev libssl-dev
# Readline Dev on Ubuntu 12.04 LTS:
sudo apt-get -y install libreadline-gplv2-dev
# Install some nokogiri dependencies:
sudo apt-get -y install libxml2 libxml2-dev libxslt1-dev
# git for version control
sudo apt-get -y install git
# Header files and static library for compiling C programs to link with the
# libpq library in order to communicate with a PostgreSQL database backend.
sudo apt-get -y install libpq-dev
# check installs
assert_package_installed build-essential tklib zlib1g-dev libssl-dev git libpq-dev
assert_package_installed libreadline-gplv2-dev libxml2 libxml2-dev libxslt1-dev
# Our ruby version manager
# rbenv
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
assert_that "Rbenv is installed" "rbenv version"
# Specify default gems in ~/.rbenv/default-gems
git clone https://github.com/sstephenson/rbenv-default-gems.git ~/.rbenv/plugins/rbenv-default-gems
# automatically runs rbenv rehash every time you install or uninstall a gem
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash
# Provides an rbenv install command to compile and install different versions of Ruby
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
assert_that "Rbenv's ruby-build plugin is installed" "rbenv install"
# Our gems to install
# skip documentation
echo "gem: --no-ri --no-rdoc" > ~/.gemrc
# TODO (phlco) replace ~/.rbenv with $RBENV_ROOT
touch ~/.rbenv/default-gems
gemlist=(
bundler # Maintains a consistent environment for ruby applications.
capybara # Acceptance test framework for web applications
guard # handle events on file system modifications
jasmine # JavaScript testing
pry # alternative to the standard IRB shell
pry-coolline # live syntax highlighting for the Pry REPL
rails # full stack, Web application framework
rspec # testing tool for Ruby
sinatra # a DSL for quickly creating web applications in Ruby
sinatra-contrib # common Sinatra extensions
github_api # Ruby interface to github API v3
hipchat # HipChat HTTP API Wrapper
awesome_print # pretty print your Ruby objects with style
rainbow # colorizing printed text on ANSI terminals
)
for gem in ${gemlist[@]}; do
echo "${gem}" >> ~/.rbenv/default-gems
done
# For testing and simplicity with Ubuntu, add these to the .bashrc until it's
# overwritten...
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
ruby_check=$(rbenv versions | grep $BELOVED_RUBY_VERSION)
if [[ "$ruby_check" == *$BELOVED_RUBY_VERSION* ]]; then
echo "$BELOVED_RUBY_VERSION is installed"
else
rbenv install $BELOVED_RUBY_VERSION
fi
assert_that "Ruby is installed and links to rbenv" "which ruby" "$HOME/.rbenv/shims/ruby"
rbenv global $BELOVED_RUBY_VERSION
assert_that "Ruby version is now '${BELOVED_RUBY_VERSION}'" \
"ruby -v | grep -q ${BELOVED_RUBY_VERSION} && echo 'true'" "true"
# check for gems
for gem in ${gemlist[@]}; do
assert_that "$gem gem is installed" "gem list $gem -i" "true"
done