diff options
author | Klemens Nanni <contact@autoboot.org> | 2015-08-24 12:34:09 +0200 |
---|---|---|
committer | Francis Rowe <info@gluglug.org.uk> | 2015-08-29 18:40:22 +0100 |
commit | 33c9e3dea85d5274f9a19db10195f3b2e5bcccd2 (patch) | |
tree | fc3d0ff2f9110f18207ddacb9596e47a9af175c1 /download | |
parent | 47dc32fb4a0170956e5b9dd33ff6e2447b9f977c (diff) | |
download | librebootfr-33c9e3dea85d5274f9a19db10195f3b2e5bcccd2.tar.gz librebootfr-33c9e3dea85d5274f9a19db10195f3b2e5bcccd2.zip |
download script: Don't download if argument is invalid
Diffstat (limited to 'download')
-rwxr-xr-x | download | 57 |
1 files changed, 23 insertions, 34 deletions
@@ -4,6 +4,7 @@ # aren't distributed in the git repository. # # Copyright (C) 2014, 2015 Francis Rowe <info@gluglug.org.uk> +# Copyright (C) 2015 Klemens Nanni <contact@autoboot.org> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,40 +23,28 @@ [ "x${DEBUG+set}" = 'xset' ] && set -v set -u -e -download="./resources/scripts/helpers/download" -programmes="unknown" +download=./resources/scripts/helpers/download +availableprogrammes=$(ls ${download}/) -usage="./download programme(s) # programmes are space separated, if specifing multiple programmes" -availableprogrammes="$(ls ${download}/)" - -# User specified no or too few/many parameters -if [ $# -lt 1 ]; then - printf "%s\n\n" "${usage}" - printf "possible values for 'programmes':\nall:\n%s\n\n" "${availableprogrammes}" - printf "Example (download everything): ./download all\n" - printf "Example (download flashrom): ./download flashrom\n" - printf "Example (download coreboot): ./download coreboot\n" - printf "Example (download coreboot and flashrom): ./download coreboot flashrom\n" - printf "Example (lists all available downloadable components): ./download list\n" - exit 1 -fi -programmes="$@" - -if [ "${programmes}" = "list" ]; then - printf "Available programmes are:\nall\n%s\n" "${availableprogrammes}" -elif [ "${programmes}" = "all" ]; then - for programme in ${availableprogrammes}; do - ${download}/${programme} - done -else - for programme in ${programmes}; do - printf "\"%s\"\n" "${programme}" - if [ -f "${download}/${programme}" ]; then +case ${@} in + all) + for programme in ${availableprogrammes}; do ${download}/${programme} - else - printf "download: WARNING: Invalid programme '%s'. Available programmes are:\nall\n%s\n" "${programmes}" "${availableprogrammes}" - fi - done -fi - + done;; + list) + printf "possible values for 'programmes':\nall:\n%s\n\n" "${availableprogrammes}";; + help) + printf "%s\n\n" "./download programme(s) # programmes are space separated, if specifing multiple programmes" + printf "possible values for 'programmes':\nall:\n%s\n\n" "${availableprogrammes}" + printf "Example (download everything): ./download all\n" + printf "Example (download flashrom): ./download flashrom\n" + printf "Example (download coreboot): ./download coreboot\n" + printf "Example (download coreboot and flashrom): ./download coreboot flashrom\n" + printf "Example (lists all available downloadable components): ./download list\n";; + *) + for programme in ${@}; do + echo ${availableprogrammes} | grep -wq ${programme} || (printf "ERROR: Invalid programme '${programme}'. See ./download help.\n"; exit 1) + done + ${download}/${@};; +esac # ------------------- DONE ---------------------- |