libreboot

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 33c9e3dea85d5274f9a19db10195f3b2e5bcccd2
parent 47dc32fb4a0170956e5b9dd33ff6e2447b9f977c
Author: Klemens Nanni <contact@autoboot.org>
Date:   Mon, 24 Aug 2015 12:34:09 +0200

download script: Don't download if argument is invalid

Diffstat:
download | 57+++++++++++++++++++++++----------------------------------
1 file changed, 23 insertions(+), 34 deletions(-)

diff --git a/download b/download @@ -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 ----------------------