Moving configuration version off as the first option into new config tree format.

This commit is contained in:
Daniel Baumann 2012-12-19 09:49:06 +01:00 committed by Daniel Baumann
parent a595e9c1bc
commit c73a5a0ee0
4 changed files with 69 additions and 19 deletions

View File

@ -12,4 +12,7 @@ PROGRAM="live-build"
VERSION="$(if [ -e ${LIVE_BUILD}/VERSION ]; then cat ${LIVE_BUILD}/VERSION; else cat /usr/share/live/build/VERSION; fi)"
CONFIG_VERSION="$(echo ${VERSION} | awk -F- '{ print $1 }')"
# FIXME
LIVE_CONFIGURATION_VERSION="${CONFIG_VERSION}"
PATH="${PWD}/local/bin:${PATH}"

38
functions/configuration.sh Executable file
View File

@ -0,0 +1,38 @@
#!/bin/sh
## live-build(7) - System Build Scripts
## Copyright (C) 2006-2012 Daniel Baumann <daniel@debian.org>
##
## 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.
Get_configuration ()
{
_CONFIGURATION_FILE="${1}"
_FIELD_NAME="${2}"
if [ -e "${_CONFIGURATION_FILE}" ]
then
_FIELD_BODY="$(grep ^${_FIELD_NAME}: ${_CONFIGURATION_FILE} | awk '{ $1=""; print $0 }' | sed -e 's|^ ||')"
fi
echo ${_FIELD_BODY}
}
Set_configuration ()
{
_CONFIGURATION_FILE="${1}"
_FIELD_NAME="${2}"
_FIELD_BODY="${3}"
if grep -qs "^${_FIELD_NAME}:" "${_CONFIGURATION_FILE}"
then
# Update configuration
sed -i -e "s|^${_FIELD_NAME}:.*$|${_FIELD_NAME}: ${_FIELD_BODY}|" "${_CONFIGURATION_FILE}"
else
# Append configuration
echo "${_FIELD_NAME}: ${_FIELD_BODY}" >> "${_CONFIGURATION_FILE}"
fi
}

View File

@ -1140,32 +1140,41 @@ Set_defaults ()
Check_defaults ()
{
if [ "${LB_CONFIG_VERSION}" ]
if [ -n "${LIVE_CONFIGURATION_VERSION}" ]
then
# We're only checking when we're actually running the checks
# that's why the check for emptyness of the version;
# however, as live-build always declares LB_CONFIG_VERSION
# however, as live-build always declares LIVE_CONFIGURATION_VERSION
# internally, this is safe assumption (no cases where it's unset,
# except when bootstrapping the functions/defaults etc.).
CURRENT_CONFIG_VERSION="$(echo ${LB_CONFIG_VERSION} | awk -F. '{ print $1 }')"
if [ ${CURRENT_CONFIG_VERSION} -ne 4 ]
CURRENT_CONFIGURATION_VERSION="$(Get_configuration config/control Configuration-Version)"
CURRENT_CONFIGURATION_VERSION="$(echo ${CURRENT_CONFIGURATION_VERSION} | awk -F. ' { print $1 }')"
if [ -n "${CURRENT_CONFIGURATION_VERSION}" ]
then
if [ ${CURRENT_CONFIG_VERSION} -ge 5 ]
then
Echo_error "This config tree is too new for this version of live-build (${VERSION})."
Echo_error "Aborting build, please get a new version of live-build."
CORRECT_VERSION="$(echo ${LIVE_CONFIGURATION_VERSION} | awk -F. '{ print $1 }')"
TOO_NEW_VERSION="$((${CORRECT_VERSION} + 1))"
TOO_OLD_VERSION="$((${CORRECT_VERSION} - 1))"
exit 1
elif [ ${CURRENT_CONFIG_VERSION} -le 3 ]
if [ ${CURRENT_CONFIGURATION_VERSION} -ne ${CORRECT_VERSION} ]
then
Echo_error "This config tree is too old for this version of live-build (${VERSION})."
Echo_error "Aborting build, please regenerate the config tree."
if [ ${CURRENT_CONFIGURATION_VERSION} -ge ${TOO_NEW_VERSION} ]
then
Echo_error "This config tree is too new for live-build (${VERSION})."
Echo_error "Aborting build, please update live-build."
exit 1
else
Echo_warning "This config tree does not specify a format version or has an unknown version number."
Echo_warning "Continuing build, but it could lead to errors or different results. Please regenerate the config tree."
exit 1
elif [ ${CURRENT_CONFIGURATION_VERSION} -le ${TOO_OLD_VERSION} ]
then
Echo_error "This config tree is too old for live-build (${VERSION})."
Echo_error "Aborting build, please update the configuration."
exit 1
else
Echo_warning "This configuration does not specify a version or has a unknown version."
Echo_warning "Continuing build, please correct the configuration."
fi
fi
fi
fi

View File

@ -969,9 +969,6 @@ mkdir -p config/includes
cat > config/common << EOF
# config/common - common options for live-build(7)
# LB_CONFIG_VERSION: internal version of the configuration file format
LB_CONFIG_VERSION="${CONFIG_VERSION}"
# \$LB_APT: set package manager
# (Default: ${LB_APT})
LB_APT="${LB_APT}"
@ -1492,5 +1489,8 @@ then
rmdir --ignore-fail-on-non-empty local > /dev/null 2>&1 || true
fi
# New style configuration
Set_configuration "config/control" "Configuration-Version" "${LIVE_CONFIGURATION_VERSION}"
# Creating stage file
Create_stagefile .build/config