Commit Graph

43 Commits (2d16e1ee479d692e3bd4ad722505a87ef8ffb5ba)

Author SHA1 Message Date
Leah Rowe 1c2de7f962 unify build/grub/* to build/coreboot/grub
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-10-06 01:34:14 +01:00
Leah Rowe 923a96c18e check git/version: properly call err()
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-10-04 10:02:59 +01:00
Leah Rowe fbd464b4f7 include/err.sh: checkgit,checkversion
call these as functions, instead of executing scripts

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-10-04 08:06:10 +01:00
Leah Rowe cb29c96c74 lbmk: simplify/correct exit commands / cleanup
general code cleanup, but a few exit commands were also
wrong. for example, relying on listitems to always return
zero status and then calling lbmk_exit 1

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-10-02 09:03:10 +01:00
Leah Rowe 8c03b886c4 Greatly simplify error handling in shell scripts
Instead of having detailed error messages, run most
commands through a function that calls err() under
fault conditions.

Where detail is still required, err() is still called
manually. Where it isn't, the error message is simply
whatever command was executed to cause the error.

This results in a massive sloccount reduction for lbmk;
specifically, 178 sloc reduction, or a 8.1% reduction.
The total sloccount is now 2022, for shell scripts.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-10-01 22:47:02 +01:00
Leah Rowe 74c48a881d move build/command/options to include/option.sh
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-27 22:31:24 +01:00
Leah Rowe 208620198c Update email address for Leah Rowe copyrights
also, some of them were out of date; years now updated.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-25 02:27:26 +01:00
Leah Rowe cc1642096e Use SPDX license headers on all scripts
This results in much cleaner copyright and license declarations.
SPDX headers are legally recognised and make auditing easier.

Also, remove descriptions of each script, from each script.
Libreboot documentation at docs/maintain/ describes them.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-25 02:19:48 +01:00
Leah Rowe f8704c0a0d lbmk: more verbose error messages
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-16 11:37:20 +01:00
Leah Rowe a1db59a583 lbmk: reduce indentation in execute_command()
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-16 11:28:26 +01:00
Leah Rowe a9ea277e56 lbmk: fail if ./build command options fails
non-zero exit, whereas it was previously an unhandled
non-zero exit as per -e - now it is simply more verbose.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-16 11:25:35 +01:00
Leah Rowe f1f5b91a85 lbmk: simplify execute_command()
if ./build command options fails, it just means that
lbmk would next check whether ./buildpath mode list exists,
which it never will because that would violate lbmk design.

the generic "help" output is more than sufficient, and tells
the user to check "list" anyway, so there's no point in saying
it here. simplify this function.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-16 11:24:03 +01:00
Leah Rowe 662b926630 lbmk: remove "./buildpath mode all"
for example: ./build boot all

the "all" function is a relic from a much older lbmk
design, where for example we might have done:

./build clean all
./download all

this is no longer used, nor is this currently relevant
for the types of scripts present in lbmk.

we can always re-add this function later if needed,
but for now? remove unwanted code.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-16 10:58:04 +01:00
Leah Rowe 4c7343088b lbmk: break up main()
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-16 10:56:40 +01:00
Leah Rowe 5f197023db lbmk: always use lbmk_exit for exits
there were certain edge cases where TMPDIR wasn't
being cleaned. this patch will fix that.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-16 10:39:04 +01:00
Leah Rowe 087f0e066a make lbmk help text actually vaguely helpful
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-10 19:25:22 +01:00
Leah Rowe 84bf47b5b9 scripts: better handling of printf: stdout/stderr
in some cases, messages that should be considered errors
or warnings, were being written to the standard output,
rather than written as error messages.

also: one or two printf statements should specifically
avoid printing errors (to any file); in these cases,
stdout has been redirected to /dev/null

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-09 23:15:17 +01:00
Leah Rowe 33e6088a16 move script/misc/versioncheck to main directory
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-04 03:28:11 +01:00
Leah Rowe da3c9bb3c5 merge config/ and resources/
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-04 02:47:25 +01:00
Riku Viitanen ef3fb05d66 Less cat abuse
More than 90% of cats were thus terminated.
read (shell built-in) is better at reading, and dogs are better pets.

Signed-off-by: Riku Viitanen <riku.viitanen@protonmail.com>
2023-09-03 17:00:21 +03:00
Leah Rowe 4885c7962d handle TMPDIR from include/export.sh
it looks a bit cluttered just sitting there in
the main script. make it an include.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-02 10:22:39 +01:00
Leah Rowe 12b33eb8c1 lbmk script: always clean up /tmp files
export TMPDIR to scripts, and handle it in a way that
we know lbmk set it

delete it at the end of the parent process, but not child
processes; when the lbmk script calls itself, child processes
will not delete the tmp directory.

some scripts in lbmk weren't cleaning up the tmpfiles they
made, and they still don't, but this mitigates that.

now in follow-up commits, i can start cleaning up those
scripts too.

not handled by this patch:
if the user cancels lbmk (ctrl+c), the tmp directory will
still be there. this too will be handled, in subsequent
patches

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-01 01:36:34 +01:00
Leah Rowe c6fd4d2ad3 lbmk: run ./build dependencies *before* root check
After that, do not allow anything to run if the user is
root. This logic flow is more robust, and reduces the
chance of bugs in the future.

We must not permit the user to run lbmk as root.

Running it as root *is* possible, by just removing
the check, and wily enough users will do that, but
this behaviour in lbmk is good practise because it
prevents accidentally running as root. If the user
went into root just for installing dependencies, they
might accidentally forget to switch back. This is a
safeguard against such folly.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-08-28 15:28:19 +01:00
Leah Rowe 0052f9d03a fix: don't require git config for dependencies
this was an oversight on my part. the script cannot be
run as root, except to install distro dependencies e.g.:

as root: ./build dependencies debian

however, ./checkgit was being run *before* checking that,
making it required to set git config as root.

this patch fixes that bug.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-08-28 12:00:26 +01:00
Leah Rowe 623c338917 fix typo in error message ("as not permitted")
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-08-27 18:25:49 +01:00
Leah Rowe 4a280c629f .gitcheck: re-write entirely. force global config.
the way the old script worked was extremely hacky

it's cleaner just to make the user configure git

i haven't used anything from the old .gitcheck script,
which is now deleted. i completely re-wrote this, in
a much simpler way.

this is less maintenance now, when things change in
the upstream projects. coreboot makes heavy use of git
within its build system

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-08-27 18:17:31 +01:00
Leah Rowe 355eb765ff move resources/scripts/ to script/
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-08-27 17:19:36 +01:00
Leah Rowe 9457d6be52 unified list command for all scripts
e.g. ./build boot roms list
./update blobs inject listboards
./build boot list
./build clean list

also this is now possible:
./build list
or maybe
./update list
^ would list directories in resources/scripts/build
and resources/scripts/update respectively

this script is added:
resources/scripts/build/command/options

call it like so, e.g.
./build command options resources/coreboot

this script is now used, for list functions in
other scripts.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-08-27 14:24:20 +01:00
Leah Rowe 1c8401be25 much, much stricter, more verbose error handling
lbmk is much more likely to crash now, in error conditions,
which is a boon for further auditing.

also: in "fetch", remove the downloaded program
if fail() was called.

this would also be done for gnulib, when downloading
grub, but done in such a way that gnulib goes first.

where calls to err write "ERROR" in the string, they
no longer say "ERROR" because the "err" function itself
now does that automatically.

also: listmodes/listoptions (in "lbmk") now reports an
error if no scripts and/or directories are found.

also: where a warning is given, but not an error, i've
gone through in some places and redirected the output
to stderr, not stdout

as part of error checks: running anything as root, except
for the "./build dependencies *" commands, is no longer
permitted and lbmk will throw an error

mrc downloads: debugfs output no longer redirected to /dev/null,
and stderr no longer redirected to stdout. everything is verbose.

certain non-error states are also more verbose. for example,
patch_rom in blobs/inject will now state when injection succeeds

certain actual errors(bugs) were fixed:
for example, build/release/roms now correctly prepares the blobs
hash files for a given target, containing only the files and
checksums in the list. Previously, a printf message was included.
Now, with this new code: blobutil/inject rightly verifies hashes.

doing all of this in one giant patch is cleaner
than 100 patches changing each file. even this is yet part
of a much larger audit going on in the Libreboot project.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-08-26 16:58:32 +01:00
Leah Rowe 50c395df59 .gitcheck: continue if no .git (don't break)
the user may have re-downloaded a coreboot tree,
in a release. this is supported. therefore, some
may have .git, and some will not

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-08-24 16:37:40 +01:00
Leah Rowe 57adbc6eb1 unify err functions across scripts
include/err.sh

this new handling also does mundane things,
such as tell you what script b0rked

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-08-23 19:12:00 +01:00
Leah Rowe 04ee26726a also clean up the main scripts
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-08-22 00:34:15 +01:00
Leah Rowe 0faf2a0c6f main lbmk script: exit non-zero if argc is wrong
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-08-20 21:39:39 +01:00
Leah Rowe 6e92d9a359 fix "./build help"
thanks Riku Viitanen for pointing out the bug

i b0rked it myself in an earlier revision, while
auditing.

it's funny because i made this exact same mistake
during the last audit, and in the exact same way

it's fixed once again

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-08-20 21:34:08 +01:00
Leah Rowe 9031bb7ba7 unify dependencies scripts
the unified logic is so small that i simply added it
to the main "build" script

commands are identical. example:

./build dependencies debian

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-08-20 21:25:51 +01:00
Leah Rowe 63b0e99f6c don't call blobutil directly from lbmk
it's bloat, and was only there for backwards compatibility
with the old commands, but the new commands are e.g.

./update blobs inject

instead of:

./blobutil inject

this results in a slight code size reduction in lbmk

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-08-17 11:56:17 +01:00
Leah Rowe 0848622799 remove download scripts, consolidate into script
most of them were just calling the gitclone script,
so remove them.

the grub script was treating gnulib as a dependency.
i've now added the ability to grab 1 dependency, in
the gitclone script (it should be expanded later to
support multiple dependencies)

the gitclone script has been renamed to "fetch".
the "fetch_trees" script does more or less the same
thing, but calls "fetch" and handles multiple revisions
if a project needs that

this is more efficient, and slightly reduces the code
size of lbmk!

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-08-17 11:50:06 +01:00
Leah Rowe 9510d749e1 lbmk: run ./.gitcheck clean on error
a glaring oversight on my part

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-20 01:07:06 +01:00
Leah Rowe 917f699cc7 lbmk: exit 1 if script failed
script is -e anyway, so this is redundant, but best
put it here anyway. it can only help. correct behaviour
is always to fail on error, except in certain cases that
would be handled on a case-by-case basis in each script
2023-06-20 01:04:11 +01:00
Nicholas Chin 0fade1b64c
lbmk: Fix regressions
- A spurious semicolon caused the arguments to printf in die() to be
  executed instead of printed
- ${@} in die() needs to be in quotes or else printf prints each word on
  a separate line
- The number of arguments to main() does not include main itself so it
  should be comparing against 1 instead of 2 to determine if enough
  arguments were supplied.
2023-06-12 17:27:49 -06:00
Leah Rowe 06c92d4a4a blobutil: merge with main script
make blobutil a symlink. Example of command changes:

./blobutil download x220_8mb
is now:
./update blobs download x220_8mb

The old command still works, for compatibility.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-27 12:00:04 +01:00
Leah Rowe ff954c5b73 unify download/build scripts
move resources/scripts/download/ to:
resources/scripts/update/module/

This: ./download coreboot
Is now: ./update module coreboot

However, running "./download coreboot"
still works, via backwards compatibility.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-27 11:44:54 +01:00
Leah Rowe 092600d163 unify these scripts: build, modify and update
unify them, by turning them into symlinks pointing
to a generic script named lbmk

the script named lbmk is a fork of the script
named "build", which just checks argument 0 and adapts
accordingly

all of these core scripts had the exact same overall
logic, and they are thus compatible

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-27 10:54:50 +01:00