-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.sh
executable file
·141 lines (118 loc) · 2.78 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
#!/usr/bin/env bash
VERSION="1.9.3-p286"
ENVIRONMENT="rvm"
DATABASES="no"
DIR=`dirname $0`
usage() {
echo ""
echo "usage: $0 options"
echo ""
echo "This script install ruby on Debian based distributions."
echo ""
echo "options:"
echo " -h Help"
echo " -e Specify the environment for ruby ($ENVIRONMENT by default) [rvm,rbenv]"
echo " -v Specify the version of ruby you want ($VERSION by default)"
echo " -d Databases you want to install (empty by default) [postgresql,mysql,mongodb,sqlite3]"
}
install_dependencies() {
#install necessary libraries
sudo apt-get update
sudo apt-get -y install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion nodejs pkg-config
}
install_rvm() {
# get rvm script intaller and run it
curl -L get.rvm.io | bash -s stable
# make the access to rvm binaries
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
# reload the environment
source ~/.rvm/scripts/rvm
source ~/.bash_profile
}
install_rbenv() {
git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
mkdir -p ~/.rbenv/plugins
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins
echo '' >> ~/.bashrc
echo '### Load rbenv environment' >> ~/.bashrc
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
sudo ~/.rbenv/plugins/install.sh
}
install_ruby() {
if [ $ENVIRONMENT = "rvm" ]
then
# install ruby
rvm install $VERSION
# use the installed version as default
rvm use $VERSION --default
fi
if [ $ENVIRONMENT = "rbenv" ]
then
rbenv install $VERSION
rbenv rehash
rbenv global $VERSION
fi
}
install_bundler() {
# install soft to checkout and install all the gems
gem install bundler
}
install_databases() {
for x in $DATABASES
do
if [ $x != "no" ]
then
$DIR/databaseInstaller/$x.sh
fi
done
}
while getopts "he:v:d:" OPTION
do
case $OPTION in
h)
usage
exit 1
;;
e)
ENVIRONMENT=$OPTARG
;;
v)
VERSION=$OPTARG
;;
d)
DATABASES=$(echo $OPTARG | tr "," "\n")
;;
?)
usage
exit
;;
esac
done
if [[ -z $VERSION ]]
then
usage
exit 1
fi
echo "You will install ruby $VERSION using $ENVIRONMENT and $DATABASES adaptaters"
echo "Are you agree ? (Y/n)"
read answer
if [ $answer = "Y" ]
then
install_dependencies
if [ $ENVIRONMENT = "rvm" ]
then
install_rvm
fi
if [ $ENVIRONMENT = "rbenv" ]
then
install_rbenv
fi
install_ruby
install_bundler
install_databases
echo 'YOUPIIII TOP COOOL'
else
usage
fi