2023-10-26 19:11:40 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2025-01-03 18:09:03 +00:00
|
|
|
# Copyright (c) 2020-2025 Leah Rowe <leah@libreboot.org>
|
2024-05-26 00:54:36 +00:00
|
|
|
# Copyright (c) 2022 Caleb La Grange <thonkpeasant@protonmail.com>
|
2023-10-26 19:11:40 +00:00
|
|
|
|
|
|
|
set -u -e
|
|
|
|
|
2024-05-09 13:48:14 +00:00
|
|
|
if [ "./${0##*/}" != "${0}" ] || [ ! -f "build" ] || [ -L "build" ]; then
|
2024-05-16 02:59:23 +00:00
|
|
|
printf "You must run this in the proper work directory.\n" 1>&2
|
2024-05-09 13:31:43 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-05-26 11:10:27 +00:00
|
|
|
. "include/lib.sh"
|
inject.sh: MAC address changer (not vendorfiles)
This is based on include/vendor.sh from this lbmk
revision:
3c9f4be76f61c80060b4238eff96ef268272cffb
This version doesn't support downloading/injecting
vendor files such as Intel ME; that's what the lbmk
version is for.
If you try to run this on a Libreboot archive that
uses vendor files, the script will see that there is
a hash file present, and not inject a new MAC.
HOWEVER: if the hash file is not present, it will
work just fine, but again only change the MAC. That
way, you can use the "./mk inject" command from lbmk,
to insert files such as Intel ME. In practise, due to
the design checking out a specific cbfstool version
based on the board config, you can only use a config
in this way that's present on both Libreboot and
Canoeboot, such as the E6400 images; the E6400 images
on Libreboot insert an Nvidia GPU ROM, but Canoeboot
does not.
You don't need to run this on Libreboot tarballs, because
the Libreboot version can be used anyway. Canoeboot is
mostly a pointless project, but I maintain it for fun. I
make it adhere to GNU FSDG for fun, even though I disagree
with it; Libreboot's binary blob reduction policy is better.
The reason for this design is because of GNU FSDG,
which Canoeboot complies with to the letter. It states
that any such project must not distribute, promote or
otherwise boost proprietary software in any way; it must
steer the user only towards entirely free software.
It also doesn't support nuking. It only sets MAC
addresses; the "setmac keep" command is not present,
because it's pointless, but these work, e.g.:
./mk inject tarball.tar.xz
./mk inject tarball.tar.xz setmac
./mk inject tarball.tar.xz setmac restore
./mk inject tarball.tar.xz MACADDRESS
./mk inject tarball.tar.xz ??:aa:bb:??:22:01
etc
Same command structure as setmac for lbmk.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-07 07:32:12 +00:00
|
|
|
. "include/inject.sh"
|
2023-10-26 19:11:40 +00:00
|
|
|
|
2025-01-02 23:52:45 +00:00
|
|
|
eval "`setvars "" vdir src_dirname srcdir mode xp ser`"
|
safer, simpler error handling in cbmk
in shell scripts, a function named the same as a program included in
the $PATH will override that program. for example, you could make a
function called ls() and this would override the standand "ls".
in cbmk, a part of it was first trying to run the "fail" command,
deferring to "err", because some scripts call fail() which does
some minor cleanup before calling err.
in most cases, fail() is not defined, and it's possible that the user
could have a program called "fail" in their $PATH, the behaviour of
which we could not determine, and it could have disastrous effects.
cbmk error handling has been re-engineered in such a way that the
err function is defined in a variable, which defaults to err_ which
calls err_, so defined under include/err.sh.
in functions that require cleanup prior to error handling, a fail()
function is still defined, and err is overridden, thus:
err="fail"
this change has made xx_() obsolete, so now only x_ is used. the x_
function is a wrapper that can be used to run a command and exit with
non-zero status (from cbmk) if the command fails. the xx_ command
did the same thing, but called fail() which would have called err();
now everything is $err
example:
rm -f "$filename" || err "could not delete file"
this would now be:
rm -f "$filename" || $err "could not delete file"
overriding of err= must be done *after* including err.sh. for
example:
err="fail"
. "include/err.sh"
^ this is wrong. instead, one must do:
. "include/err.sh"
err="fail"
this is because err is set as a global variable under err.sh
the new error handling is much cleaner, and safer. it also reduces
the chance of mistakes such as: calling err when you meant to
call fail. this is because the standard way is now to call $err,
so you set err="fail" at the top of the script and all is well.
Signed-off-by: Leah Rowe <info@minifree.org>
2024-03-27 01:19:39 +00:00
|
|
|
err="fail"
|
2023-10-26 19:11:40 +00:00
|
|
|
|
|
|
|
main()
|
|
|
|
{
|
2024-06-22 02:55:04 +00:00
|
|
|
[ $# -lt 1 ] && $err "bad command"
|
2024-07-22 22:35:26 +00:00
|
|
|
spath="script/$1"; shcmd="shift 1"
|
|
|
|
[ "${1#-*}" != "$1" ] && spath="script/trees" && shcmd=":"
|
2023-10-26 19:11:40 +00:00
|
|
|
|
2024-12-30 19:23:27 +00:00
|
|
|
for g in "command -v git" "git config --global user.name" \
|
2024-05-25 15:34:07 +00:00
|
|
|
"git config --global user.email" "git_init"; do
|
2025-01-03 15:56:41 +00:00
|
|
|
eval "$g 1>/dev/null 2>/dev/null || $err \"Unconfigured: $g\""
|
2024-05-25 15:34:07 +00:00
|
|
|
done
|
2024-05-15 03:02:48 +00:00
|
|
|
|
2024-07-22 22:35:26 +00:00
|
|
|
case "${spath#script/}" in
|
2024-06-02 22:34:10 +00:00
|
|
|
version) printf "%s\nWebsite: %s\n" "$relname" "$projectsite" ;;
|
inject.sh: MAC address changer (not vendorfiles)
This is based on include/vendor.sh from this lbmk
revision:
3c9f4be76f61c80060b4238eff96ef268272cffb
This version doesn't support downloading/injecting
vendor files such as Intel ME; that's what the lbmk
version is for.
If you try to run this on a Libreboot archive that
uses vendor files, the script will see that there is
a hash file present, and not inject a new MAC.
HOWEVER: if the hash file is not present, it will
work just fine, but again only change the MAC. That
way, you can use the "./mk inject" command from lbmk,
to insert files such as Intel ME. In practise, due to
the design checking out a specific cbfstool version
based on the board config, you can only use a config
in this way that's present on both Libreboot and
Canoeboot, such as the E6400 images; the E6400 images
on Libreboot insert an Nvidia GPU ROM, but Canoeboot
does not.
You don't need to run this on Libreboot tarballs, because
the Libreboot version can be used anyway. Canoeboot is
mostly a pointless project, but I maintain it for fun. I
make it adhere to GNU FSDG for fun, even though I disagree
with it; Libreboot's binary blob reduction policy is better.
The reason for this design is because of GNU FSDG,
which Canoeboot complies with to the letter. It states
that any such project must not distribute, promote or
otherwise boost proprietary software in any way; it must
steer the user only towards entirely free software.
It also doesn't support nuking. It only sets MAC
addresses; the "setmac keep" command is not present,
because it's pointless, but these work, e.g.:
./mk inject tarball.tar.xz
./mk inject tarball.tar.xz setmac
./mk inject tarball.tar.xz setmac restore
./mk inject tarball.tar.xz MACADDRESS
./mk inject tarball.tar.xz ??:aa:bb:??:22:01
etc
Same command structure as setmac for lbmk.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-07 07:32:12 +00:00
|
|
|
inject) shift 1; xbmk_inject "$@" ;;
|
2024-12-30 00:50:53 +00:00
|
|
|
release) shift 1; mkrelease "$@" ;;
|
rom.sh: new file, to replace script/roms
stub it from the trees script. the way it works now,
there is less code in the build system.
./build roms
this is no longer a thing
./build roms serprog
this is also no longer a thing. instead, do:
./update trees -b coreboot targetnamehere
./update trees -b pico-serprog
./update trees -b stm32-vserprog
the old commands still works, which causes the new
commands to run
coreboot roms now appear in elf/, not bin/, as before,
but those images now contain payloads.
NOTE: to contradict the above: ./build roms is no
longer a thing, in that it's now deprecated, but
backward compatibility is present for now. it will
be removed in a future release.
./build roms list also still works! it will do:
./update trees -b coreboot list
also:
./update trees -b grub list
this is now possible too
if a target "list" is provided, for multi-tree sources,
the targets are shown.
there is another difference: seagrub roms are now seagrub_,
instead of seabios_withgrub.
seabios-only roms are no longer provided, where grub is also
enabled; only seagrub is used. the user can easily remove
the bootorder file, if they want seabios to not try grub first.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-07-06 22:36:13 +00:00
|
|
|
roms)
|
lib.sh: new function mk() to handle trees in bulk
single-tree projects cannot be handled in bulk, e.g.
./mk -f project1 project2 project3
that is still the case, from the shell, but internally
it is now possible:
mk -f project1 project2 project3
mk() is a function that simply handles the given flag,
and all projects specified.
it does not handle cases without argument, for example
you cannot do:
mk -f
arguments must be provided. it can be used internally,
to simplify cases where multiple single-tree projects
must be handled, but *also* allows multi-tree projects
to be specified, without being able to actually handle
trees within that multi-tree project; so for example,
you can only specify coreboot, and then it would run
on every coreboot tree.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-07-28 12:30:25 +00:00
|
|
|
[ $# -gt 1 ] && [ "$2" = "serprog" ] && \
|
|
|
|
mk -b stm32-vserprog pico-serprog && return 0
|
2024-12-30 00:50:53 +00:00
|
|
|
shift 1; x_ ./mk -b coreboot "$@" ;;
|
2024-05-16 10:34:31 +00:00
|
|
|
*)
|
2024-06-22 02:55:04 +00:00
|
|
|
[ -f "$spath" ] || $err "bad command"
|
2024-12-30 00:50:53 +00:00
|
|
|
$shcmd; "$spath" "$@" || $err "excmd: $spath $(echo "$@")" ;;
|
2023-10-26 19:11:40 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
git_init()
|
|
|
|
{
|
2024-05-25 15:56:44 +00:00
|
|
|
[ -L ".git" ] && return 1
|
2023-10-26 19:11:40 +00:00
|
|
|
[ -e ".git" ] && return 0
|
2025-01-02 23:52:45 +00:00
|
|
|
eval "`setvars "$(date -Rud @$versiondate)" cdate _nogit`"
|
2023-10-26 19:11:40 +00:00
|
|
|
|
2024-05-25 15:56:44 +00:00
|
|
|
git init || return 1
|
|
|
|
git add -A . || return 1
|
2024-05-26 00:54:36 +00:00
|
|
|
git commit -m "$projectname $version" --date "$cdate" \
|
2024-05-25 15:56:44 +00:00
|
|
|
--author="xbmk <xbmk@example.com>" || return 1
|
2024-05-26 00:54:36 +00:00
|
|
|
git tag -a "$version" -m "$projectname $version" || return 1
|
2023-10-26 19:11:40 +00:00
|
|
|
}
|
|
|
|
|
2024-05-11 02:52:52 +00:00
|
|
|
mkrelease()
|
|
|
|
{
|
2024-05-16 02:59:23 +00:00
|
|
|
export XBMK_RELEASE="y"
|
2024-05-11 02:52:52 +00:00
|
|
|
|
|
|
|
vdir="release"
|
|
|
|
while getopts d:m: option; do
|
2024-06-22 02:55:04 +00:00
|
|
|
[ -z "$OPTARG" ] && $err "empty argument not allowed"
|
2024-05-26 00:54:36 +00:00
|
|
|
case "$option" in
|
|
|
|
d) vdir="$OPTARG" ;;
|
|
|
|
m) mode="$OPTARG" ;;
|
2024-06-22 02:55:04 +00:00
|
|
|
*) $err "invalid option '-$option'" ;;
|
2024-05-11 02:52:52 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
vdir="$vdir/$version"
|
2024-05-11 02:52:52 +00:00
|
|
|
src_dirname="${relname}_src"
|
2024-05-26 00:54:36 +00:00
|
|
|
srcdir="$vdir/$src_dirname"
|
2024-05-11 02:52:52 +00:00
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
[ -e "$vdir" ] && $err "already exists: \"$vdir\""
|
|
|
|
mkdir -p "$vdir" || $err "mkvdir: !mkdir -p \"$vdir\""
|
|
|
|
git clone . "$srcdir" || $err "mkdir: !gitclone \"$srcdir\""
|
2024-06-09 14:47:51 +00:00
|
|
|
touch "$srcdir/lock" || $err "can't make lock file in $srcdir/"
|
2024-05-11 02:52:52 +00:00
|
|
|
|
|
|
|
build_release
|
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
printf "\n\nDONE! Check release files under %s\n" "$vdir"
|
2024-05-11 02:52:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
build_release()
|
|
|
|
{
|
|
|
|
(
|
2024-06-27 21:18:01 +00:00
|
|
|
cd "$srcdir" || $err "$vdir: !cd \"$srcdir\""
|
2024-07-26 14:24:00 +00:00
|
|
|
./mk -f; x_ rm -Rf tmp; rmgit .
|
2024-05-15 02:19:32 +00:00
|
|
|
x_ mv src/docs docs
|
2024-05-11 02:52:52 +00:00
|
|
|
) || $err "can't create release files"
|
|
|
|
|
|
|
|
git log --graph --pretty=format:'%Cred%h%Creset %s %Creset' \
|
2024-05-26 00:54:36 +00:00
|
|
|
--abbrev-commit > "$srcdir/CHANGELOG" || $err "!gitlog $srcdir"
|
2024-06-09 14:47:51 +00:00
|
|
|
rm -f "$srcdir/lock" || $err "can't remove lock file in $srcdir"
|
2024-05-11 02:52:52 +00:00
|
|
|
|
|
|
|
(
|
2024-06-27 21:18:01 +00:00
|
|
|
cd "${srcdir%/*}" || $err "$vdir: mktarball \"$srcdir\""
|
|
|
|
mktarball "${srcdir##*/}" "${srcdir##*/}.tar.xz" || $err "$vdir: mksrc"
|
2024-05-11 02:52:52 +00:00
|
|
|
) || $err "can't create src tarball"
|
2024-05-26 00:54:36 +00:00
|
|
|
[ "$mode" = "src" ] && return 0
|
2024-05-11 02:52:52 +00:00
|
|
|
|
2024-06-09 14:47:51 +00:00
|
|
|
touch "$srcdir/lock" || $err "can't make lock file in $srcdir/"
|
2024-05-11 02:52:52 +00:00
|
|
|
(
|
2024-06-27 21:18:01 +00:00
|
|
|
cd "$srcdir" || $err "$vdir: 2 !cd \"$srcdir\""
|
2024-10-08 15:16:30 +00:00
|
|
|
mk -b coreboot pico-serprog stm32-vserprog pcsx-redux
|
2024-05-15 00:41:19 +00:00
|
|
|
x_ mv bin ../roms
|
2024-05-11 02:52:52 +00:00
|
|
|
) || $err "can't build rom images"
|
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
rm -Rf "$srcdir" || $err "!rm -Rf $srcdir"
|
2024-05-11 02:52:52 +00:00
|
|
|
}
|
|
|
|
|
2023-10-26 19:11:40 +00:00
|
|
|
fail()
|
|
|
|
{
|
2024-06-27 02:18:23 +00:00
|
|
|
tmp_cleanup || printf "WARNING: can't rm tmpfiles: %s\n" "$TMPDIR" 1>&2
|
safer, simpler error handling in cbmk
in shell scripts, a function named the same as a program included in
the $PATH will override that program. for example, you could make a
function called ls() and this would override the standand "ls".
in cbmk, a part of it was first trying to run the "fail" command,
deferring to "err", because some scripts call fail() which does
some minor cleanup before calling err.
in most cases, fail() is not defined, and it's possible that the user
could have a program called "fail" in their $PATH, the behaviour of
which we could not determine, and it could have disastrous effects.
cbmk error handling has been re-engineered in such a way that the
err function is defined in a variable, which defaults to err_ which
calls err_, so defined under include/err.sh.
in functions that require cleanup prior to error handling, a fail()
function is still defined, and err is overridden, thus:
err="fail"
this change has made xx_() obsolete, so now only x_ is used. the x_
function is a wrapper that can be used to run a command and exit with
non-zero status (from cbmk) if the command fails. the xx_ command
did the same thing, but called fail() which would have called err();
now everything is $err
example:
rm -f "$filename" || err "could not delete file"
this would now be:
rm -f "$filename" || $err "could not delete file"
overriding of err= must be done *after* including err.sh. for
example:
err="fail"
. "include/err.sh"
^ this is wrong. instead, one must do:
. "include/err.sh"
err="fail"
this is because err is set as a global variable under err.sh
the new error handling is much cleaner, and safer. it also reduces
the chance of mistakes such as: calling err when you meant to
call fail. this is because the standard way is now to call $err,
so you set err="fail" at the top of the script and all is well.
Signed-off-by: Leah Rowe <info@minifree.org>
2024-03-27 01:19:39 +00:00
|
|
|
err_ "${1}"
|
2023-10-26 19:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tmp_cleanup()
|
|
|
|
{
|
2024-06-27 02:18:23 +00:00
|
|
|
[ "$xbmk_parent" = "y" ] || return 0
|
2024-06-27 02:20:18 +00:00
|
|
|
[ "$TMPDIR" = "/tmp" ] || rm -Rf "$TMPDIR" || return 1
|
2024-06-09 14:37:13 +00:00
|
|
|
rm -f lock || return 1
|
2023-10-26 19:11:40 +00:00
|
|
|
}
|
|
|
|
|
2024-12-30 00:50:53 +00:00
|
|
|
main "$@"
|
2024-06-27 02:18:23 +00:00
|
|
|
tmp_cleanup || err_ "can't rm TMPDIR upon non-zero exit: $TMPDIR"
|