source: live-build/trunk/fuentes/frontends/cgi/live-build-cgi @ 900

Last change on this file since 900 was 900, checked in by kbut, 3 years ago

add original source

  • Property svn:executable set to *
File size: 9.3 KB
Line 
1#!/bin/sh
2
3## live-build(7) - System Build Scripts
4## Copyright (C) 2006-2012 Daniel Baumann <daniel@debian.org>
5##
6## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
7## This is free software, and you are welcome to redistribute it
8## under certain conditions; see COPYING for details.
9
10
11# Including common functions
12( . "${LIVE_BUILD}/scripts/build.sh" > /dev/null 2>&1 || true ) || . /usr/lib/live/build.sh
13
14# Reading defaults
15if [ -r /etc/default/live-build-cgi ]
16then
17        . /etc/default/live-build-cgi
18else
19        echo "E: /etc/default/live-build-cgi missing"
20        exit 1
21fi
22
23_HOSTNAME="$(hostname -f)"
24
25# Turn on debug if enabled
26if [ "${_DEBUG}" = "enabled" ]
27then
28        set -x
29fi
30
31# Sending http header
32echo "Content-type: text/html"
33echo
34
35# Sending html header
36cat "${_TEMPLATES}"/header.html
37
38# CGI
39if [ -z "${QUERY_STRING}" ]
40then
41        # Sending html form
42        sed -e "s/VERSION/${VERSION}/" \
43            -e "s/DATE/`date +%Y%m%d-%H:%M`/" \
44        "${_TEMPLATES}"/form.html
45else
46        # Converting spaces:    sed 's/+/ /g'
47        # Converting '@':       sed 's/%40/@/g'
48        # Converting ':':       sed 's/%3A/:/g'
49        # Converting ';':       sed 's/%3B/\;/g'
50        # Converting '/':       sed 's/%2F/\//g'
51        # Converting '~':       sed 's/%7E/\~/g'
52        # Converting '=':       sed 's/%3D/=/g'
53        # Converting '+':       sed 's/%2B/+/g'
54
55        # Translate parameters
56        QUERY_STRING=$(echo "${QUERY_STRING}" | 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')
57        # Debug the filtering string
58        # echo ${QUERY_STRING}
59
60        # Email
61        _EMAIL=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])email=[-0-9a-zA-Z._@]+' | cut -f 2 -d '=' | head -n1)
62
63        # CGI Packages List
64        _LB_CGIPACKAGES=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])cgipackages=[-0-9a-zA-Z. _+]+' | cut -f 2 -d '=' | head -n1)
65
66        # CGI Config for git
67        _LB_CONFIG=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])config=[-a-z.]+' | cut -f 2 -d '=' | head -n1)
68        _LB_CONFIG="git://live.debian.net/git/${_LB_CONFIG}"
69
70        # Standard options
71        LB_BINARY_IMAGES=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])binary_images=[-a-z]+' | cut -f 2 -d '=' | head -n1)
72        LB_DISTRIBUTION=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])distribution=[a-z]+' | cut -f 2 -d '=' | head -n1)
73
74        # Advanced bootstrap options
75        LB_ARCHITECTURES=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])architectures=[0-9a-z]+' | cut -f 2 -d '=' | head -n1)
76        LB_BOOTSTRAP_FLAVOUR=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])bootstrap_flavour=[a-z]+' | cut -f 2 -d '=' | head -n1)
77        LB_ARCHIVE_AREAS=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])archive_areas=[a-z]+' | cut -f 2 -d '=' | head -n1)
78
79        # Advanced chroot options
80        LB_CHROOT_FILESYSTEM=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])chroot_filesystem=[0-9a-z]+' | cut -f 2 -d '=' | head -n1)
81        LB_LINUX_FLAVOURS=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])linux_flavours=[-0-9a-z]+' | cut -f 2 -d '=' | head -n1)
82        LB_SECURITY=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])security=[a-z]+' | cut -f 2 -d '=' | head -n1)
83
84        # Advanced binary options
85        LB_BINARY_INDICES=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])binary_indices=[a-z]+' | cut -f 2 -d '=' | head -n1)
86        LB_BOOTAPPEND_INSTALL=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])bootappend_install=[-0-9a-zA-Z. _+=:/]+' | cut -f2- -d '=' | head -n1)
87        LB_BOOTAPPEND_LIVE=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])bootappend_live=[-0-9a-zA-Z. _+=:/]+' | cut -f2- -d '=' | head -n1)
88        LB_BOOTLOADER=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])bootloader=[a-z]+' | cut -f 2 -d '=' | head -n1)
89        LB_DEBIAN_INSTALLER=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])debian_installer=[a-z]+' | cut -f 2 -d '=' | head -n1)
90        LB_ISO_APPLICATION=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])iso_application=[-0-9a-zA-Z. ~;:/_]+' | cut -f 2 -d '=' | head -n1)
91        LB_ISO_PREPARER=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])iso_preparer=[-0-9a-zA-Z. ~;:/_]+' | cut -f 2 -d '=' | head -n1)
92        LB_ISO_PUBLISHER=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])iso_publisher=[-0-9a-zA-Z. ~;:/_@]+' | cut -f 2 -d '=' | head -n1)
93        LB_ISO_VOLUME=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])iso_volume=[-0-9a-zA-Z. ~;:/_]+' | cut -f 2 -d '=' | head -n1)
94        LB_MEMTEST=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])memtest=[0-9a-z+]+' | cut -f 2 -d '=' | head -n1)
95        LB_NET_ROOT_PATH=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])net_path=[-0-9a-zA-Z._/]+' | cut -f 2 -d '=' | head -n1)
96        LB_NET_ROOT_SERVER=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])net_server=[0-9.]+' | cut -f 2 -d '=' | head -n1)
97
98        # Advanced source options
99        LB_SOURCE=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])source=[a-z]+' | cut -f 2 -d '=' | head -n1)
100        LB_SOURCE_IMAGES=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])source_images=[a-z]+' | cut -f 2 -d '=' | head -n1)
101
102        # Unofficial options
103        _CUSTOM_BOOTSTRAP=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])custom_bootstrap=[-0-9a-zA-Z.~:/_]+' | cut -f 2 -d '=' | head -n1)
104        _CUSTOM_BINARY=$(echo "${QUERY_STRING}" | grep -oE '(^|[?&])custom_binary=[-0-9a-zA-Z.~:/_]+' | cut -f 2 -d '=' | head -n1)
105
106        # FIXME: filter invalid options
107        unset QUERY_STRING
108
109        if [ -z "${_EMAIL}" ]
110        then
111                echo "<h2><div style='color: red;'>Error: No email address specified.</div></h2>"
112
113                sed -e "s/VERSION/${VERSION}/" \
114                    -e "s/DATE/`date +%Y%m%d-%H:%M`/" \
115                "${_TEMPLATES}"/form.html
116
117                exit
118        fi
119
120        # Getting build identifier
121        _BUILD=$(date +%Y%m%d.%H%M%S.%N)
122
123        # Getting number of builds pending.
124        _QUEUENUM=$(ls "${_TEMPDIR}"/*.build | wc -l)
125
126        #echo "${QUERY_STRING}"
127        # Sending html confirmation
128        # Note: On each string remember to use a delimeter that is not in the string.
129        sed -e "s/BUILD/${_BUILD}/g" \
130            -e "s/EMAIL/${_EMAIL}/" \
131            -e "s/QUEUENUM/${_QUEUENUM}/" \
132            -e "s/LB_BINARY_IMAGES/${LB_BINARY_IMAGES}/" \
133            -e "s/LB_DISTRIBUTION/${LB_DISTRIBUTION}/" \
134            -e "s#_LB_CONFIG#${_LB_CONFIG}#" \
135            -e "s/_LB_CGIPACKAGES/${_LB_CGIPACKAGES}/" \
136            -e "s/LB_ARCHITECTURES/${LB_ARCHITECTURES}/" \
137            -e "s/LB_BOOTSTRAP_FLAVOUR/${LB_BOOTSTRAP_FLAVOUR}/" \
138            -e "s/LB_ARCHIVE_AREAS/${LB_ARCHIVE_AREAS}/" \
139            -e "s/LB_CHROOT_FILESYSTEM/${LB_CHROOT_FILESYSTEM}/" \
140            -e "s/LB_LINUX_FLAVOURS/${LB_LINUX_FLAVOURS}/" \
141            -e "s/LB_SECURITY/${LB_SECURITY}/" \
142            -e "s/LB_BINARY_INDICES/${LB_BINARY_INDICES}/" \
143            -e "s#LB_BOOTAPPEND_INSTALL#${LB_BOOTAPPEND_INSTALL}#" \
144            -e "s#LB_BOOTAPPEND_LIVE#${LB_BOOTAPPEND_LIVE}#" \
145            -e "s/LB_BOOTLOADER/${LB_BOOTLOADER}/" \
146            -e "s/LB_DEBIAN_INSTALLER/${LB_DEBIAN_INSTALLER}/" \
147            -e "s#LB_ISO_APPLICATION#${LB_ISO_APPLICATION}#" \
148            -e "s#LB_ISO_PREPARER#${LB_ISO_PREPARER}#" \
149            -e "s#LB_ISO_PUBLISHER#${LB_ISO_PUBLISHER}#" \
150            -e "s#LB_ISO_VOLUME#${LB_ISO_VOLUME}#" \
151            -e "s/LB_MEMTEST/${LB_MEMTEST}/" \
152            -e "s#LB_NET_ROOT_PATH#${LB_NET_ROOT_PATH}#" \
153            -e "s/LB_NET_ROOT_SERVER/${LB_NET_ROOT_SERVER}/" \
154            -e "s#SERVER#${_SERVER}#g" \
155            -e "s/LB_SOURCE_IMAGES/${LB_SOURCE_IMAGES}/" \
156            -e "s/LB_SOURCE/${LB_SOURCE}/" \
157            -e "s#CUSTOM_BOOTSTRAP#${_CUSTOM_BOOTSTRAP}#" \
158            -e "s#CUSTOM_BINARY#${_CUSTOM_BINARY}#" \
159        "${_TEMPLATES}"/build.html
160
161        # Creating temporary directory
162        mkdir -p "${_TEMPDIR}"
163
164# Writing build file
165cat > "${_TEMPDIR}"/"${_BUILD}".build << EOF
166# live-build-cgi "${VERSION}" build file
167# `date -R`
168
169_BUILD="${_BUILD}"
170_EMAIL="${_EMAIL}"
171
172REMOTE_ADDR="${REMOTE_ADDR}"
173
174# CGI Packages List
175_LB_CGIPACKAGES="${_LB_CGIPACKAGES}"
176
177# CGI Config for git
178_LB_CONFIG="${_LB_CONFIG}"
179
180# Standard options
181LB_BINARY_IMAGES="${LB_BINARY_IMAGES}"
182LB_DISTRIBUTION="${LB_DISTRIBUTION}"
183
184# Advanced bootstrap options
185LB_ARCHITECTURES="${LB_ARCHITECTURES}"
186LB_ARCHIVE_AREAS="${LB_ARCHIVE_AREAS}"
187
188# Advanced chroot options
189LB_CHROOT_FILESYSTEM="${LB_CHROOT_FILESYSTEM}"
190LB_LINUX_FLAVOURS="${LB_LINUX_FLAVOURS}"
191LB_SECURITY="${LB_SECURITY}"
192
193# Advanced binary options
194LB_BINARY_INDICES="${LB_BINARY_INDICES}"
195LB_BOOTAPPEND_INSTALL="${LB_BOOTAPPEND_INSTALL}"
196LB_BOOTAPPEND_LIVE="${LB_BOOTAPPEND_LIVE}"
197LB_BOOTLOADER="${LB_BOOTLOADER}"
198LB_DEBIAN_INSTALLER="${LB_DEBIAN_INSTALLER}"
199LB_ISO_APPLICATION="${LB_ISO_APPLICATION}"
200LB_ISO_PREPARER="${LB_ISO_PREPARER}"
201LB_ISO_PUBLISHER="${LB_ISO_PUBLISHER}"
202LB_ISO_VOLUME="${LB_ISO_VOLUME}"
203LB_MEMTEST="${LB_MEMTEST}"
204LB_NET_ROOT_PATH="${LB_NET_ROOT_PATH}"
205LB_NET_ROOT_SERVER="${LB_NET_ROOT_SERVER}"
206
207# Advanced source options
208LB_SOURCE_IMAGES="${LB_SOURCE_IMAGES}"
209LB_SOURCE="${LB_SOURCE}"
210
211# Unofficial options
212_CUSTOM_BOOTSTRAP="${_CUSTOM_BOOTSTRAP}"
213_CUSTOM_BINARY="${_CUSTOM_BINARY}"
214
215EOF
216
217        echo "$(date +%b\ %d\ %H:%M:%S) ${_HOSTNAME} live-build-cgi: add web build (${_BUILD}) from ${REMOTE_ADDR}." >> /var/log/live
218        echo "$(date +%b\ %d\ %H:%M:%S) ${_HOSTNAME} live-build-cgi: options ${_BUILD} |email ${_EMAIL}|binary_images ${LB_BINARY_IMAGES}|distribution ${LB_DISTRIBUTION}|config ${_LB_CONFIG}|cgipackages ${_LB_CGIPACKAGES}|architectures ${LB_ARCHITECTURES}|archive_areas ${LB_ARCHIVE_AREAS}|chroot_filesystem ${LB_CHROOT_FILESYSTEM}|linux_flavours ${LB_LINUX_FLAVOURS}|security ${LB_SECURITY}|binary_indices ${LB_BINARY_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}|custom_bootstrap ${_CUSTOM_BOOTSTRAP}|custom_binary ${_CUSTOM_BINARY}" >> /var/log/live
219fi
220
221sed -e "s/VERSION/${VERSION}/" "${_TEMPLATES}"/footer.html
Note: See TracBrowser for help on using the repository browser.