@@ -55,19 +55,10 @@ usage()
55
55
echo " $this_script --help"
56
56
echo " $this_script --list"
57
57
echo " "
58
- exit 1
58
+ echo " [exit 10]"
59
+ exit 10
59
60
}
60
61
61
- # If this script is invoked without arguements, print usage information
62
- # and terminate execution of the script.
63
- if [ $# == 0 ]; then
64
- usage | less
65
- exit 1
66
- fi
67
-
68
- # Interpret the first argument as the name of the package to build
69
- package_to_build=$1
70
-
71
62
# If the package name is recognized, then set the default version.
72
63
# Otherwise, list the allowable package names and default versions and then exit.
73
64
set_default_version ()
@@ -101,9 +92,11 @@ set_default_version()
101
92
printf " %s (default version %s)\n" " $KEY " " $VALUE "
102
93
fi
103
94
elif [[ " $KEY " == " _unknown" ]]; then
104
- # No recognizeable argument passed so print usage information and exit:
95
+ # No recognizeable argument passed so exit:
105
96
printf " $this_script : Package name not recognized. Execute '$this_script --list' to list the allowable package names.\n"
106
- exit 1
97
+ echo " "
98
+ echo " Aborting. [exit 20]"
99
+ exit 20
107
100
elif [[ $package_to_build == " $KEY " ]]; then
108
101
# We recognize the package name so we set the default version:
109
102
verbosity=$1
@@ -116,39 +109,11 @@ set_default_version()
116
109
done
117
110
if [[ $package_to_build == " --list" || $package_to_build == " -l" ]]; then
118
111
echo " "
119
- exit 1
112
+ echo " Aborting. [exit 30]"
113
+ exit 30
120
114
fi
121
115
}
122
116
123
- # Interpret the second command-line argument, if present, as the package version.
124
- # Otherwise, set the default package version.
125
- if [[ -z $2 ]]; then
126
- set_default_version
127
- version_to_build=$default_version
128
- elif [[ $2 == " --default" ]]; then
129
- set_default_version " quietly"
130
- version_to_build=$default_version
131
- else
132
- version_to_build=$2
133
- fi
134
-
135
- # Interpret the third command-line argument, if present, as the installation path.
136
- # Otherwise, install in a subdirectory of the present working directory.
137
- default_install_path=${PWD} /$package_to_build -$version_to_build -installation
138
- if [[ -z $3 || $3 == " --query-path" ]]; then
139
- install_path=$default_install_path
140
- else
141
- install_path=$3
142
- fi
143
-
144
- # Interpret the fourth command-line argument, if present, as the number of threads for 'make'.
145
- # Otherwise, default to single-threaded 'make'.
146
- if [ -z $4 ]; then
147
- num_threads=1
148
- else
149
- num_threads=$4
150
- fi
151
-
152
117
check_prerequisites ()
153
118
{
154
119
# This is a bash 3 hack standing in for a bash 4 hash (bash 3 is the lowest common
@@ -173,7 +138,8 @@ check_prerequisites()
173
138
if [[ " $KEY " == " _unknown" ]]; then
174
139
printf " $this_script : No specified dowload mechanism.\n"
175
140
printf " Please add a 'KEY:VALUE' pair to the 'package_download_mechanism' list in the '$this_script ' script.\n"
176
- exit 1
141
+ echo " Aborting. [exit 40]"
142
+ exit 40
177
143
elif [[ " $package_to_build " == " $KEY " ]]; then
178
144
# Set the download mechanism corresponding to the recognized package:
179
145
fetch=$VALUE
@@ -190,19 +156,13 @@ check_prerequisites()
190
156
if ! type make > /dev/null; then
191
157
printf " $this_script : 'make' is required for compiling packages from source. \n"
192
158
printf " Please ensure that 'make' is installed and in your path. Aborting.\n"
193
- exit 1
194
- fi
195
- # Verify that the download mechanism is in the path.
196
- if ! type $fetch > /dev/null; then
197
- printf " $this_script : the default download mechanism for $KEY is $fetch .\n"
198
- printf " Please ensure that $fetch is installed and in your path. Aborting.\n"
199
- exit 1
159
+ echo " Aborting. [exit 50]"
160
+ exit 50
200
161
fi
201
162
}
202
163
203
-
204
- # Download pkg-config if the tar ball is not already in the present working directory
205
- download_if_necessary ()
164
+ # Define the package location
165
+ set_url ()
206
166
{
207
167
if [[ $package_to_build == ' cmake' ]]; then
208
168
major_minor=" ${version_to_build% .* } "
@@ -224,9 +184,10 @@ download_if_necessary()
224
184
KEY=" ${package%% ;* } "
225
185
VALUE=" ${package##* ;} "
226
186
if [[ " $KEY " == " _unknown" ]]; then
227
- # No recognizeable argument passed so print usage information and exit:
187
+ # No recognizeable argument passed so exit:
228
188
printf " $this_script : Package name not recognized. Execute '$this_script --list' to list the allowable package names.\n"
229
- exit 1
189
+ echo " Aborting. [exit 60]"
190
+ exit 60
230
191
elif [[ $package_to_build == " $KEY " ]]; then
231
192
# We recognize the package name so we set the URL head:
232
193
url_head=$VALUE
@@ -261,9 +222,10 @@ download_if_necessary()
261
222
KEY=" ${package%% ;* } "
262
223
VALUE=" ${package##* ;} "
263
224
if [[ " $KEY " == " _unknown" ]]; then
264
- # No recognizeable argument passed so print usage information and exit:
225
+ # No recognizeable argument passed so exit:
265
226
printf " $this_script : Package name not recognized. Execute '$this_script --list' to list the allowable package names.\n"
266
- exit 1
227
+ echo " Aborting. [exit 70]"
228
+ exit 70
267
229
elif [[ $package_to_build == " $KEY " ]]; then
268
230
# We recognize the package name so we set the URL tail:
269
231
url_tail=$VALUE
@@ -272,6 +234,13 @@ download_if_necessary()
272
234
done
273
235
url=" $url_head " " $url_tail "
274
236
237
+ }
238
+
239
+ # Download pkg-config if the tar ball is not already in the present working directory
240
+ download_if_necessary ()
241
+ {
242
+ set_url
243
+
275
244
if [ -f $url_tail ] || [ -d $url_tail ]; then
276
245
echo " Found '$url_tail ' in ${PWD} ."
277
246
echo " If it resulted from an incomplete download, building $package_to_build could fail."
@@ -282,9 +251,33 @@ download_if_necessary()
282
251
else
283
252
printf " n\n"
284
253
printf " Please remove $url_tail and restart the installation to to ensure a fresh download."
285
- exit 1
254
+ echo " Aborting. [exit 80]"
255
+ exit 80
256
+ fi
257
+ elif ! type $fetch & > /dev/null; then
258
+ # The download mechanism is missing
259
+ echo " "
260
+ echo " "
261
+ echo " *****************"
262
+ printf " $this_script : The default download mechanism for $KEY is $fetch .\n"
263
+ printf " $this_script : Please either ensure that $fetch is installed and in your PATH \n"
264
+ printf " $this_script : or download the $KEY source from "
265
+ set_url
266
+ printf " $url \n"
267
+ called_by_install_sh=` echo " $( ps -p $PPID -o args=) " | grep install.sh`
268
+ printf " $this_script : Place the downloaded file in ${PWD} \n"
269
+ if [[ ! -z $called_by_install_sh ]]; then
270
+ caller=" install.sh"
271
+ else
272
+ caller=" build"
286
273
fi
274
+ printf " $this_script : Then restart $caller . Aborting [exit 90]\n"
275
+ echo " *****************"
276
+ echo " "
277
+ echo " "
278
+ exit 90
287
279
else
280
+ # The download mechanism is in the path.
288
281
if [[ " $fetch " == " svn" ]]; then
289
282
if [[ $version_to_build == ' --avail' || $version_to_build == ' -a' ]]; then
290
283
args=ls
@@ -317,12 +310,13 @@ download_if_necessary()
317
310
else
318
311
echo " Download failed: $url_tail is not in the following, expected location:"
319
312
echo " $download_path "
320
- exit 1
313
+ echo " Aborting. [exit 110]"
314
+ exit 110
321
315
fi
322
316
fi
323
317
}
324
318
325
- # Unpack pkg-config if the unpacked tar ball is not in the present working directory
319
+ # Unpack if the unpacked tar ball is not in the present working directory
326
320
unpack_if_necessary ()
327
321
{
328
322
if [[ $fetch == " svn" || $fetch == " git" ]]; then
@@ -377,10 +371,48 @@ build_and_install()
377
371
popd
378
372
}
379
373
374
+ # Print usage information and exit if script is invoked without arguments or with --help or -h as the first argument
380
375
if [ $# == 0 ]; then
381
- # Print usage information if script is invoked without arguments
382
376
usage | less
377
+ exit 120
383
378
elif [[ $1 == ' --help' || $1 == ' -h' ]]; then
379
+ usage | less
380
+ exit 130
381
+ fi
382
+
383
+ # Interpret the first argument as the name of the package to build
384
+ package_to_build=$1
385
+
386
+ # Interpret the second command-line argument, if present, as the package version.
387
+ # Otherwise, set the default package version.
388
+ if [[ -z $2 ]]; then
389
+ set_default_version
390
+ version_to_build=$default_version
391
+ elif [[ $2 == " --default" ]]; then
392
+ set_default_version " quietly"
393
+ version_to_build=$default_version
394
+ else
395
+ version_to_build=$2
396
+ fi
397
+
398
+ # Interpret the third command-line argument, if present, as the installation path.
399
+ # Otherwise, install in a subdirectory of the present working directory.
400
+ default_install_path=${PWD} /$package_to_build -$version_to_build -installation
401
+ if [[ -z $3 || $3 == " --query-path" ]]; then
402
+ install_path=$default_install_path
403
+ else
404
+ install_path=$3
405
+ fi
406
+
407
+ # Interpret the fourth command-line argument, if present, as the number of threads for 'make'.
408
+ # Otherwise, default to single-threaded 'make'.
409
+ if [ -z $4 ]; then
410
+ num_threads=1
411
+ else
412
+ num_threads=$4
413
+ fi
414
+
415
+ if [[ $1 == ' --help' || $1 == ' -h' ]]; then
384
416
# Print usage information if script is invoked with --help or -h argument
385
417
usage | less
386
418
elif [[ $2 == ' --default' && $3 == ' --query-path' ]]; then
@@ -390,6 +422,10 @@ elif [[ $2 == '--default' && $3 == '--query-path' ]]; then
390
422
elif [[ $2 == ' --default' && $3 == ' --query-version' ]]; then
391
423
printf " $default_version \n"
392
424
exit 0
425
+ elif [[ $2 == ' --default' && $3 == ' --query-url' ]]; then
426
+ set_url
427
+ printf " $url \n"
428
+ exit 0
393
429
elif [[ $1 == ' -v' || $1 == ' -V' || $1 == ' --version' ]]; then
394
430
# Print script copyright if invoked with -v, -V, or --version argument
395
431
echo " "
0 commit comments