Skip to content

Commit caae076

Browse files
Damian Rousonzbeekman
authored andcommitted
Handle missing wget gracefully
The "build" script now detects a messing download mechanism (as designated in the $fetch variable) and prompts the user to download the relevant tar ball and restart the installation. A few exit statements have also been updated to have unique exit codes. A minor edit in "install.sh" indicates to the user that the tar ball will be downloaded "if necessary", i.e., if it isn't already found in the expected location.
1 parent 3996afa commit caae076

File tree

2 files changed

+99
-63
lines changed

2 files changed

+99
-63
lines changed

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ find_or_install()
534534
echo "$this_script: Ready to build $package executable $executable in $package_install_path"
535535
fi
536536

537-
printf "$this_script: Ok to download, build, and install $package from source? (y/n) "
537+
printf "$this_script: Ok to download (if necessary), build, and install $package from source? (y/n) "
538538
read proceed_with_build
539539

540540
if [[ $proceed_with_build != "y" ]]; then

install_prerequisites/build

Lines changed: 98 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,10 @@ usage()
5555
echo " $this_script --help"
5656
echo " $this_script --list"
5757
echo ""
58-
exit 1
58+
echo "[exit 10]"
59+
exit 10
5960
}
6061

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-
7162
# If the package name is recognized, then set the default version.
7263
# Otherwise, list the allowable package names and default versions and then exit.
7364
set_default_version()
@@ -101,9 +92,11 @@ set_default_version()
10192
printf "%s (default version %s)\n" "$KEY" "$VALUE"
10293
fi
10394
elif [[ "$KEY" == "_unknown" ]]; then
104-
# No recognizeable argument passed so print usage information and exit:
95+
# No recognizeable argument passed so exit:
10596
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
107100
elif [[ $package_to_build == "$KEY" ]]; then
108101
# We recognize the package name so we set the default version:
109102
verbosity=$1
@@ -116,39 +109,11 @@ set_default_version()
116109
done
117110
if [[ $package_to_build == "--list" || $package_to_build == "-l" ]]; then
118111
echo ""
119-
exit 1
112+
echo "Aborting. [exit 30]"
113+
exit 30
120114
fi
121115
}
122116

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-
152117
check_prerequisites()
153118
{
154119
# 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()
173138
if [[ "$KEY" == "_unknown" ]]; then
174139
printf "$this_script: No specified dowload mechanism.\n"
175140
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
177143
elif [[ "$package_to_build" == "$KEY" ]]; then
178144
# Set the download mechanism corresponding to the recognized package:
179145
fetch=$VALUE
@@ -190,19 +156,13 @@ check_prerequisites()
190156
if ! type make > /dev/null; then
191157
printf "$this_script: 'make' is required for compiling packages from source. \n"
192158
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
200161
fi
201162
}
202163

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()
206166
{
207167
if [[ $package_to_build == 'cmake' ]]; then
208168
major_minor="${version_to_build%.*}"
@@ -224,9 +184,10 @@ download_if_necessary()
224184
KEY="${package%%;*}"
225185
VALUE="${package##*;}"
226186
if [[ "$KEY" == "_unknown" ]]; then
227-
# No recognizeable argument passed so print usage information and exit:
187+
# No recognizeable argument passed so exit:
228188
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
230191
elif [[ $package_to_build == "$KEY" ]]; then
231192
# We recognize the package name so we set the URL head:
232193
url_head=$VALUE
@@ -261,9 +222,10 @@ download_if_necessary()
261222
KEY="${package%%;*}"
262223
VALUE="${package##*;}"
263224
if [[ "$KEY" == "_unknown" ]]; then
264-
# No recognizeable argument passed so print usage information and exit:
225+
# No recognizeable argument passed so exit:
265226
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
267229
elif [[ $package_to_build == "$KEY" ]]; then
268230
# We recognize the package name so we set the URL tail:
269231
url_tail=$VALUE
@@ -272,6 +234,13 @@ download_if_necessary()
272234
done
273235
url="$url_head""$url_tail"
274236

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+
275244
if [ -f $url_tail ] || [ -d $url_tail ]; then
276245
echo "Found '$url_tail' in ${PWD}."
277246
echo "If it resulted from an incomplete download, building $package_to_build could fail."
@@ -282,9 +251,33 @@ download_if_necessary()
282251
else
283252
printf "n\n"
284253
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"
286273
fi
274+
printf "$this_script: Then restart $caller. Aborting [exit 90]\n"
275+
echo "*****************"
276+
echo ""
277+
echo ""
278+
exit 90
287279
else
280+
# The download mechanism is in the path.
288281
if [[ "$fetch" == "svn" ]]; then
289282
if [[ $version_to_build == '--avail' || $version_to_build == '-a' ]]; then
290283
args=ls
@@ -317,12 +310,13 @@ download_if_necessary()
317310
else
318311
echo "Download failed: $url_tail is not in the following, expected location:"
319312
echo "$download_path"
320-
exit 1
313+
echo "Aborting. [exit 110]"
314+
exit 110
321315
fi
322316
fi
323317
}
324318

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
326320
unpack_if_necessary()
327321
{
328322
if [[ $fetch == "svn" || $fetch == "git" ]]; then
@@ -377,10 +371,48 @@ build_and_install()
377371
popd
378372
}
379373

374+
# Print usage information and exit if script is invoked without arguments or with --help or -h as the first argument
380375
if [ $# == 0 ]; then
381-
# Print usage information if script is invoked without arguments
382376
usage | less
377+
exit 120
383378
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
384416
# Print usage information if script is invoked with --help or -h argument
385417
usage | less
386418
elif [[ $2 == '--default' && $3 == '--query-path' ]]; then
@@ -390,6 +422,10 @@ elif [[ $2 == '--default' && $3 == '--query-path' ]]; then
390422
elif [[ $2 == '--default' && $3 == '--query-version' ]]; then
391423
printf "$default_version\n"
392424
exit 0
425+
elif [[ $2 == '--default' && $3 == '--query-url' ]]; then
426+
set_url
427+
printf "$url\n"
428+
exit 0
393429
elif [[ $1 == '-v' || $1 == '-V' || $1 == '--version' ]]; then
394430
# Print script copyright if invoked with -v, -V, or --version argument
395431
echo ""

0 commit comments

Comments
 (0)