1 #################################################################
3 # Debian live-build specific functions.
5 # Author: Jan Blunck <jblunck@infradead.org>
7 # This file is part of build.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License version 2 or 3 as
11 # published by the Free Software Foundation.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program (see the file COPYING); if not, write to the
20 # Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 #################################################################
25 recipe_setup_livebuild() {
26 TOPDIR=/usr/src/packages
27 test "$DO_INIT_TOPDIR" = false || rm -rf "$BUILD_ROOT$TOPDIR"
28 for i in OTHER SOURCES LIVEBUILD_ROOT ; do
29 mkdir -p "$BUILD_ROOT$TOPDIR/$i"
31 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
32 if test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
33 mv "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
35 cp -p "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
39 recipe_prepare_livebuild() {
48 if [ -z "${DIR}" -o ! -d ${DIR} -o ${DIR} = ${DIR##${BUILD_ROOT}} ] ; then
52 pushd ${DIR} >/dev/null
54 # cleanup existing repository files
55 rm -f Packages Packages.gz Release
58 mkdir -p dists/${DIST}
59 # Suite is symlinked to Codename
60 ln -s ${DIST} dists/stable
62 # create Packages and Sources files
63 mkdir -p dists/${DIST}/main/binary-${ARCH}
64 mkdir -p dists/${DIST}/main/source
65 cat > ${BUILD_ROOT}/.createrepo_debian.tmp.sh <<-EOF
66 cd /.build.binaries || exit 1
67 dpkg-scanpackages -m . > dists/${DIST}/main/binary-${ARCH}/Packages
68 gzip -c9 < dists/${DIST}/main/binary-${ARCH}/Packages \
69 > dists/${DIST}/main/binary-${ARCH}/Packages.gz
70 dpkg-scansources . > dists/${DIST}/main/source/Sources
71 gzip -c9 dists/${DIST}/main/source/Sources \
72 > dists/${DIST}/main/source/Sources.gz
74 chroot $BUILD_ROOT su -c "sh /.createrepo_debian.tmp.sh" - root
76 rm -f $BUILD_ROOT/.createrepo_debian.tmp.sh
77 [ "${RESULT}" != 0 ] && return
80 pushd dists/${DIST} >/dev/null
87 Date: Sat, 15 Jun 2013 10:55:26 UTC
88 Description: Debian repository created by build-recipe-livebuild
91 echo "SHA256:" >> Release
92 for file in main/binary-${ARCH}/Packages* ; do
93 local SUM=( $(sha256sum ${file}) )
94 local SIZE=$(stat -c '%s' ${file})
95 echo " ${SUM} ${SIZE} ${file}" >> Release
97 for file in main/source/Sources* ; do
98 local SUM=( $(sha256sum ${file}) )
99 local SIZE=$(stat -c '%s' ${file})
100 echo " ${SUM} ${SIZE} ${file}" >> Release
104 # TODO: this is missing the signature with the private key
109 # This script expects that the $BUILD_ROOT is a Debian installation with
110 # live-build already installed!
113 # $BUILD_ROOT the Debian chroot
114 # $TOPDIR/SOURCES includes the live-build config tarball
115 # $TOPDIR/$LIVEBUILD_ROOT where live-build will be called
116 # $RECIPEFILE the name of the live-build config tarball
118 recipe_build_livebuild() {
119 local ARCH=$(chroot $BUILD_ROOT su -c "dpkg-architecture -qDEB_BUILD_ARCH")
120 local DIST=$(chroot $BUILD_ROOT su -c "lsb_release --codename" | awk '{ print $2 }')
121 local LIVEBUILD_ROOT="LIVEBUILD_ROOT"
123 [ -z "${ARCH}" -o -z "${DIST}" ] && cleanup_and_exit 1
125 test -d $BUILD_ROOT/.build.binaries || cleanup_and_exit 1
126 if test "$DO_INIT" = true -o ! -d "$BUILD_ROOT/.build.binaries/dists" ; then
127 echo "creating repository metadata..."
128 createrepo_debian $BUILD_ROOT/.build.binaries ${ARCH} ${DIST}
131 # Write our default configuration variables
132 mkdir -p $BUILD_ROOT/etc/live
133 cat > $BUILD_ROOT/etc/live/build.conf <<-EOF
134 LB_DEBIAN_INSTALLER_DISTRIBUTION="${DIST}"
135 LB_DISTRIBUTION="${DIST}"
136 LB_PARENT_DISTRIBUTION="${DIST}"
137 LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION="${DIST}"
138 LB_PARENT_MIRROR_BOOTSTRAP="file:/.build.binaries/"
139 LB_PARENT_MIRROR_CHROOT="file:/.build.binaries/"
140 LB_PARENT_MIRROR_CHROOT_SECURITY="file:/.build.binaries/"
141 LB_PARENT_MIRROR_BINARY="file:/.build.binaries/"
142 LB_PARENT_MIRROR_BINARY_SECURITY="file:/.build.binaries/"
143 LB_PARENT_MIRROR_DEBIAN_INSTALLER="file:/.build.binaries/"
144 LB_MIRROR_BOOTSTRAP="file:/.build.binaries/"
145 LB_MIRROR_CHROOT="file:/.build.binaries/"
146 LB_MIRROR_CHROOT_SECURITY="file:/.build.binaries/"
147 LB_MIRROR_BINARY="file:/.build.binaries/"
148 LB_MIRROR_BINARY_SECURITY="file:/.build.binaries/"
149 LB_MIRROR_DEBIAN_INSTALLER="file:/.build.binaries/"
150 LB_APT_SECURE="false"
151 LIVE_IMAGE_NAME="${RECIPEFILE%.livebuild}"
154 # Expand live-build configuration to $TOPDIR/$LIVEBUILD_ROOT
155 echo "Expanding live-build configuration"
156 tar -xvf $BUILD_ROOT/$TOPDIR/SOURCES/$RECIPEFILE \
157 -C $BUILD_ROOT/$TOPDIR/$LIVEBUILD_ROOT || cleanup_and_exit 1
159 # Skip top-level directory if it matches recipe name, ...
160 local files=($BUILD_ROOT/$TOPDIR/$LIVEBUILD_ROOT/*)
161 # ... but ignore some well known names
162 files=(${files[@]%%*/auto})
163 files=(${files[@]%%*/config})
164 files=(${files[@]%%*/local})
165 if [ ${#files[@]} -eq 1 ] && \
166 [ -d $BUILD_ROOT/$TOPDIR/$LIVEBUILD_ROOT/${RECIPEFILE%.livebuild} ]
168 LIVEBUILD_ROOT="LIVEBUILD_ROOT/${RECIPEFILE%.livebuild}"
171 # Sanity check to not configure archives inside configuration
172 files=($BUILD_ROOT/$TOPDIR/$LIVEBUILD_ROOT/config/archives/*)
173 if [ ${#files[@]} -gt 0 ]; then
174 echo "E: No configuration in config/archives/* allowed"
178 # TODO: Add the repository public key
179 # cp ... $BUILD_ROOT/$TOPDIR/$LIVEBUILD_ROOT/config/archives/debian.key
181 if [ -x $BUILD_ROOT/usr/lib/build/livebuild_pre_run ] ; then
182 echo "Running OBS build livebuild_pre_run hook"
183 chroot $BUILD_ROOT su -c \
184 "export RECIPEFILE=${RECIPEFILE}; /usr/lib/build/livebuild_pre_run" \
185 - root < /dev/null || cleanup_and_exit 1
188 # TODO: this might move to lb auto/config file
189 if [ -f $BUILD_ROOT/$TOPDIR/SOURCES/livebuild_pre_run ] ; then
190 cp $BUILD_ROOT/$TOPDIR/SOURCES/livebuild_pre_run \
191 $BUILD_ROOT/.build.livebuild_pre_run
192 chmod +x $BUILD_ROOT/.build.livebuild_pre_run
193 echo "Running package livebuild_pre_run hook"
194 chroot $BUILD_ROOT su -c \
195 "export RECIPEFILE=${RECIPEFILE}; /.build.livebuild_pre_run" \
196 - root < /dev/null || cleanup_and_exit 1
199 chroot $BUILD_ROOT su -c "cd $TOPDIR/$LIVEBUILD_ROOT && lb build" - root \
200 < /dev/null || cleanup_and_exit 1
202 # extract build result basenames
203 local build_results=""
204 for i in $BUILD_ROOT/$TOPDIR/$LIVEBUILD_ROOT/* ; do
205 test -f "$i" || continue
208 build_results="${build_results}\n${i%%.hybrid.iso}"
211 build_results="${build_results}\n${i%%.iso}"
214 build_results="${build_results}\n${i%%.img}"
217 build_results="${build_results}\n${i%%.netboot.tar*}"
220 build_results="${build_results}\n${i%%.tar*}"
227 # Fail the build if no build results are found
228 if [ -z "${build_results}" ] ; then
229 echo "No live-build result found"
233 # move created products (and their metadata files) to destination
234 local buildnum="${RELEASE:+-Build${RELEASE}}"
235 for prefix in $(echo -e ${build_results} | sort | uniq) ; do
236 for f in ${prefix}.* ; do
238 $BUILD_ROOT/$TOPDIR/OTHER/${prefix##*/}${buildnum}${f#${prefix}}
244 recipe_resultdirs_livebuild() {
245 # our results are already in OTHER