summaryrefslogtreecommitdiff
path: root/download
blob: e5dcb3d6dbf7df483acefc27871445a6e491fbbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env bash

# Generic script for downloading programs used by the build system
#
#	Copyright (C) 2014, 2015, 2020, 2021 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>
#	Copyright (C) 2022 Alper Nebi Yasak <alpernebiyasak@gmail.com>
#
#	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
#	the Free Software Foundation, either version 3 of the License, or
#	(at your option) any later version.
#
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

./.gitcheck

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e

./resources/scripts/misc/versioncheck

# set this when you want to modify each coreboot tree
# for example, you want to test custom patches
# NODELETE= ./download coreboot
deletegit="true"
deleteblobs="true"
if [ "x${NODELETE+set}" = 'xset' ]; then
	[ "x${NODELETE:-all}" = "xgit" ] && deletegit="false"
	[ "x${NODELETE:-all}" = "xall" ] && deleteblobs="false" && deletegit="false"
fi

rm -f "build_error"

download=resources/scripts/download

listprograms() {
	for program in "${download}"/*; do
		printf '%s\n' "${program##*/}"
	done
}

help() {
	cat <<- EOF
	USAGE:	./download <PROGRAM> <OPTIONS>

	possible values for 'program':
	$(listprograms)

	Example:	./download flashrom
	Example:	./download coreboot

	Some program options allow for additional parameters:
	Example:	./download coreboot default
	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

	Each program download script should also accept the --help paramater to
	display the usage of the script.

	Refer to the documentation for more information.
	EOF
}

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
		if [ -f "${downloadProgram}" ]; then
			if [ "${deleteblobs}" = "false" ]; then
				NODELETE= "${downloadProgram}"
			elif [ "${deletegit}" = "false" ]; then
				NODELETE=git "${downloadProgram}"
			else
				"${downloadProgram}"
			fi
		fi
	done
	exit 0
elif [ ! -f "${download}/${program}" ]; then
	help
	die "Invalid argument '${program}'. See: './download help'."
fi

if [ $# -lt 1 ]; then	
	if [ "${deleteblobs}" = "false" ]; then
		NODELETE= "${download}/${program}"
	elif [ "${deletegit}" = "false" ]; then
		NODELETE=git "${download}/${program}"
	else
		"${download}/${program}"
	fi
else	
	if [ "${deleteblobs}" = "false" ]; then
		NODELETE= "${download}/${program}" $@
	elif [ "${deletegit}" = "false" ]; then
		NODELETE=git "${download}/${program}" $@
	else
		"${download}/${program}" $@
	fi
fi

exit 0

./.gitcheck clean