summaryrefslogtreecommitdiff
path: root/build
blob: dcc74e9be306f096fcf91e9965e5a28b41a21bae (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
#!/usr/bin/env sh
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (c) 2014-2015,2020-2024 Leah Rowe <leah@libreboot.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>

set -u -e

if [ "./${0##*/}" != "${0}" ] || [ ! -f "build" ] || [ -L "build" ]; then
	printf "You must run this in the proper work directory.\n" 1>&2
	exit 1
fi

. "include/lib.sh"
. "include/vendor.sh"
. "include/mrc.sh"

err="fail"

main()
{
	[ $# -lt 1 ] && $err "bad command"
	spath="script/$1"; shift 1

	[ "${spath#script/}" = "download" ] && vendor_download $@ && return 0
	[ -f "$spath" ] || $err "bad command"
	"$spath" $@ || $err "excmd: $spath $(echo "$@")"; set -u -e
}

fail()
{
	tmp_cleanup || printf "WARNING: can't rm tmpfiles: %s\n" "$TMPDIR" 1>&2
	err_ "${1}"
}

tmp_cleanup()
{
	[ "$xbmk_parent" = "y" ] || return 0
	[ "$TMPDIR" = "/tmp" ] || rm -Rf "$TMPDIR" || return 1
	rm -f lock || return 1
}

main $@
tmp_cleanup || err_ "can't rm TMPDIR upon non-zero exit: $TMPDIR"