live-build/functions/stagefile.sh

91 lines
1.8 KiB
Bash
Raw Normal View History

2007-09-23 08:04:46 +00:00
#!/bin/sh
## live-build(7) - System Build Scripts
## Copyright (C) 2016-2020 The Debian Live team
## Copyright (C) 2006-2015 Daniel Baumann <mail@daniel-baumann.ch>
##
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
## This is free software, and you are welcome to redistribute it
## under certain conditions; see COPYING for details.
2007-09-23 08:04:46 +00:00
# Get the default filename for a script's stagefile (the name of the script
# file itself). A suffix can be appended via providing as a param.
Stagefile_name ()
{
local SUFFIX="${1}"
local FILENAME
FILENAME="$(basename $0)"
echo ${FILENAME}${SUFFIX:+.$SUFFIX}
}
2007-09-23 08:04:46 +00:00
Check_stagefile ()
{
local FILE
local NAME
FILE=".build/${1:-$(Stagefile_name)}"
NAME="$(basename ${FILE})"
2007-09-23 08:04:46 +00:00
# Checking stage file
2007-09-23 08:04:49 +00:00
if [ -f "${FILE}" ]
2007-09-23 08:04:46 +00:00
then
if [ "${_FORCE}" != "true" ]
2007-09-23 08:04:48 +00:00
then
# Skip execution
Echo_warning "Skipping %s, already done" "${NAME}"
2007-09-23 08:04:48 +00:00
exit 0
2007-09-23 08:04:51 +00:00
else
# Force execution
Echo_message "Forcing %s" "${NAME}"
2007-09-23 08:04:51 +00:00
rm -f "${FILE}"
2007-09-23 08:04:48 +00:00
fi
2007-09-23 08:04:46 +00:00
fi
}
Create_stagefile ()
{
local FILE
local DIRECTORY
FILE=".build/${1:-$(Stagefile_name)}"
DIRECTORY="$(dirname ${FILE})"
2007-09-23 08:04:46 +00:00
# Creating stage directory
2007-09-23 08:05:11 +00:00
mkdir -p "${DIRECTORY}"
2007-09-23 08:04:46 +00:00
# Creating stage file
2007-09-23 08:04:49 +00:00
touch "${FILE}"
2007-09-23 08:04:46 +00:00
}
Remove_stagefile ()
{
local FILE
FILE=".build/${1:-$(Stagefile_name)}"
rm -f "${FILE}"
}
# Find at least one of the required stages, `exit 1` if none found
2007-09-23 08:04:46 +00:00
Require_stagefile ()
{
if [ $# -eq 0 ]; then
Echo_warning "Bad `Require_stagefile` usage, no params were supplied"
return 0
fi
local FILE
for FILE in ${@}; do
if [ -f ".build/${FILE}" ]; then
return 0
2007-09-23 08:04:52 +00:00
fi
done
local NAME
NAME="$(basename ${0})"
2007-09-23 08:04:52 +00:00
if [ $# -eq 1 ]; then
Echo_error "%s requires stage: %s" "${NAME}" "${FILE}"
else
Echo_error "%s requires one of these stages: %s" "${NAME}" "$(echo ${@})"
2007-09-23 08:04:46 +00:00
fi
exit 1
2007-09-23 08:04:46 +00:00
}