live-build-cgi 8.82 KB
Newer Older
1
2
#!/bin/sh

3
## live-build(7) - System Build Scripts
4
## Copyright (C) 2006-2013 Daniel Baumann <mail@daniel-baumann.ch>
5
##
6
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
7
8
9
## This is free software, and you are welcome to redistribute it
## under certain conditions; see COPYING for details.

10

11
# Including common functions
12
. /usr/lib/live/build.sh
13

14
# Reading defaults
15
if [ -r /etc/default/live-build-cgi ]
16
then
17
	. /etc/default/live-build-cgi
18
else
19
	echo "E: /etc/default/live-build-cgi missing"
20
21
22
	exit 1
fi

23
24
_HOSTNAME="$(hostname -f)"

25
26
# Turn on debug if true
if [ "${_DEBUG}" = "true" ]
27
28
29
30
31
32
33
34
then
	set -x
fi

# Sending http header
echo "Content-type: text/html"
echo

35
36
37
38
39
40
41
42
# If we are passed something then read it in.
if [ "$REQUEST_METHOD" = "POST" ] && [ "$CONTENT_LENGTH" -gt 0 ]
then
	#QUERY_STRING=`cat /dev/stdin`
	QUERY_STRING=$(cat /dev/stdin)
	#read -n $CONTENT_LENGTH POST_DATA <&0
fi

43
# Translate parameters
44
QUERY_STRING=$(echo "${POST_DATA}" | sed -e 's/%2F/\//g' -e 's/+/ /g' -e 's/%3B/;/g' -e 's/%7E/~/g' -e 's/%3A/:/g' -e 's/%40/@/g' -e 's/%3D/=/g' -e 's/%2B/+/g')
45
46
47
48
# Debug the filtering string
# echo ${QUERY_STRING}


49
50
51
52
53
54
55
# Sending html header
cat "${_TEMPLATES}"/header.html

# CGI
if [ -z "${QUERY_STRING}" ]
then
	# Sending html form
56
	sed -e "s/VERSION/${VERSION}/" \
57
58
59
60
61
62
63
64
65
	    -e "s/DATE/`date +%Y%m%d-%H:%M`/" \
	"${_TEMPLATES}"/form.html
else
	# Converting spaces:	sed 's/+/ /g'
	# Converting '@':	sed 's/%40/@/g'
	# Converting ':':	sed 's/%3A/:/g'
	# Converting ';':	sed 's/%3B/\;/g'
	# Converting '/':	sed 's/%2F/\//g'
	# Converting '~':	sed 's/%7E/\~/g'
66
67
	# Converting '=':	sed 's/%3D/=/g'
	# Converting '+':	sed 's/%2B/+/g'
68
69

	# Email
70
	_EMAIL=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])email=[-0-9a-zA-Z._@]+' | cut -f 2 -d '=' | head -n1)
71

72
73
74
	# CGI Packages List
	_LB_CGIPACKAGES=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])cgipackages=[-0-9a-zA-Z. _+]+' | cut -f 2 -d '=' | head -n1)

75
	# CGI Config for git
76
	_LB_CONFIG=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])config=[-a-z]+' | cut -f 2 -d '=' | head -n1)
77

78
	# Standard options
79
	LIVE_IMAGE_TYPE=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])binary_images=[-a-z]+' | cut -f 2 -d '=' | head -n1)
80
	LB_DISTRIBUTION=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])distribution=[a-z]+' | cut -f 2 -d '=' | head -n1)
81
82

	# Advanced bootstrap options
83
84
	LIVE_IMAGE_ARCHITECTURE=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])architectures=[0-9a-z]+' | cut -f 2 -d '=' | head -n1)
	LIVE_IMAGE_ARCHIVE_AREAS=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])archive_areas=[a-z]+' | cut -f 2 -d '=' | head -n1)
85
86

	# Advanced chroot options
87
88
89
	LB_CHROOT_FILESYSTEM=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])chroot_filesystem=[0-9a-z]+' | cut -f 2 -d '=' | head -n1)
	LB_LINUX_FLAVOURS=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])linux_flavours=[-0-9a-z]+' | cut -f 2 -d '=' | head -n1)
	LB_SECURITY=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])security=[a-z]+' | cut -f 2 -d '=' | head -n1)
90
91

	# Advanced binary options
92
	LB_APT_INDICES=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])apt_indices=[a-z]+' | cut -f 2 -d '=' | head -n1)
93
94
95
96
97
98
99
100
101
102
103
	LB_BOOTAPPEND_INSTALL=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])bootappend_install=[-0-9a-zA-Z. _+=:/]+' | cut -f2- -d '=' | head -n1)
	LB_BOOTAPPEND_LIVE=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])bootappend_live=[-0-9a-zA-Z. _+=:/]+' | cut -f2- -d '=' | head -n1)
	LB_BOOTLOADER=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])bootloader=[a-z]+' | cut -f 2 -d '=' | head -n1)
	LB_DEBIAN_INSTALLER=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])debian_installer=[a-z]+' | cut -f 2 -d '=' | head -n1)
	LB_ISO_APPLICATION=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])iso_application=[-0-9a-zA-Z. ~;:/_]+' | cut -f 2 -d '=' | head -n1)
	LB_ISO_PREPARER=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])iso_preparer=[-0-9a-zA-Z. ~;:/_]+' | cut -f 2 -d '=' | head -n1)
	LB_ISO_PUBLISHER=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])iso_publisher=[-0-9a-zA-Z. ~;:/_@]+' | cut -f 2 -d '=' | head -n1)
	LB_ISO_VOLUME=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])iso_volume=[-0-9a-zA-Z. ~;:/_]+' | cut -f 2 -d '=' | head -n1)
	LB_MEMTEST=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])memtest=[0-9a-z+]+' | cut -f 2 -d '=' | head -n1)
	LB_NET_ROOT_PATH=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])net_path=[-0-9a-zA-Z._/]+' | cut -f 2 -d '=' | head -n1)
	LB_NET_ROOT_SERVER=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])net_server=[0-9.]+' | cut -f 2 -d '=' | head -n1)
104
105

	# Advanced source options
106
107
	LB_SOURCE=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])source=[a-z]+' | cut -f 2 -d '=' | head -n1)
	LB_SOURCE_IMAGES=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])source_images=[a-z]+' | cut -f 2 -d '=' | head -n1)
108
109
110
111
112
113
114
115

	# FIXME: filter invalid options
	unset QUERY_STRING

	if [ -z "${_EMAIL}" ]
	then
		echo "<h2><div style='color: red;'>Error: No email address specified.</div></h2>"

116
		sed -e "s/VERSION/${VERSION}/" \
117
118
119
120
121
122
123
124
125
		    -e "s/DATE/`date +%Y%m%d-%H:%M`/" \
		"${_TEMPLATES}"/form.html

		exit
	fi

	# Getting build identifier
	_BUILD=$(date +%Y%m%d.%H%M%S.%N)

126
127
128
	# Getting number of builds pending.
	_QUEUENUM=$(ls "${_TEMPDIR}"/*.build | wc -l)

129
130
131
132
133
	#echo "${QUERY_STRING}"
	# Sending html confirmation
	# Note: On each string remember to use a delimeter that is not in the string.
	sed -e "s/BUILD/${_BUILD}/g" \
	    -e "s/EMAIL/${_EMAIL}/" \
134
	    -e "s/QUEUENUM/${_QUEUENUM}/" \
135
	    -e "s/LIVE_IMAGE_TYPE/${LIVE_IMAGE_TYPE}/" \
136
	    -e "s/LB_DISTRIBUTION/${LB_DISTRIBUTION}/" \
137
	    -e "s#_LB_CONFIG#${_LB_CONFIG}#" \
138
	    -e "s/_LB_CGIPACKAGES/${_LB_CGIPACKAGES}/" \
139
140
	    -e "s/LIVE_IMAGE_ARCHITECTURE/${LIVE_IMAGE_ARCHITECTURE}/" \
	    -e "s/LIVE_IMAGE_ARCHIVE_AREAS/${LIVE_IMAGE_ARCHIVE_AREAS}/" \
141
142
143
	    -e "s/LB_CHROOT_FILESYSTEM/${LB_CHROOT_FILESYSTEM}/" \
	    -e "s/LB_LINUX_FLAVOURS/${LB_LINUX_FLAVOURS}/" \
	    -e "s/LB_SECURITY/${LB_SECURITY}/" \
144
	    -e "s/LB_APT_INDICES/${LB_APT_INDICES}/" \
145
146
147
148
149
150
151
152
153
154
155
	    -e "s#LB_BOOTAPPEND_INSTALL#${LB_BOOTAPPEND_INSTALL}#" \
	    -e "s#LB_BOOTAPPEND_LIVE#${LB_BOOTAPPEND_LIVE}#" \
	    -e "s/LB_BOOTLOADER/${LB_BOOTLOADER}/" \
	    -e "s/LB_DEBIAN_INSTALLER/${LB_DEBIAN_INSTALLER}/" \
	    -e "s#LB_ISO_APPLICATION#${LB_ISO_APPLICATION}#" \
	    -e "s#LB_ISO_PREPARER#${LB_ISO_PREPARER}#" \
	    -e "s#LB_ISO_PUBLISHER#${LB_ISO_PUBLISHER}#" \
	    -e "s#LB_ISO_VOLUME#${LB_ISO_VOLUME}#" \
	    -e "s/LB_MEMTEST/${LB_MEMTEST}/" \
	    -e "s#LB_NET_ROOT_PATH#${LB_NET_ROOT_PATH}#" \
	    -e "s/LB_NET_ROOT_SERVER/${LB_NET_ROOT_SERVER}/" \
156
	    -e "s#SERVER#${_SERVER}#g" \
157
158
	    -e "s/LB_SOURCE_IMAGES/${LB_SOURCE_IMAGES}/" \
	    -e "s/LB_SOURCE/${LB_SOURCE}/" \
159
160
161
162
163
164
165
	"${_TEMPLATES}"/build.html

	# Creating temporary directory
	mkdir -p "${_TEMPDIR}"

# Writing build file
cat > "${_TEMPDIR}"/"${_BUILD}".build << EOF
166
# live-build-cgi "${VERSION}" build file
167
168
169
170
171
# `date -R`

_BUILD="${_BUILD}"
_EMAIL="${_EMAIL}"

172
173
REMOTE_ADDR="${REMOTE_ADDR}"

174
175
176
# CGI Packages List
_LB_CGIPACKAGES="${_LB_CGIPACKAGES}"

177
178
179
# CGI Config for git
_LB_CONFIG="${_LB_CONFIG}"

180
# Standard options
181
LIVE_IMAGE_TYPE="${LIVE_IMAGE_TYPE}"
182
LB_DISTRIBUTION="${LB_DISTRIBUTION}"
183
184

# Advanced bootstrap options
185
186
LIVE_IMAGE_ARCHITECTURE="${LIVE_IMAGE_ARCHITECTURE}"
LIVE_IMAGE_ARCHIVE_AREAS="${LIVE_IMAGE_ARCHIVE_AREAS}"
187
188

# Advanced chroot options
189
190
191
LB_CHROOT_FILESYSTEM="${LB_CHROOT_FILESYSTEM}"
LB_LINUX_FLAVOURS="${LB_LINUX_FLAVOURS}"
LB_SECURITY="${LB_SECURITY}"
192
193

# Advanced binary options
194
LB_APT_INDICES="${LB_APT_INDICES}"
195
196
197
198
199
200
201
202
203
204
205
LB_BOOTAPPEND_INSTALL="${LB_BOOTAPPEND_INSTALL}"
LB_BOOTAPPEND_LIVE="${LB_BOOTAPPEND_LIVE}"
LB_BOOTLOADER="${LB_BOOTLOADER}"
LB_DEBIAN_INSTALLER="${LB_DEBIAN_INSTALLER}"
LB_ISO_APPLICATION="${LB_ISO_APPLICATION}"
LB_ISO_PREPARER="${LB_ISO_PREPARER}"
LB_ISO_PUBLISHER="${LB_ISO_PUBLISHER}"
LB_ISO_VOLUME="${LB_ISO_VOLUME}"
LB_MEMTEST="${LB_MEMTEST}"
LB_NET_ROOT_PATH="${LB_NET_ROOT_PATH}"
LB_NET_ROOT_SERVER="${LB_NET_ROOT_SERVER}"
206
207

# Advanced source options
208
209
LB_SOURCE_IMAGES="${LB_SOURCE_IMAGES}"
LB_SOURCE="${LB_SOURCE}"
210
211
212

EOF

213
214
	echo "$(date +%b\ %d\ %H:%M:%S) ${_HOSTNAME} live-build-cgi: add web build (${_BUILD}) from ${REMOTE_ADDR}." >> /var/log/live/live-build-request
	echo "$(date +%b\ %d\ %H:%M:%S) ${_HOSTNAME} live-build-cgi: options ${_BUILD} |email ${_EMAIL}|binary_images ${LIVE_IMAGE_TYPE}|distribution ${LB_DISTRIBUTION}|config ${_LB_CONFIG}|cgipackages ${_LB_CGIPACKAGES}|architectures ${LIVE_IMAGE_ARCHITECTURE}|archive_areas ${LIVE_IMAGE_ARCHIVE_AREAS}|chroot_filesystem ${LB_CHROOT_FILESYSTEM}|linux_flavours ${LB_LINUX_FLAVOURS}|security ${LB_SECURITY}|apt_indices ${LB_APT_INDICES}|bootappend_install ${LB_BOOTAPPEND_INSTALL}|bootappend_live ${LB_BOOTAPPEND_LIVE}|bootloader ${LB_BOOTLOADER}|debian_installer ${LB_DEBIAN_INSTALLER}|iso_application ${LB_ISO_APPLICATION}|iso_preparer ${LB_ISO_PREPARER}|iso_publisher ${LB_ISO_PUBLISHER}|iso_volume ${LB_ISO_VOLUME}|memtest ${LB_MEMTEST}|net_path ${LB_NET_ROOT_PATH}|net_server ${LB_NET_ROOT_SERVER}|source_images ${LB_SOURCE_IMAGES}|sources ${LB_SOURCE}" >> /var/log/live/live-build-request
215
216
217
fi

sed -e "s/VERSION/${VERSION}/" "${_TEMPLATES}"/footer.html