diff options
| author | Leah Rowe <leah@libreboot.org> | 2023-05-18 09:09:26 +0100 | 
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2023-05-18 09:11:59 +0100 | 
| commit | 62c88dfb6e41a51330c294e6a5da4d39ebb5a885 (patch) | |
| tree | a32fba090b8cb25ea8836444a3dcecf8a1293e77 | |
| parent | 5b5949092847307f60293b50ed5388f265568581 (diff) | |
download script: improved coding style
introduce main()
cleaned up the if/else block
Signed-off-by: Leah Rowe <leah@libreboot.org>
| -rwxr-xr-x | download | 85 | 
1 files changed, 45 insertions, 40 deletions
| @@ -2,7 +2,7 @@  # Generic script for downloading programs used by the build system  # -#	Copyright (C) 2014, 2015, 2020, 2021 Leah Rowe <info@minifree.org> +#	Copyright (C) 2014,2015,2020,2021,2023 Leah Rowe <info@minifree.org>  #	Copyright (C) 2015 Patrick "P. J." McDermott <pj@pehjota.net>  #	Copyright (C) 2015, 2016 Klemens Nanni <contact@autoboot.org>  #	Copyright (C) 2022 Caleb La Grange <thonkpeasant@protonmail.com> @@ -27,16 +27,42 @@  [ "x${DEBUG+set}" = 'xset' ] && set -v  set -u -e -./resources/scripts/misc/versioncheck - -rm -f "build_error" -  download=resources/scripts/download +program="" + +main() +{ +	./resources/scripts/misc/versioncheck	 +	rm -f "build_error" + +	if [ $# -lt 1 ]; then +		help +		die "Please specify arguments." +	fi + +	program="${1}" +	shift 1 + +	if [ "${program}" = help ]; then +		help +		exit 0 +	elif [ "${program}" = "all" ]; then +		for downloadProgram in ${download}/*; do +			"${downloadProgram}" +		done +		exit 0 +	elif [ ! -f "${download}/${program}" ]; then +		help +		die "Invalid argument '${program}'. See: './download help'." +	elif [ $# -lt 1 ]; then	 +		"${download}/${program}" +	else	 +		"${download}/${program}" $@ +	fi -listprograms() { -	for program in "${download}"/*; do -		printf '%s\n' "${program##*/}" -	done +	exit 0 + +	./.gitcheck clean  }  help() { @@ -54,9 +80,9 @@ help() {  	Example:	./download coreboot x60  	Each program download script should work without extra paramaters, but -	they can use them. For instance, './download coreboot' will download all -	coreboot trees by default, but './download coreboot x60' will only download -	the coreboot tree required for the target: x60 +	they can be used. For example, './download coreboot' will download all +	coreboot trees by default, but './download coreboot x60' will only +	download the coreboot tree required for the target: x60  	Each program download script should also accept the --help parameter to  	display the usage of the script. @@ -65,36 +91,15 @@ help() {  	EOF  } +listprograms() { +	for program in "${download}"/*; do +		printf '%s\n' "${program##*/}" +	done +} +  die() {  	printf 'Error: %s\n' "${@}" 1>&2  	exit 1  } -if [ $# -lt 1 ]; then -	help -	die "Please specify arguments." -fi - -program="${1}" -shift 1 -[ "${program}" = help ] && help && exit 0 - -if [ "${program}" = "all" ]; then -	for downloadProgram in ${download}/*; do -		"${downloadProgram}" -	done -	exit 0 -elif [ ! -f "${download}/${program}" ]; then -	help -	die "Invalid argument '${program}'. See: './download help'." -fi - -if [ $# -lt 1 ]; then	 -	"${download}/${program}" -else	 -	"${download}/${program}" $@ -fi - -exit 0 - -./.gitcheck clean +main $@ | 
