From 33c9e3dea85d5274f9a19db10195f3b2e5bcccd2 Mon Sep 17 00:00:00 2001 From: Klemens Nanni Date: Mon, 24 Aug 2015 12:34:09 +0200 Subject: download script: Don't download if argument is invalid --- download | 57 +++++++++++++++++++++++---------------------------------- 1 file changed, 23 insertions(+), 34 deletions(-) (limited to 'download') diff --git a/download b/download index 82f78945..3e003a38 100755 --- a/download +++ b/download @@ -4,6 +4,7 @@ # aren't distributed in the git repository. # # Copyright (C) 2014, 2015 Francis Rowe +# Copyright (C) 2015 Klemens Nanni # # 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 ---------------------- -- cgit v1.2.3-70-g09d2