summaryrefslogtreecommitdiff
path: root/functions/packagelists.sh
blob: aad1ea2d3e0b6224e1c4c7a300adf4df69b337be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/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.


Expand_packagelist ()
{
	_LB_EXPAND_QUEUE="$(basename "${1}")"

	shift

	while [ -n "${_LB_EXPAND_QUEUE}" ]
	do
		_LB_LIST_NAME="$(echo ${_LB_EXPAND_QUEUE} | cut -d" " -f1)"
		_LB_EXPAND_QUEUE="$(echo ${_LB_EXPAND_QUEUE} | cut -s -d" " -f2-)"
		_LB_LIST_LOCATION=""
		_LB_NESTED=0
		_LB_ENABLED=1

		for _LB_SEARCH_PATH in ${@}
		do
			if [ -e "${_LB_SEARCH_PATH}/${_LB_LIST_NAME}" ]
			then
				_LB_LIST_LOCATION="${_LB_SEARCH_PATH}/${_LB_LIST_NAME}"
				break
			fi
		done

		if [ -z "${_LB_LIST_LOCATION}" ]
		then
			echo "W: Unknown package list '${_LB_LIST_NAME}'" >&2
			continue
		fi

		while read _LB_LINE
		do
			case "${_LB_LINE}" in
				\!*)
					_EXEC="$(echo ${_LB_LINE} | sed -e 's|^!||')"

					case "${LB_BUILD_WITH_CHROOT}" in
						true)
							chroot chroot sh -c "${_EXEC}"
							;;

						false)
							eval ${_EXEC}
							;;
					esac
					;;

				\#if\ *)
					if [ ${_LB_NESTED} -eq 1 ]
					then
						echo "E: Nesting conditionals is not supported" >&2
						exit 1
					fi
					_LB_NESTED=1

					_LB_NEEDLE="$(echo "${_LB_LINE}" | cut -d' ' -f3-)"
					_LB_HAYSTACK="$(eval "echo \$LB_$(echo "${_LB_LINE}" | cut -d' ' -f2)")"

					_LB_ENABLED=0
					for _LB_NEEDLE_PART in ${_LB_NEEDLE}
					do
						for _LB_HAYSTACK_PART in ${_LB_HAYSTACK}
						do
							if [ "${_LB_NEEDLE_PART}" = "${_LB_HAYSTACK_PART}" ]
							then
								_LB_ENABLED=1
							fi
						done
					done
					;;

				\#nif\ *)
					if [ ${_LB_NESTED} -eq 1 ]
					then
						echo "E: Nesting conditionals is not supported" >&2
						exit 1
					fi
					_LB_NESTED=1

					_LB_NEEDLE="$(echo "${_LB_LINE}" | cut -d' ' -f3-)"
					_LB_HAYSTACK="$(eval "echo \$LB_$(echo "${_LB_LINE}" | cut -d' ' -f2)")"

					_LB_ENABLED=0
					for _LB_NEEDLE_PART in ${_LB_NEEDLE}
					do
						for _LB_HAYSTACK_PART in ${_LB_HAYSTACK}
						do
							if [ "${_LB_NEEDLE_PART}" != "${_LB_HAYSTACK_PART}" ]
							then
								_LB_ENABLED=1
							fi
						done
					done
					;;

				\#endif*)
					_LB_NESTED=0
					_LB_ENABLED=1
					;;

				\#*)
					if [ ${_LB_ENABLED} -ne 1 ]
					then
						continue
					fi

					# Find includes
					_LB_INCLUDES="$(echo "${_LB_LINE}" | sed -n \
						-e 's|^#<include> \([^ ]*\)|\1|gp' \
						-e 's|^#include <\([^ ]*\)>|\1|gp')"

					# Add to queue
					_LB_EXPAND_QUEUE="$(echo ${_LB_EXPAND_QUEUE} ${_LB_INCLUDES} |
						sed -e 's|[ ]*$||' -e 's|^[ ]*||')"
					;;

				*)
					if [ ${_LB_ENABLED} -eq 1 ]
					then
						echo "${_LB_LINE}"
					fi
					;;

			esac
		done < "${_LB_LIST_LOCATION}"
	done
}