This repository has been archived by the owner on Mar 14, 2023. It is now read-only.
forked from zeroc0d3/ruby-installation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dummy.sh
executable file
·221 lines (195 loc) · 7.1 KB
/
dummy.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
#!/usr/bin/env sh
TITLE="RUBY INSTALLATION SCRIPT" # script name
VER="1.5.4-dummy" # script version
DEFAULT_VERSION="2.4.2" # default version installation
DEFAULT_PACKAGE="rbenv" # default package installation
INSTALL_VERSION=$DEFAULT_VERSION
INSTALL_PACKAGE=$DEFAULT_PACKAGE
USERNAME=`echo $USER` # default username
PATH_HOME=`echo $HOME` # default home path
### Path Installation Ruby Package Manager ###
RBENV_ROOT="$PATH_HOME/.rbenv"
RVM_ROOT="/usr/local/rvm"
### Path Backup Old Ruby Package Manager ###
SNAP_BACKUP=`date '+%Y%m%d%H%M'`
PATH_BACKUP_RBENV=$PATH_HOME"/__rbenv_"$SNAP_BACKUP
PATH_BACKUP_RVM=$PATH_HOME"/__rvm_"$SNAP_BACKUP
VAR_SHELL=`$SHELL -c 'echo $0'`
get_time() {
DATE=`date '+%Y-%m-%d %H:%M:%S'`
}
logo() {
clear
echo "\033[22;32m==========================================================================\033[0m"
echo "\033[22;31m __________ _________ _______ .___________ \033[0m"
echo "\033[22;31m \____ /___________ ____ \_ ___ \\ _ \ __| _/\_____ \ LAB \033[0m"
echo "\033[22;31m / // __ \_ __ \/ _ \/ \ \// /_\ \ / __ | _(__ < \033[0m"
echo "\033[22;31m / /\ ___/| | \( <_> ) \___\ \_/ \/ /_/ | / \ \033[0m"
echo "\033[22;31m /_______ \___ >__| \____/ \______ /\_____ /\____ | /______ / \033[0m"
echo "\033[22;31m \/ \/ \/ \/ \/ \/ \033[0m"
echo "\033[22;32m--------------------------------------------------------------------------\033[0m"
echo "\033[22;32m# $TITLE :: ver-$VER \033[0m"
}
header() {
logo
echo "\033[22;32m==========================================================================\033[0m"
get_time
echo "\033[22;37m# BEGIN PROCESS..... (Please Wait) \033[0m"
echo "\033[22;33m# Start at: $DATE \033[0m\n"
}
footer() {
echo "\033[22;32m==========================================================================\033[0m"
get_time
echo "\033[22;33m# Finish at: $DATE \033[0m"
echo "\033[22;37m# END PROCESS..... \033[0m\n"
}
check_version() {
## RUBY_VERSION from Docker Environment
if [ "${RUBY_VERSION}" != "" ]
then
INSTALL_VERSION=${RUBY_VERSION}
fi
}
check_ruby_package() {
## RUBY_PACKAGE from Docker Environment
if [ "${RUBY_PACKAGE}" != "" ]
then
INSTALL_PACKAGE=${RUBY_PACKAGE}
fi
}
cleanup() {
get_time
echo "\033[22;34m[ $DATE ] ##### Archiving Old Ruby Packages: \033[0m"
# if [ "$INSTALL_PACKAGE" = "rbenv" ]
# then
# if [ -d "$RBENV_ROOT" ]; then
# mv $RBENV_ROOT $PATH_BACKUP_RBENV
# fi
# else
# if [ -d "$RVM_ROOT" ]; then
# sudo mv $RVM_ROOT $PATH_BACKUP_RVM
# fi
# fi
# sudo rm -f /etc/profile.d/rvm.sh
echo ""
get_time
echo "\033[22;32m[ $DATE ] :: [ ✔ ] \033[22;32m Old Ruby Packages Archived... \033[0m\n"
}
load_env() {
get_time
echo "\033[22;34m[ $DATE ] ##### Load Environment: \033[0m"
### Running Ruby Environment ###
PWD=`pwd`
cd $PWD; /bin/sh ./ruby.sh
if [ "$INSTALL_PACKAGE" = "rbenv" ]
then
if [ "$VAR_SHELL" = "`which zsh`" ] || [ "$VAR_SHELL" = "zsh" ]
then
echo "\033[22;32m[ $DATE ] $PATH_HOME/.zshrc \033[0m\n"
else
if [ "$VAR_SHELL" = "`which bash`" ] || [ "$VAR_SHELL" = "bash" ]
then
echo "\033[22;32m[ $DATE ] $PATH_HOME/.bashrc \033[0m\n"
else
echo "\033[22;32m[ $DATE ] $PATH_HOME/.bashrc \033[0m\n"
fi
fi
else
echo "\033[22;32m[ $DATE ] $RVM_ROOT/scripts/rvm \033[0m\n"
fi
get_time
echo "\033[22;32m[ $DATE ] :: [ ✔ ] \033[22;32m Environment Loaded... \033[0m\n"
}
reload_shell() {
if [ "$INSTALL_PACKAGE" = "rbenv" ]
then
exec $SHELL
else
source $RVM_ROOT/scripts/rvm
fi
}
install_ruby() {
get_time
echo "\033[22;34m[ $DATE ] ##### Install Ruby Version: \033[0m"
echo "\033[22;32m[ $DATE ] $INSTALL_VERSION \033[0m\n"
get_time
echo "\033[22;34m[ $DATE ] ##### Using Ruby Package: \033[0m"
echo "\033[22;32m[ $DATE ] $INSTALL_PACKAGE \033[0m\n"
cleanup
if [ "$INSTALL_PACKAGE" = "rbenv" ]
then
#-----------------------------------------------------------------------------
# Get repo rbenv
#-----------------------------------------------------------------------------
get_time
echo "\033[22;34m[ $DATE ] ##### Download RBENV Repository: \033[0m"
# git clone https://github.com/rbenv/rbenv.git $RBENV_ROOT \
# && git clone https://github.com/rbenv/ruby-build.git $RBENV_ROOT/plugins/ruby-build
# #-----------------------------------------------------------------------------
# # Install Ruby with rbenv (default)
# #-----------------------------------------------------------------------------
# $RBENV_ROOT/bin/rbenv install $INSTALL_VERSION \
# && $RBENV_ROOT/bin/rbenv global $INSTALL_VERSION \
# && $RBENV_ROOT/bin/rbenv rehash
echo ""
get_time
echo "\033[22;32m[ $DATE ] :: [ ✔ ] \033[22;32m Ruby Installed... \033[0m\n"
else
#-----------------------------------------------------------------------------
# Get repo rvm
#-----------------------------------------------------------------------------
get_time
echo "\033[22;34m[ $DATE ] ##### Download RVM Repository: \033[0m"
# curl -sSL https://rvm.io/mpapis.asc | gpg2 --import \
# && curl -sSL https://raw.githubusercontent.com/wayneeseguin/rvm/master/binscripts/rvm-installer | sudo bash -s stable \
# && sudo usermod -a -G rvm root \
# && sudo usermod -a -G rvm $USERNAME \
# && sudo cp ruby.sh /etc/profile.d/rvm.sh \
# && umask g+w \
# && sudo $RVM_ROOT/bin/rvm get head --auto-dotfiles
# #-----------------------------------------------------------------------------
# # Install Ruby with rvm (alternatives)
# #-----------------------------------------------------------------------------
# $RVM_ROOT/bin/rvm install $INSTALL_VERSION \
# && $RVM_ROOT/bin/rvm use $INSTALL_VERSION --default
echo ""
get_time
echo "\033[22;32m[ $DATE ] :: [ ✔ ] \033[22;32m Ruby Installed... \033[0m\n"
fi
}
validate_installation() {
get_time
echo "\033[22;34m[ $DATE ] ##### Ruby Version: \033[0m"
RUBY=`which ruby`
RUBY_V=`$RUBY -v`
echo "\033[22;32m[ $DATE ] $RUBY_V \033[0m\n"
get_time
echo "\033[22;34m[ $DATE ] ##### Path Ruby: \033[0m"
echo "\033[22;32m[ $DATE ] $RUBY \033[0m\n"
get_time
echo "\033[22;34m[ $DATE ] ##### Path Gem: \033[0m"
GEM=`which gem`
echo "\033[22;32m[ $DATE ] $GEM \033[0m\n"
}
install_bundle() {
get_time
echo "\033[22;34m[ $DATE ] ##### Install Bundle: \033[0m"
echo "\033[22;32m[ $DATE ] $GEM install bundle \033[0m\n"
# $GEM install bundle
echo ""
get_time
echo "\033[22;32m[ $DATE ] :: [ ✔ ] \033[22;32m Bundle Installed... \033[0m"
}
main() {
header
check_version
check_ruby_package
install_ruby
load_env
validate_installation
install_bundle
footer
reload_shell
}
### START HERE ###
main