Commit Graph

60 Commits (08610f41451bc7d3f95d33f1dfdc22fce01821cf)

Author SHA1 Message Date
Leah Rowe 08610f4145 init.sh: only update version files on parent
don't update them on child instances, since it's a waste
of time; the lock file prevents further execution, so we
are just wasting time writing to disk.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-18 19:18:54 +01:00
Leah Rowe 412b0a81d7 init.sh: simplify unknown version creation
we don't need to read or write a file at all, in that case.
we only then need to generate one if running ./mk release.

the scenario in which no .git and no version files exist
is when someone grabs the build system from a snapshot
generated by e.g. forgejo instances. it's ill advised, so
we advise against it, but it is mitigated in code.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-18 19:18:49 +01:00
Leah Rowe 2a6a4d765d init.sh: only set xbmk version on parent instance
On child instances, we need only read.

Apply the principle of least privilege.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-18 19:18:44 +01:00
Leah Rowe 416b1f66be init.sh: initialise variables AFTER path
That way, unnecessary work is avoided on child instances.

Of course, the current check assumes that TMPDIR wasn't
already set by a wily user before running lbmk, but then
those sorts of users probably know what they're doing.

If they don't know, they will soon find out. Therefore, I
have added additional checks on child instances, preventing
the build system from running if XBMK_CACHE is not set; if
it isn't, then that could very easy lead to certain system
files being overwritten.

The user must never know what happens if XBMK_CACHE is unset.
We simply will not allow it.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-18 19:18:39 +01:00
Leah Rowe 46f09075c2 init.sh: merge create_pathdirs with set_pyver
all this function does now is create the python symlink,
based on work that was already performed in set_pyver

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-18 19:18:33 +01:00
Leah Rowe abf52b0394 init.sh: Set python version only on parent
Do it after the creation of xbmkpath.

This avoids performing an unnecessary check, since
PATH will have already been corrected for child
instances; Python will already be correct there.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-18 19:18:28 +01:00
Leah Rowe 1e4e3f36f4 init.sh: remove useless command
we mkdir -p xbmklocal, only to remkdir it immediately
afterward, which is the intended behaviour; on parent
instances, xbmklocal is to be re-created fresh.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-18 19:18:22 +01:00
Leah Rowe ed83718cf2 init.sh: remove useless comment
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-18 19:18:18 +01:00
Leah Rowe 8617375799 init.sh: xbmk_create_tmpdir to xbmk_mkdirs
this function now simply creates directories that lbmk
will use, rather than creating specific directories.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-18 19:18:13 +01:00
Leah Rowe 83064459d9 init.sh: move gnupath creation to create_tmpdir
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-18 19:18:07 +01:00
Leah Rowe 0389d1eadb init.sh: move PATH init to set_env
we must only set this in the parent instance, not
child instances. this prevents the variable from
being over-populated with repeated entries.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-18 19:18:03 +01:00
Leah Rowe 4aba9ef29e init.sh: check the lock file BEFORE git init
this way, initialisation will not be performed erroneously
while another parent instance of lbmk is running.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-18 19:17:57 +01:00
Leah Rowe fa2c288939 init.sh: return from child in set_env instead
This is earlier than the current check, thus preventing
the initialisation of a git repository and/or the recreation
of xbmktmp and xbmklocal by erroneous parent executions of lbmk
while another parent is running - the latter of which could have
caused a massively unpredictable build failure, so this is also
a pre-emptive bug fix, fixing all kinds of weird bugs.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-18 19:17:34 +01:00
Leah Rowe 2acdfefdf9 inject.sh: bring in sync with lbmk 0f931b508a8
see lbmk commit:
0f931b508a8eb34e70b2ed3628ac4fe74f22b8e8
from 10 May 2025

The lbmk version of inject.sh also contained logic to
download vendor files, which cbmk doesn't and won't support.

This made merging patches between the two projects harder, so
lbmk's version has been modified to mostly only include the MAC
address related code on inject.sh, just like the Canoeboot one.

On lbmk, extra functionality for vendor files is now provided
on include/vendor.sh, which cbmk lacks (and will never have).

With a few minor alterations, this script is now very much in
sync with the lbmk version.

In fact, just to provide the point, here is the diff between
lbmk's version of inject.sh, compared to the version in cbmk
introduced by this commit. Observe:

(< is a subtracted line, and > is an added line. So the < shows
what was removed from lbmk's version when adding to cbmk, and
the > lines show what cbmk added to its version).

yes me cbmk$ colordiff ../lbmk/include/inject.sh include/inject.sh
89,90d88
< 	[ -n "$vcfg" ] && check_vcfg
<
94,95d91
< 	mecleaner="$xbmkpwd/$cbdir/util/me_cleaner/me_cleaner.py"
< 	kbc1126_ec_dump="$xbmkpwd/$cbdir/util/kbc1126/kbc1126_ec_dump"
103,104d98
< 	[ "$nukemode" = "nuke" ] || x_ ./mk download "$board"
<
112,113c106,107
< 		e "$tmpromdir/$_hashes" f && \
< 		    has_hashes="y" && hashfile="$_hashes" && break; :
---
> 		e "$tmpromdir/$_hashes" f && err \
> 		    "'$archive': vendorfile insertion unsupported"
118,120d111
< 	fx_ prep x_ find "$tmpromdir" -maxdepth 1 -type f -name "*.rom"
< 	( check_vendor_hashes ) || err "Can't verify hashes for '$archive'"; :
<
129d119
< 	setvfile && return 1; :

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-10 18:20:44 +01:00
Leah Rowe a170ab4118 cbmk: use x_ instead of err, where appropriate
many places in cbmk used err, because older versions
of x_ did not handle globbing properly.

however, use of x_ is preferable on trivial commands.

the only time err() should be called is what it has
to be, when x_ can't work, or when a more useful error
message is needed, for context.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-10 18:09:43 +01:00
Leah Rowe e320ce60a7 init.sh: Only check XBMK_CACHE if it exists
Otherwise, if it doesn't exist, the current check will
wrongly exit with error status, preventing you from
running the build system at all!

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-08 22:19:01 +01:00
Leah Rowe 63cef86bdb init.sh: remove useless export
we already reset to n if not y, afterward

just rely on that

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-08 16:09:41 +01:00
Leah Rowe 0a3793ad4e init.sh: also allow XBMK_RELEASE=Y or N
as opposed to =n or =y

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-08 16:09:34 +01:00
Leah Rowe 433b5de916 init.sh: Resolve XBMK_CACHE via readlink
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-08 16:09:26 +01:00
Leah Rowe 5d2c94a8bd init.sh: check XBMK_CACHE is a directory instead
it doesn't matter if it's not a file. that's the wrong check.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-08 16:09:20 +01:00
Leah Rowe f0a0f678bf init.sh: export LOCALVERSION in set_env
Don't do it in set_version

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-08 16:09:14 +01:00
Leah Rowe 542d72192d init.sh: run set_version before set_env
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-08 16:09:08 +01:00
Leah Rowe 9ccfee43e7 init.sh: Use readlink in pybin()
Use realpath only as a fallback.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-08 16:09:03 +01:00
Leah Rowe e47324619d lbmk: Replace err with much simpler implementation
The current implementation is insanely over-engineered,
and completely unnecessary.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-06 04:44:03 +01:00
Leah Rowe 5b2d537123 init.sh: Silence the output of git config --global
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-04 17:45:02 +01:00
Leah Rowe edfa4a0ddd init.sh: Run git name/email check before init
Otherwise, it returns if init is already done, which
later leads to build errors in coreboot.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-04 17:44:57 +01:00
Leah Rowe 15afad4a2b init.sh: single-quote xbmklock in xbmk_lock()
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-04 17:44:35 +01:00
Leah Rowe 41bc473276 init.sh: define lock file in a variable instead
don't hardcode it.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-04 17:44:26 +01:00
Leah Rowe 4415865ccc init.sh: tidy up xbmk_child_exec()
make the command style more consistent, for example
relying on x_ inside a subshell to print the command
and arguments if a command failed.

this is a good style, and i'll probably use it in other
places on lbmk.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-04 17:44:21 +01:00
Leah Rowe cd979e3b09 lbmk: MUCH safer err function
Don't directly call a variable. Call a function that
checks the variable instead.

The new err function also checks whether an exit was
actually done, and exits 1 if not.

If an exit was done by the given function, but the exit
was zero, this is also corrected to perform an exit 1.

This fixes a longstanding design flaw of lbmk.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-04 17:43:18 +01:00
Leah Rowe 6e14ab7c09 init.sh: tidy up the python version check
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-04 17:36:32 +01:00
Leah Rowe 7944fd6297 init.sh: move non-init functions to lib.sh
these were missed in a previous cleanup

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-04 17:36:27 +01:00
Leah Rowe 159ded1c4e init.sh: simplify dependencies handling
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-04 17:36:23 +01:00
Leah Rowe e05787d82f init.sh: tidy up pathdir creation
we can use remkdir here. it does the same thing.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-04 17:36:00 +01:00
Leah Rowe bb5228dc32 init.sh: *Re-create* tmpdirs on parent instance
To make sure any old files are removed, always re-create.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-04 17:32:53 +01:00
Leah Rowe 0c05289152 init.sh: Always create xbmklocal
If we're in a release work directory, TMPDIR is already
set, so the local ./tmp won't be created, which would
lead to an error.

Fix it by creating xbmklocal before checking TMPDIR.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-04 17:32:47 +01:00
Leah Rowe b2c14b6759 lbmk: Unified local ./tmp handling
Make it an absolute directory, relative to xbmktmp.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-04 17:32:24 +01:00
Leah Rowe 2d05cd260d init.sh: Explicitly create the xbmktmp directory
mktemp would normally do it, but we must not rely on that

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-04 17:29:02 +01:00
Leah Rowe e32a6c96d5 init.sh: unified handling of ./tmp
not to be confused with /tmp

we use ./tmp inside the lbmk work directory, for large files,
because /tmp might not be very big, or might be a tmpfs

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-04 17:28:12 +01:00
Leah Rowe 6348e8a93e move x_() to lib.sh
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-04 17:17:58 +01:00
Leah Rowe a30fd38ae4 init.sh: move setvars/err_ to lib.sh
these functions make more sense in lib.sh

i made mk link lib.sh first, so that the
functions on init.sh can still use them.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-04 17:17:53 +01:00
Leah Rowe db162c3662 init.sh: fix yet another double quote for dotfiles
i missed this one, in another recent revision

double-quote because of the dot, for bash users

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-30 15:47:02 +01:00
Leah Rowe 34d134f2f2 init.sh: don't use eval to read version files
it's not necessary, and was the cause of a recent issue,
which i mitigated, but why mitigate it?

prevent bugs. don't use eval unless absolutely necessary.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-30 15:46:16 +01:00
Leah Rowe b63612871d init.sh: use backslash for dotfiles in eval
see:

commit f0c629dcc6c3f2242a735567cdd6855fa108d1a5
Author: Leah Rowe <leah@libreboot.org>
Date:   Sat Apr 12 13:51:49 2025 +0100

    lib.sh: write version/versiondate to dotfiles

and this bug report:

https://codeberg.org/libreboot/lbmk/issues/284

The report indicates that the above commit broke bash,
when sh (on the user's system) is bash.

I know sometimes when using bash, I need to use the
back slash when dealing with dots, e.g. when grepping
something.

Also double quote references to dotfiles, e.g. when
directing the output of printf.

I never noticed the issue myself, since I use dash.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-30 15:46:10 +01:00
Leah Rowe 4ff7cd3d77 init.sh: make git name/email error more useful
instruct the user what to do in these conditions

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-30 15:45:25 +01:00
Leah Rowe ec287ca69e init.sh: move git name/mail check to xbmk_git_init
the command -v check has been removed, since this function
already calls git immediately, which would accomplish the
same thing since that causes an error if git isn't there.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-30 15:45:19 +01:00
Leah Rowe f89e5ad87a init.sh: tidy up the git name/email check
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-30 15:45:13 +01:00
Leah Rowe f3caaf394e mk: move git check to init.sh xbmk_set_version
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-30 15:44:24 +01:00
Leah Rowe f30892e92f init.sh: tidy up xbmk_init()
more version-related code moved to xbmk_set_version

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-30 15:44:18 +01:00
Leah Rowe cbf486789d mk: move git_init to init.sh
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-30 15:44:14 +01:00