2010-09-02 11:12:37 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
## live-build(7) - System Build Scripts
|
2020-03-11 09:07:21 -01:00
|
|
|
## Copyright (C) 2016-2020 The Debian Live team
|
2015-01-04 18:05:39 -01:00
|
|
|
## Copyright (C) 2006-2015 Daniel Baumann <mail@daniel-baumann.ch>
|
2010-09-02 11:12:37 +00:00
|
|
|
##
|
2012-07-29 23:59:00 +00:00
|
|
|
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
|
2010-09-02 11:12:37 +00:00
|
|
|
## This is free software, and you are welcome to redistribute it
|
|
|
|
## under certain conditions; see COPYING for details.
|
|
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Including common functions
|
frontend: avoid trying to load /scripts/build.sh
unless `LIVE_BUILD` is set in the environment when running live-build,
this var will be empty. this will result in the frontend trying to load
the file '/scripts/build.sh', which is doubtful the file intended to be
loaded, if it exists. the intention of checking the path
"${LIVE_BUILD}/scripts/build.sh" is really only to do so if the var is
actually used, so let's only do so if it's non-empty.
since we use `set -e`, if build.sh is not found in either location then
failure will occur. if it is found, presuming it is the real file that we
expect to be found, this file sets the var to a default if it was an empty
string, thus we need not worry about use of the var later in the frontend
script.
also, the var is exported prior to exec'ing the command script, so we know
that in the command scripts it is not going to be empty, and those in
themselves loading build.sh which again exports the var ensures that it
will be set for subsequent loads of component scripts (which happens to
go through the frontend again, not that that matters. so except for at the
start of execution, it should never be found to be empty.
Gbp-Dch: Short
2020-03-19 03:58:59 -01:00
|
|
|
[ -n "${LIVE_BUILD}" ] && [ -e "${LIVE_BUILD}/scripts/build.sh" ] && . "${LIVE_BUILD}/scripts/build.sh" || . /usr/lib/live/build.sh
|
2010-09-02 11:12:37 +00:00
|
|
|
|
|
|
|
# Setting static variables
|
2015-02-05 02:30:47 -01:00
|
|
|
DESCRIPTION="Utility to build live systems"
|
2020-02-25 08:00:06 -01:00
|
|
|
HELP=""
|
|
|
|
USAGE="lb {clean|config|build}"
|
2010-09-02 11:12:37 +00:00
|
|
|
|
2020-04-24 14:00:05 +00:00
|
|
|
# This bits of code relies on the fact that we only accept
|
|
|
|
# options without values before the real command.
|
|
|
|
GLOBAL_ARGS=""
|
|
|
|
while true; do
|
|
|
|
case $1 in
|
|
|
|
-*)
|
|
|
|
GLOBAL_ARGS="${GLOBAL_ARGS:+$GLOBAL_ARGS }$1"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
Arguments $GLOBAL_ARGS
|
|
|
|
|
|
|
|
if [ $# = 0 ]; then
|
|
|
|
Echo_error "Missing sub-command"
|
|
|
|
Usage --fail
|
|
|
|
fi
|
2010-09-02 11:12:37 +00:00
|
|
|
|
2020-03-11 21:33:50 -01:00
|
|
|
COMMAND="${1}"
|
|
|
|
shift
|
2010-09-02 11:12:37 +00:00
|
|
|
|
2020-03-11 21:33:50 -01:00
|
|
|
if [ -x "${LIVE_BUILD}/scripts/build/${COMMAND}" ]; then
|
|
|
|
# User has live-build copied locally in the system
|
|
|
|
SCRIPT="${LIVE_BUILD}/scripts/build/${COMMAND}"
|
|
|
|
elif [ -x "local/live-build/scripts/build/${COMMAND}" ]; then
|
|
|
|
# User has live-build copied locally in the config
|
|
|
|
SCRIPT="local/live-build/scripts/build/${COMMAND}";
|
|
|
|
elif [ -x /usr/lib/live/build/${COMMAND} ]; then
|
|
|
|
# User has live-build installed in the system
|
|
|
|
SCRIPT=/usr/lib/live/build/"${COMMAND}"
|
|
|
|
else
|
2020-03-30 11:10:06 +00:00
|
|
|
Echo_error "Unknown command: ${COMMAND}"
|
2020-03-11 21:33:50 -01:00
|
|
|
exit 1
|
|
|
|
fi
|
2012-01-12 20:22:57 -01:00
|
|
|
|
2020-03-30 11:08:12 +00:00
|
|
|
if [ "${COMMAND}" != "config" ]; then
|
|
|
|
# Checking user account
|
|
|
|
if [ "$(id -u)" -ne "0" ]; then
|
|
|
|
Echo_error "Root privileges needed!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
ENV=""
|
|
|
|
for _FILE in config/environment config/environment.binary; do
|
|
|
|
if [ -e "${_FILE}" ]; then
|
|
|
|
ENV="${ENV} $(grep -v '^#' ${_FILE})"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-03-11 19:38:51 -01:00
|
|
|
_CMD_LABEL="lb ${COMMAND}"
|
|
|
|
if [ "${_COLOR_OUT}" = "true" ]; then
|
|
|
|
_CMD_LABEL="${CYAN}${_CMD_LABEL}${NO_COLOR}"
|
|
|
|
fi
|
2020-04-29 18:00:40 +00:00
|
|
|
Echo "[%s] ${_CMD_LABEL} %s" "$(date +'%F %T')" "$(echo ${GLOBAL_ARGS} ${@})"
|
2020-04-03 03:22:55 +00:00
|
|
|
|
2020-04-29 18:00:40 +00:00
|
|
|
exec /usr/bin/env ${ENV} "${SCRIPT}" ${GLOBAL_ARGS} "${@}"
|