summaryrefslogtreecommitdiff
path: root/functions
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2012-12-19 09:49:06 +0100
committerDaniel Baumann <mail@daniel-baumann.ch>2013-05-06 14:50:03 +0200
commitc73a5a0ee0b7e372ef33b6f0ab817d86a1a8093e (patch)
tree7b0a5f2208056d319688540b0e1eaf346f85f0cd /functions
parenta595e9c1bc870897c98ed95a7659db3c87966eea (diff)
downloadvyos-live-build-c73a5a0ee0b7e372ef33b6f0ab817d86a1a8093e.tar.gz
vyos-live-build-c73a5a0ee0b7e372ef33b6f0ab817d86a1a8093e.zip
Moving configuration version off as the first option into new config tree format.
Diffstat (limited to 'functions')
-rwxr-xr-xfunctions/common.sh3
-rwxr-xr-xfunctions/configuration.sh38
-rwxr-xr-xfunctions/defaults.sh41
3 files changed, 66 insertions, 16 deletions
diff --git a/functions/common.sh b/functions/common.sh
index 9284ec564..9621e476b 100755
--- a/functions/common.sh
+++ b/functions/common.sh
@@ -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}"
diff --git a/functions/configuration.sh b/functions/configuration.sh
new file mode 100755
index 000000000..951e354fa
--- /dev/null
+++ b/functions/configuration.sh
@@ -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
+}
diff --git a/functions/defaults.sh b/functions/defaults.sh
index d49534c09..2500ddd59 100755
--- a/functions/defaults.sh
+++ b/functions/defaults.sh
@@ -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