-
Notifications
You must be signed in to change notification settings - Fork 1
/
installbiobash
executable file
·267 lines (200 loc) · 7.91 KB
/
installbiobash
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
#!/usr/bin/env bash
#
# Performs the installation of BIOBASH.
#
#Common libraries
source lib/shml/shml.sh
source lib/bb_utility/check.sh
source lib/bb_utility/file.sh
#----------------------------------------------------------------------------
#
# FUNCTIONS
#
#----------------------------------------------------------------------------
# Reads user input to define installation directory. Returns real path to dir.
function define_install_dir() {
read -p " Install in (/usr/local): " dir
#If user hitted ENTER, $dir comes empty, so use default install dir.
#Otherwise use user provided path.
if [ -z "$dir" ]; then
dir=$default
else
dir=$dir
fi
#realpath for installDir. No relative paths allowed.
#There is a bug with paths like "~/path/to/dir". For some reason "realpath" do not
#resolve this type of path in the script, but it does in the shell!!??
#return=$(realpath "${dir}")
return=$(file::full_path "${dir}")
#Return value
echo -n "$return"
}
# Some propaganda/user feedback.
v=$(cat version)
echo "
$(fgcolor gray '...............................................................') $(fgcolor end)
$(a bold)$(fgcolor lightblue ' BIOBASH INSTALLER') $(fgcolor end) $(a end)
$(fgcolor lightblue ' Bioinformatics and Systems Biology Laboratory') $(fgcolor end)
$(fgcolor lightblue ' Institute for Genetics - National University of Colombia') $(fgcolor end)
$(fgcolor lightblue ' https://gibbs.unal.edu.co') $(fgcolor end)
"
#----------------------------------------------------------------------------
#
# BEFORE ATTEMPTING ANYTHING... check pre-requisites.
#
#----------------------------------------------------------------------------
./check_dependencies.sh
#If check dependencies was succesful it creates a "flag" file: depend_ok
#otherwise (file doesn`t exist) there are dependencies to be met. Stop installation.
if [[ ! -e depend_ok ]];then
echo "$(fgcolor yellow) Quitting installation of BioBash.$(fgcolor end)
"
exit 1
fi
# If we reached this point it means dependencies check was succesful and therefore
# it is safe to erase depend_ok file. It is not needed from now on.
rm depend_ok
#----------------------------------------------------------------------------
#
# START ACTUAL INSTALLATION
#
#-----------------------------------------------------------------------------
# We are assuming a standard installation on a Linux Machine (at least
# for now). This is the default directory for installation.
default="/usr/local"
echo " $(fgcolor lightblue) $(a bold)SELECT THE INSTALLATION DIRECTORY$(a end).$(fgcolor end)"
echo "$(hr)"
echo "$(fgcolor gray)
The installation directory is the place where all BioBash related
files will be stored, including libraries and binaries. By default
BioBash will be installed in '$default' directory, nevertheless you
need write permissions on that folder. Alternatively you can define a
path to another installation directory.$(fgcolor end)
Hit ENTER to use the default installation directory ($default) or
provide a valid installation path:
"
installDir="$(define_install_dir)"
# Wether install will be performed on user defined or default install dir, it is
# important to make sure that it exists and that we can write on it.
# Does it exist?
if [ ! -d "${installDir}" ];then
echo "$(fgcolor red)$installDir does not exist. Please make sure it is a valid directory.$(fgcolor end)
"
exit 1
fi
# If we reached this point it means directoy exists. Check if it is writable.
if [ ! -w "$installDir" ];then
echo "I can not write to: $installDir. Please make sure you have the right permissions on that folder."
exit 1
fi
#If we reached this point, it means we can proceed with installation.
#----------------------------------------------------------------------
#
# MAIN INSTALLATION
#
#-----------------------------------------------------------------------
# "version" is a file in main install dir
BBVERSION=$(cat version)
BIOBASH_HOME=$(echo "$installDir/biobash-$BBVERSION")
#User feedback
echo "
$(fgcolor green)I am ready to install BioBash version $BBVERSION in $BIOBASH_HOME.$(fgcolor end)
"
echo "
$(fgcolor lightblue) $(a bold)INSTALL BIOBASH IN ${BIOBASH_HOME} $(a end)$(fgcolor end)
$(hr)
$(fgcolor gray)
We have now all necessary information to install BioBASH in this machine.
The ${BIOBASH_HOME} folder will be the root of this
installation and all necessary scripts, dependencies
and executables will be installed there.
$(fgcolor end)
"
#Flow control. Answer should be "y" or "n"
continue=0
until [ $continue == "y" ] || [ $continue == "n" ]
do
read -p 'Proceed? [y/n]: ' continue
done
if [[ $continue == "n" ]]; then
echo "$(fgcolor green)
Leaving BioBash Installation. Nothing done.
Bye!
$(fgcolor end)
"
exit 0
elif [[ $continue == "y" ]];then
echo "
$(fgcolor lightblue)$(a bold) STARTING BioBASH INSTALLATION $(a end) $(fgcolor end)
$(hr)"
else
echo "$(fgcolor red)
ERROR: Installation can not proceed. Unknown reason.
$(fgcolor end)"
exit 1
fi
#Create BIOBASH directory. The "-p" option is useful when re-trying the installation multiple times,
#so if the directory was created before it won't complain because directory already exists.
echo "$(fgcolor green) Creating BioBASH home in: ${BIOBASH_HOME}$(fgcolor end)"
mkdir -p "$BIOBASH_HOME"
#----------------------------------------------------------------------------
#
# SETUP ENVIRONMENT
#
# This routine puts all needed environmental variables into bashrc
#
#----------------------------------------------------------------------------
#Note that we are sending the $BIOBASH_HOME variable to the script!!!
echo "$(fgcolor green) Setting up the environment$(fgcolor end)"
./setup_environment.sh "$BIOBASH_HOME"
#If environment setup was succesful it creates a "flag" file: environ_ok
#otherwise (file doesn`t exist) there were errors. Stop installation.
if [[ ! -e environ_ok ]];then
echo "$(fgcolor red) [ERROR] UNABLE TO PERFORM INSTALLATION.
Please check previous messages for possible reasons.
Quitting installation of BioBash.$(fgcolor end)
"
exit 1
fi
# If we reached this point it means environment set up was succesful and therefore
# it is safe to erase depend_ok file. It is not needed from now on.
rm environ_ok
#----------------------------------------------------------------------------
#
# Copy libraries
#
# This routine copies libraries and stuff in BIOBASH_HOME
#
#----------------------------------------------------------------------------
echo "$(fgcolor green) Copying binaries and executables in $BIOBASH_HOME $(fgcolor end)
"
# Future version needs a better selection of what to install.
cp -r ./lib "$BIOBASH_HOME"
cp -r ./bin "$BIOBASH_HOME"
cp -r ./unitesting "$BIOBASH_HOME"
cp -r ./testdata "$BIOBASH_HOME"
cp ./version "$BIOBASH_HOME"
cp exec/bb_* "$BIOBASH_HOME" #These are all the actual BB scripts.
#----------------------------------------------------------------------------
#
# Source enviroment
#
#----------------------------------------------------------------------------
source ~/.bashrc
echo "
$(fgcolor lightblue)
$(emoji thumbsup) [BIOBASH WAS INSTALLED SUCCESFULLY!]
$(fgcolor end)
$(attribute bold) You can start using BioBash right now! $(attribute end)
Nevertheless it is possible that you will need to inform your shell that BioBASH was installed.
So, please update your environment with the following command:
> source ~/.bashrc
Alternatively you can open a new terminal or logout and login from your account.
$(attribute bold) Thank you for installing BIOBASH $(attribute end)
$(fgcolor lightblue)
Bioinformatics and Systems Biology Laboratory
Institute for Genetics - National University of Colombia
Bogota - Colombia
$(fgcolor end)
"
exit 0