2023-10-06 01:12:52 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2024-05-11 02:52:52 +00:00
|
|
|
# SPDX-FileCopyrightText: 2014,2015,2020-2024 Leah Rowe <leah@libreboot.org>
|
2023-10-06 01:12:52 +00:00
|
|
|
# SPDX-FileCopyrightText: 2015 Patrick "P. J." McDermott <pj@pehjota.net>
|
|
|
|
# SPDX-FileCopyrightText: 2015, 2016 Klemens Nanni <contact@autoboot.org>
|
|
|
|
# SPDX-FileCopyrightText: 2022, Caleb La Grange <thonkpeasant@protonmail.com>
|
|
|
|
|
|
|
|
set -u -e
|
|
|
|
|
2024-05-09 13:48:14 +00:00
|
|
|
if [ "./${0##*/}" != "${0}" ] || [ ! -f "build" ] || [ -L "build" ]; then
|
2024-05-09 13:31:43 +00:00
|
|
|
printf "You must run this in the lbmk work directory.\n" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-10-06 01:12:52 +00:00
|
|
|
. "include/option.sh"
|
2024-05-11 04:33:43 +00:00
|
|
|
. "include/vendor.sh"
|
|
|
|
. "include/mrc.sh"
|
2023-10-06 01:12:52 +00:00
|
|
|
|
2024-05-15 02:55:44 +00:00
|
|
|
eval "$(setvars "" script_path aur_notice vdir src_dirname srcdir _xm mode xp)"
|
safer, simpler error handling in lbmk
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 lbmk, 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.
lbmk 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 lbmk) 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 <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
err="fail"
|
2023-10-07 01:06:33 +00:00
|
|
|
|
2023-10-06 01:12:52 +00:00
|
|
|
linkpath="${0}"
|
|
|
|
linkname="${linkpath##*/}"
|
|
|
|
|
|
|
|
main()
|
|
|
|
{
|
safer, simpler error handling in lbmk
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 lbmk, 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.
lbmk 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 lbmk) 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 <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
x_ id -u 1>/dev/null 2>/dev/null
|
|
|
|
[ $# -lt 1 ] && $err "Too few arguments. Try: ${0} help"
|
2023-10-06 01:12:52 +00:00
|
|
|
|
safer, simpler error handling in lbmk
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 lbmk, 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.
lbmk 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 lbmk) 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 <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
[ "$1" = "dependencies" ] && x_ install_packages $@ && lbmk_exit 0
|
2023-10-06 01:12:52 +00:00
|
|
|
|
2024-05-15 03:02:48 +00:00
|
|
|
which git 1>/dev/null 2>/dev/null || \
|
|
|
|
git_err "git not installed. please install git-scm."
|
|
|
|
git config --global user.name 1>/dev/null 2>/dev/null || \
|
|
|
|
git_err "git config --global user.name \"John Doe\""
|
|
|
|
git config --global user.email 1>/dev/null 2>/dev/null || \
|
|
|
|
git_err "git config --global user.email \"john.doe@example.com\""
|
|
|
|
|
|
|
|
for cmd in initcmd git_init excmd; do
|
2023-12-23 16:16:26 +00:00
|
|
|
eval "${cmd} \$@"
|
|
|
|
done
|
2023-10-06 01:12:52 +00:00
|
|
|
lbmk_exit 0
|
|
|
|
}
|
|
|
|
|
2023-12-23 16:16:26 +00:00
|
|
|
initcmd()
|
2023-10-06 01:12:52 +00:00
|
|
|
{
|
safer, simpler error handling in lbmk
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 lbmk, 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.
lbmk 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 lbmk) 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 <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
[ "$(id -u)" != "0" ] || $err "this command as root is not permitted"
|
2023-10-06 01:12:52 +00:00
|
|
|
|
2023-10-19 23:17:30 +00:00
|
|
|
case "${1}" in
|
2023-12-19 02:51:33 +00:00
|
|
|
help) usage ${0} ;;
|
2024-05-11 05:22:56 +00:00
|
|
|
list) items "script" ;;
|
2024-05-15 01:49:30 +00:00
|
|
|
version) printf "%s\n" "$relname" ;;
|
2024-05-11 02:52:52 +00:00
|
|
|
release) shift 1; mkrelease $@ ;;
|
2024-05-11 04:33:43 +00:00
|
|
|
inject) shift 1; vendor_inject $@ ;;
|
|
|
|
download) shift 1; vendor_download $@ ;;
|
2023-12-19 02:51:33 +00:00
|
|
|
*)
|
2024-05-11 05:22:56 +00:00
|
|
|
script_path="script/${1}"
|
2023-12-19 02:51:33 +00:00
|
|
|
return 0 ;;
|
2023-10-19 23:17:30 +00:00
|
|
|
esac
|
2024-05-11 04:33:43 +00:00
|
|
|
set -u -e # some commands disable them. turn them on!
|
2023-12-19 02:51:33 +00:00
|
|
|
lbmk_exit 0
|
2023-10-06 01:12:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
install_packages()
|
|
|
|
{
|
|
|
|
if [ $# -lt 2 ]; then
|
|
|
|
printf "You must specify a distro, namely:\n" 1>&2
|
|
|
|
printf "Look at files under config/dependencies/\n" 1>&2
|
|
|
|
printf "Example: ./build dependencies debian\n" 1>&2
|
safer, simpler error handling in lbmk
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 lbmk, 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.
lbmk 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 lbmk) 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 <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
$err "install_packages: target not specified"
|
2023-10-06 01:12:52 +00:00
|
|
|
fi
|
|
|
|
|
safer, simpler error handling in lbmk
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 lbmk, 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.
lbmk 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 lbmk) 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 <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
[ -f "config/dependencies/${2}" ] || $err "Unsupported target"
|
2023-10-06 01:12:52 +00:00
|
|
|
|
|
|
|
. "config/dependencies/${2}"
|
|
|
|
|
safer, simpler error handling in lbmk
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 lbmk, 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.
lbmk 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 lbmk) 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 <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
x_ ${pkg_add} ${pkglist}
|
2023-10-19 23:17:30 +00:00
|
|
|
[ -z "${aur_notice}" ] && return 0
|
2023-12-24 09:04:36 +00:00
|
|
|
printf "You must install AUR packages: %s\n" "$aur_notice" 1>&2
|
2023-10-06 01:12:52 +00:00
|
|
|
}
|
|
|
|
|
2023-10-20 20:10:26 +00:00
|
|
|
# release archives contain .gitignore, but not .git.
|
|
|
|
# lbmk can be run from lbmk.git, or an archive.
|
|
|
|
git_init()
|
|
|
|
{
|
safer, simpler error handling in lbmk
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 lbmk, 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.
lbmk 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 lbmk) 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 <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
[ -L ".git" ] && $err "Reference .git is a symlink"
|
2023-10-20 20:10:26 +00:00
|
|
|
[ -e ".git" ] && return 0
|
2024-05-15 02:10:25 +00:00
|
|
|
eval "$(setvars "$(date -Rud @${versiondate})" cdate _nogit)"
|
2023-10-20 20:10:26 +00:00
|
|
|
|
safer, simpler error handling in lbmk
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 lbmk, 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.
lbmk 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 lbmk) 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 <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
git init || $err "${PWD}: cannot initialise Git repository"
|
|
|
|
git add -A . || $err "${PWD}: cannot add files to Git repository"
|
2023-11-09 16:31:40 +00:00
|
|
|
git commit -m "${projectname} ${version}" --date "${cdate}" \
|
|
|
|
--author="lbmk <lbmk@libreboot.org>" || \
|
safer, simpler error handling in lbmk
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 lbmk, 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.
lbmk 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 lbmk) 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 <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
$err "$PWD: can't commit ${projectname}/${version}, date $cdate"
|
2023-10-20 20:10:26 +00:00
|
|
|
git tag -a "${version}" -m "${projectname} ${version}" || \
|
safer, simpler error handling in lbmk
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 lbmk, 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.
lbmk 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 lbmk) 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 <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
$err "${PWD}: cannot git-tag ${projectname}/${version}"
|
2023-10-20 20:10:26 +00:00
|
|
|
}
|
|
|
|
|
2023-12-23 16:16:26 +00:00
|
|
|
excmd()
|
2023-10-06 01:12:52 +00:00
|
|
|
{
|
2024-05-11 05:22:56 +00:00
|
|
|
[ -f "${script_path}" ] || $err "Bad command. Run: ${linkpath} help"
|
|
|
|
shift 1; "$script_path" $@ || $err "excmd: ${script_path} ${@}"
|
2023-10-06 01:12:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
progname=${0}
|
|
|
|
cat <<- EOF
|
2024-05-15 01:49:30 +00:00
|
|
|
$relname
|
2023-11-08 06:17:40 +00:00
|
|
|
|
2023-10-19 23:17:30 +00:00
|
|
|
USAGE: ${progname} <OPTION>
|
2023-10-06 01:12:52 +00:00
|
|
|
|
2023-10-19 23:17:30 +00:00
|
|
|
possible values for 'OPTION':
|
2024-05-11 05:22:56 +00:00
|
|
|
$(items "script")
|
2023-10-06 01:12:52 +00:00
|
|
|
|
2024-05-11 04:17:41 +00:00
|
|
|
Special commands (consult $projectname documentation):
|
2024-05-11 04:33:43 +00:00
|
|
|
./vendor inject
|
|
|
|
./vendor download
|
2024-05-11 04:17:41 +00:00
|
|
|
./update release
|
|
|
|
./build dependencies distroname
|
|
|
|
(replace distroname with a filename from config/dependencies/)
|
|
|
|
|
2023-11-09 16:40:36 +00:00
|
|
|
To know what ${projectname} version you're on, type:
|
2023-11-08 06:17:40 +00:00
|
|
|
${progname} version
|
|
|
|
|
2023-10-07 01:36:46 +00:00
|
|
|
Refer to ${projectname} documentation for more info.
|
2023-10-06 01:12:52 +00:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2024-05-11 02:52:52 +00:00
|
|
|
mkrelease()
|
|
|
|
{
|
|
|
|
export LBMK_RELEASE="y"
|
|
|
|
|
|
|
|
vdir="release"
|
|
|
|
while getopts d:m: option; do
|
|
|
|
[ -z "${OPTARG}" ] && $err "Empty argument not allowed"
|
|
|
|
case "${option}" in
|
|
|
|
d) vdir="${OPTARG}" ;;
|
|
|
|
m) mode="${OPTARG}" ;;
|
|
|
|
*) $err "Invalid option" ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
vdir="${vdir}/${version}"
|
|
|
|
src_dirname="${relname}_src"
|
|
|
|
srcdir="${vdir}/${src_dirname}"
|
|
|
|
|
|
|
|
[ -e "${vdir}" ] && $err "already exists: \"${vdir}\""
|
2024-05-14 23:42:27 +00:00
|
|
|
mkdir -p "${vdir}" || $err "mkvdir: !mkdir -p \"${vdir}\""
|
|
|
|
git clone . "${srcdir}" || $err "mkdir: !gitclone \"${srcdir}\""
|
2024-05-11 02:52:52 +00:00
|
|
|
|
|
|
|
build_release
|
|
|
|
|
2024-05-11 21:14:04 +00:00
|
|
|
printf "\n\nDONE! Check release files under %s\n" "${vdir}"
|
2024-05-11 02:52:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
build_release()
|
|
|
|
{
|
|
|
|
_xm="build_release ${vdir}"
|
|
|
|
(
|
|
|
|
cd "${srcdir}" || $err "${_xm}: !cd \"${srcdir}\""
|
|
|
|
fetch_trees
|
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' \
|
|
|
|
--abbrev-commit > "${srcdir}/CHANGELOG" || \
|
|
|
|
$err "build_release $srcdir: couldn't generate changelog"
|
|
|
|
|
|
|
|
(
|
2024-05-15 00:32:15 +00:00
|
|
|
cd "${srcdir%/*}" || $err "${_xm}: mktarball \"${srcdir}\""
|
|
|
|
mktarball "${srcdir##*/}" "${srcdir##*/}.tar.xz" || \
|
|
|
|
$err "$_xm: mksrc"
|
2024-05-11 02:52:52 +00:00
|
|
|
) || $err "can't create src tarball"
|
|
|
|
[ "${mode}" = "src" ] && return 0
|
|
|
|
|
|
|
|
(
|
|
|
|
cd "${srcdir}" || $err "${_xm}: 2 !cd \"${srcdir}\""
|
2024-05-15 00:41:19 +00:00
|
|
|
./build roms all || $err "${_xm}: roms-all"
|
|
|
|
./build roms serprog rp2040 || $err "${_xm}: rp2040"
|
|
|
|
./build roms serprog stm32 || $err "${_xm}: stm32"
|
|
|
|
x_ mv bin ../roms
|
2024-05-11 02:52:52 +00:00
|
|
|
) || $err "can't build rom images"
|
|
|
|
|
|
|
|
rm -Rf "${srcdir}" || $err "!rm -Rf ${srcdir}"
|
|
|
|
}
|
|
|
|
|
|
|
|
fetch_trees()
|
|
|
|
{
|
2024-05-15 02:39:28 +00:00
|
|
|
for x in $(items config/git); do
|
|
|
|
./update trees -f "$x" || $err "$_xm: fetch $x"
|
2024-05-11 02:52:52 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
for x in config/*/build.list; do
|
2024-05-15 02:53:26 +00:00
|
|
|
[ -f "$x" ] && xp="${x#*/}" && xp="${xp%/*}"
|
|
|
|
[ ! -f "$x" ] || [ -L "$xp" ] || x_ rm -Rf "src/$xp/$xp"
|
2024-05-11 02:52:52 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
find . -name ".git" -exec rm -Rf {} + || $err "$_xm: rm .git"
|
|
|
|
find . -name ".gitmodules" -exec rm -Rf {} + || $err "$_xm: rm .gitmod"
|
2024-05-15 01:56:58 +00:00
|
|
|
rm -Rf tmp .git src/u-boot/*/test/lib/strlcat.c || $err "$_xm !rm"
|
2024-05-11 02:52:52 +00:00
|
|
|
}
|
|
|
|
|
2023-10-06 01:12:52 +00:00
|
|
|
lbmk_exit()
|
|
|
|
{
|
safer, simpler error handling in lbmk
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 lbmk, 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.
lbmk 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 lbmk) 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 <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
tmp_cleanup || err_ "lbmk_exit: can't rm tmpdir upon exit $1: $tmpdir"
|
2023-10-06 01:12:52 +00:00
|
|
|
exit $1
|
|
|
|
}
|
|
|
|
|
|
|
|
fail()
|
|
|
|
{
|
2023-12-24 09:04:36 +00:00
|
|
|
tmp_cleanup || printf "WARNING: can't rm tmpdir: %s\n" "$tmpdir" 1>&2
|
safer, simpler error handling in lbmk
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 lbmk, 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.
lbmk 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 lbmk) 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 <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
err_ "${1}"
|
2023-10-06 01:12:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tmp_cleanup()
|
|
|
|
{
|
|
|
|
[ "${tmpdir_was_set}" = "n" ] || return 0
|
|
|
|
rm -Rf "${tmpdir}" || return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
main $@
|