|
| 1 | +# shellcheck shell=bash |
1 | 2 | # If -p, -D, -P, or -V specifies a package, set package_url |
2 | 3 | # If -U specifies a package, print the package_url and exit with normal status |
3 | 4 | # shellcheck disable=SC2154 |
4 | 5 | set_or_print_url() |
5 | 6 | { |
6 | 7 | # Verify requirements |
7 | | - [ ! -z "${arg_U}" ] && [ ! -z "${arg_D:-${arg_p:-${arg_P:-${arg_V:-${arg_B}}}}}" ] && |
| 8 | + [[ -n "${arg_U}" && -n "${arg_D:-${arg_p:-${arg_P:-${arg_V:-${arg_B}}}}}" ]] && |
8 | 9 | emergency "Please pass only one of {-B, -D, -p, -P, -U, -V} or a longer equivalent (multiple detected)." |
9 | 10 |
|
10 | 11 | # Get package name from argument passed with -p, -D, -P, -V, or -U |
11 | 12 | package_to_build="${arg_p:-${arg_D:-${arg_P:-${arg_U:-${arg_V:-${arg_B}}}}}}" |
12 | 13 |
|
13 | | -if [[ ! -z ${arg_u:-} ]]; then |
| 14 | +if [[ -n "${arg_u:-}" ]]; then |
14 | 15 | # User specified a URL from which to download the package |
15 | | - url_tail=${arg_u##*/} # set url_tail to text_after_final_slash |
16 | | - url_head=${arg_u%%${url_tail}} # set url_head text before url_tail |
| 16 | + url_tail="${arg_u##*/}" # set url_tail to text_after_final_slash, greedy expansion needed |
| 17 | + url_head="${arg_u%${url_tail}}" # set url_head text before url_tail |
17 | 18 | else |
18 | 19 |
|
19 | 20 | if [[ "${package_to_build}" == 'cmake' ]]; then |
|
87 | 88 | emergency "Package ${package_name:-} not recognized. Use --l or --list-packages to list the allowable names." |
88 | 89 | fi |
89 | 90 |
|
90 | | -fi # end if [[ ! -z $arg_u ]]; then |
| 91 | +fi # end if [[ -n "${arg_u:-}" ]]; then |
91 | 92 |
|
92 | 93 | package_url="${url_head}""${url_tail}" |
93 | 94 |
|
94 | 95 | # If a printout of the package URL was requested, then print it and exit with normal status |
95 | | - if [[ ! -z "${arg_U:-}" ]]; then |
| 96 | + if [[ -n "${arg_U:-}" ]]; then |
96 | 97 | printf "%s\n" "${package_url}" |
97 | 98 | exit 0 |
98 | 99 | fi |
|
0 commit comments