summaryrefslogtreecommitdiff
path: root/include/lib.sh
AgeCommit message (Collapse)Author
2025-05-02lib.sh: simplify remkdir()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-02move x_() to lib.shLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-05-02init.sh: move setvars/err_ to lib.shLeah Rowe
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-04-29lib.sh: Provide printf for mktarballLeah Rowe
Just to let the user know lbmk hasn't died. Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-26lib.sh: move _ua to the xbmkget functionLeah Rowe
don't declare it globally, because it's only used here Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-26move variables out of init.sh to othersLeah Rowe
move them where they are used, or if they are used in many places, move them to lib.sh Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-26lib.sh: rename vendor_checksumLeah Rowe
rename it to bad_checksum, so that its use makes more sense Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-26lib.sh: move singletree() to git.shLeah Rowe
it is primarily used there, and then in mk, but only after git.sh is sourced. Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-26lib.sh: move cbfs() to rom.shLeah Rowe
it is only ever used there, so move it there Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-26re-split include/init.sh to lib.shLeah Rowe
move non-init functions to lib.sh Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-26rename include/lib.sh to init.shLeah Rowe
this is in prep for the next change, where non-init functions will be moved to another file, again named include/lib.sh Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-26lib.sh: introduce more top-down function orderLeah Rowe
a lot of init code was handled outside of any function. the coding style used in the rest of the build system has now been introduced, with xbmk_init being the main function. Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-26mk: simplify main()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-26lib.sh: use realpath to get sys python on venvLeah Rowe
In the previous revision, I make hardcoded use of /usr/local/bin and /usr/bin as search locations, instead of relying on PATH, when the user has a python venv, because in those cases, we cannot rely on PATH so we use a python command to detect the venv and then force use of the normal system path for python. However, there's no guarantee that the real Python will indeed live at these locations. For example, some distros like Nix or Guix will use many locations for different versions of a given package, and it's for the birds as to what given package version the user might be running. Therefore, this patch retains that current hardcoded assumption of /usr/local/bin and /usr/bin but *only* as a fallback solution, instead checking realpath first. The "realpath" command isn't technically POSIX standard, but in practise it is available on GNU coreutils, Busybox, and the various BSD userlands. I could perhaps *import* a realpath utility, and use that, but this should be fine. Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-26lib.sh: Force use of System Python to prevent hangLeah Rowe
If the user has a virtual environment, the current logic will cause lbmk to hang. A useful workaround is to force use of the direct path to the system binary of python. This works by detecting a virtual environment first, and deferring to the old behaviour if no venv is found. If one is found, then it will not rely on PATH, but instead only search the standard locations /usr/local/bin and /usr/bin. Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-23lib.sh: further condense the python checkLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-23lib.sh: further simplify the python checkLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-23lib.sh: condense the python checkLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-23lib.sh: simplify mk()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-23lib.sh: simplify cbfs()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-23lib.sh: simplify the python checkLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-22lib.sh: add missing copyright yearLeah Rowe
alper made a fix to this file a few hours ago, but forgot to update the copyright header i'm doing it for alper, as a courtesy Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-21lib.sh: Fix python3 detection when 'python' is python2Alper Nebi Yasak
Properly set $pyver to "3" when we detect we can use python3. In the following version checks, use the $python we detected instead of a 'python' from PATH because the latter might be a python2 while still co-existing with a python3. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2025-04-18lib.sh: perform root check even earlierLeah Rowe
initialising variables, setting PWD, setting version, this is all unnecessary before the root check, because the dependencies commands use none of these. Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-18lib.sh: tidy up opening logic (put it together)Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-18lib.sh: do root check before python checkLeah Rowe
we don't need python before the root check principle of least privilege Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-18lib.sh: simplify mktarball()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-18lib.sh: fix missing s/TMPDIR/xbmktmpLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-17lbmk: don't handle TMPDIR directlyLeah Rowe
lbmk creates TMPDIR as /tmp/xbmk_*, but it's theoretically possible that something could re-export it by mistake. this change retains the same initialisation, but further use is now via a new variable "xbmktmp", that stores the value of TMPDIR upon lbmk's initialisation of it. this reduces the chance of such a bug in the future, as described above, so it is a preemptive/preventative fix. Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-16lib.sh mktarball: stricter tar error handlingLeah Rowe
There was no error handling, *at all*, on the actual tar command, due to the lack of set -o pipefail, which we cannot rely on in sh. The x_ wrapper can be used in this case, as a mitigation. Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-13Revert "lib.sh: use eval for the command in x_"Leah Rowe
This reverts commit 3bfdecdc75bbc77f795736ac282f858f2eb7ab94. The commit that this reverses, caused sch5545 ec firmware downloads to fail, due to globbing.
2025-04-13lib.sh: fix bad eval writing version/versiondateLeah Rowe
x_ cannot be used, where output is redirected to a file; only the convention piping can be used, for errors. relying on x_ in these cases will cause unpredictable bugs. Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-13lib.sh: use eval for the command in x_Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-12lib.sh: tidy up the error handlingLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-12remove xbmk_parent, handle forking in lib.shLeah Rowe
I was using a complicated method of knowing whether the current instance was parent or a child, to know whether the lock file and TMPDIR needed to be purged. It was quite error-prone too. Instead, I'm now handling it directly from within the if statement that previously initialised xbmk_parent=y, forking ./mk from there. The forked instance would not trigger that if clause again, since then TMPDIR is created, thus avoiding recursion. This is an improvement because it doesn't rely on how the parent handles exit statuses, and it ensures that the lock/tmp files are never accidentally deleted. Even if a given program/script that lbmk runs would export TMPDIR, it doesn't matter because lbmk doesn't, so it would be unaffected. Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-12lib.sh: define x_ right after err_Leah Rowe
because the top-down function order isn't as reliable in lib.sh, since this is what first runs, included in every other script Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-12lib.sh: minor cleanupLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-12lib.sh: write version/versiondate to dotfilesLeah Rowe
write to .version and .versiondate, instead of version and versiondate. this will hide them to avoid visual clutter while analysing files within lbmk. Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-12lib.sh: hardcode projectname/projectsiteLeah Rowe
remove the corresponding files, containing these strings Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-11lib.sh: double-quote pwd to prevent globbingLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-11lbmk: unified PWD handling (work directory)Leah Rowe
instead of running pwd all the time, run it once in lib.sh, and export PWD. for lbmk-specific use of PWD, use xbmkpwd, which contains the value of PWD as was set by the pwd utility in lib.sh. many parts of lbmk rely on pwd, and it *must* be correct. this change adds basic error handling, since pwd can in fact return errors in some cases. Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-11lib.sh: initialise PATH if it's unsetLeah Rowe
it's incorrect for PATH not to be set, but some users may foolishly blank it out before running lbmk. prevent such issues, by initialising it. Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-11move XBMKPATH to include/lib.shLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-11lbmk: use pwd util, not PWD environmental variableLeah Rowe
PWD could be anything, if the user manually exported it before running lbmk. always run pwd instead, to get the real string. Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-11clean up a few semicolons in the build systemLeah Rowe
several code lines were condensed together, which make them less readable. make the code more readable by having separate commands on separate lines. i previously did this during my manic build system audits of 2023 and 2024; condensing lines like this is overly pedantic and serves no real purpose. Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-06lib.sh: Much safer python version checkLeah Rowe
See: https://docs.python.org/3/library/sys.html#sys.version_info The sys.version_info tuple is a more reliable way to get the version. Our previous logic assumed that Python would always output "Python versionnumber", but this may not always be how it works. We've seen this for example where Debian modifies some GNU toolchains to include Debian something in the output. Python has a standard method built in for outputting exact the information we need. In my system, what I got was this: (3, 11, 2, 'final', 0) That output was from running this command: python -c 'import sys; print(sys.version_info[:])' This is much more robust, so use this instead. Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-05set up python in PATH, ensuring that it is python3Leah Rowe
we already check the python version, and set a variable for it, so that we can reliably use python3, even if python in PATH doesn't correspond to python3. for example if a system has python as python2 and python3 as python3 well, we use that when running deguard for example, but various upstream projects that we use may need python, and all of them use python3, not 2 so, re-use the python variable set up by lbmk, and set it up in PATH accordingly. this now makes the note about python3 obsolete, on docs/build.md in lbwww.git Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-03lib.sh: Set python after dependenciesLeah Rowe
otherwise, the user can't install python, which is in the dependencies. an irony! Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-03lib.sh: Fix unescaped quotes in chkvars()Leah Rowe
This should be the proper fix now Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-03Revert "fix more unescaped quotes in eval"Leah Rowe
This reverts commit ec6bcc1fba5fbdf8b19b3d1cf9711f3d4c9c3741.