summaryrefslogtreecommitdiff
path: root/functions
diff options
context:
space:
mode:
authorChris Lamb <chris@chris-lamb.co.uk>2008-04-26 23:43:01 +0100
committerChris Lamb <chris@chris-lamb.co.uk>2008-04-26 23:43:01 +0100
commitd77ee361377df448c6e65dd3dbfe411b0f4d9e43 (patch)
treea6527b20eb18f75fd337135cf3efdb46117904dc /functions
parentbb68e3016688f144cf6241c615317605c8e0823f (diff)
downloadvyos-live-build-d77ee361377df448c6e65dd3dbfe411b0f4d9e43.tar.gz
vyos-live-build-d77ee361377df448c6e65dd3dbfe411b0f4d9e43.zip
Support simple conditionals in package lists
This patch adds support for simple conditionals in package lists. For example, to limit a package to i386 only: foo #if ARCHITECTURE i386 package-only-in-i386 #endif bar Any variable that beings in LH_ can be expanded: #if MODE ubuntu package-only-in-ubuntu #endif Nesting of conditionals is not supported. If the variable to be expanded does not exist, the conditional is false. Signed-off-by: Chris Lamb <chris@chris-lamb.co.uk>
Diffstat (limited to 'functions')
-rwxr-xr-xfunctions/packageslists.sh60
1 files changed, 50 insertions, 10 deletions
diff --git a/functions/packageslists.sh b/functions/packageslists.sh
index 443caad66..5f05a4b36 100755
--- a/functions/packageslists.sh
+++ b/functions/packageslists.sh
@@ -20,6 +20,8 @@ Expand_packagelist ()
_LH_LIST_NAME="$(echo ${_LH_EXPAND_QUEUE} | cut -d" " -f1)"
_LH_EXPAND_QUEUE="$(echo ${_LH_EXPAND_QUEUE} | cut -s -d" " -f2-)"
_LH_LIST_LOCATION=""
+ _LH_NESTED=0
+ _LH_ENABLED=1
for _LH_SEARCH_PATH in ${@} "${LH_BASE:-/usr/share/live-helper}/lists"
do
@@ -35,17 +37,55 @@ Expand_packagelist ()
continue
fi
- # Output packages
- grep -v "^#" ${_LH_LIST_LOCATION} | grep .
+ while read _LH_LINE
+ do
+ case "${_LH_LINE}" in
+ \#if\ *)
+ if [ ${_LH_NESTED} -eq 1 ]
+ then
+ echo "E: Nesting conditionals is not supported" >&2
+ exit 1
+ fi
+
+ _LH_NESTED=1
+ _LH_VAR="$(echo "${_LH_LINE}" | cut -d' ' -f2)"
+ _LH_VAL="$(echo "${_LH_LINE}" | cut -d' ' -f3)"
+
+ if [ -n "${_LH_VAR}" ] && [ "$(eval "echo \$LH_${_LH_VAR}")" != "${_LH_VAL}" ]
+ then
+ _LH_ENABLED=0
+ fi
+ ;;
+
+ \#endif*)
+ _LH_NESTED=0
+ _LH_ENABLED=1
+ ;;
+
+ \#*)
+ if [ ${_LH_ENABLED} -ne 1 ]
+ then
+ continue
+ fi
+
+ # Find includes
+ _LH_INCLUDES="$(echo "${_LH_LINE}" | sed -n \
+ -e 's|^#<include> \([^ ]*\)|\1|gp' \
+ -e 's|^#include <\([^ ]*\)>|\1|gp')"
+
+ # Add to queue
+ _LH_EXPAND_QUEUE="$(echo ${_LH_EXPAND_QUEUE} ${_LH_INCLUDES} |
+ sed -e 's|[ ]*$||' -e 's|^[ ]*||')"
+ ;;
- # Find includes
- _LH_INCLUDES="$(sed -n \
- -e 's|^#<include> \([^ ]*\)|\1|gp' \
- -e 's|^#include <\([^ ]*\)>|\1|gp' \
- "${_LH_LIST_LOCATION}")"
+ *)
+ if [ ${_LH_ENABLED} -eq 1 ]
+ then
+ echo "${_LH_LINE}"
+ fi
+ ;;
- # Add to queue
- _LH_EXPAND_QUEUE="$(echo ${_LH_EXPAND_QUEUE} ${_LH_INCLUDES} | \
- sed -e 's|[ ]*$||' -e 's|^[ ]*||')"
+ esac
+ done < "${_LH_LIST_LOCATION}"
done
}