1 #################################################################
3 # Debian live-build specific functions.
5 # Author: Adrian Schroeter <adrian@suse.de>
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_snapcraft() {
26 TOPDIR=/usr/src/packages
27 test "$DO_INIT_TOPDIR" = false || rm -rf "$BUILD_ROOT$TOPDIR"
28 for i in OTHER SOURCES SNAPCRAFT_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_snapcraft() {
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 # snapcraft already installed!
113 # $BUILD_ROOT the Debian chroot
114 # $TOPDIR/SOURCES includes the snapcraft sources
115 # $TOPDIR/$SNAPCRAFT_ROOT where snapcraft will be called
116 # $RECIPEFILE the name of the snapcraft.yaml config file
118 recipe_build_snapcraft() {
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 SNAPCRAFT_ROOT="SNAPCRAFT_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 chroot $BUILD_ROOT su -c "cd $TOPDIR/SOURCES && snapcraft build" - root \
132 || cleanup_and_exit 1
133 chroot $BUILD_ROOT su -c "cd $TOPDIR/SOURCES && snapcraft snap" - root \
134 || cleanup_and_exit 1
136 # extract build result basenames
137 local build_results=""
138 for i in $BUILD_ROOT/$TOPDIR/SOURCES/* ; do
139 test -f "$i" || continue
142 build_results="${build_results}\n${i%%.snap}"
149 # Fail the build if no build results are found
150 if [ -z "${build_results}" ] ; then
151 echo "No live-build result found"
155 # move created products (and their metadata files) to destination
156 local buildnum="${RELEASE:+-Build${RELEASE}}"
157 for prefix in $(echo -e ${build_results} | sort | uniq) ; do
158 for f in ${prefix}.* ; do
160 $BUILD_ROOT/$TOPDIR/OTHER/${prefix##*/}${buildnum}${f#${prefix}}
166 recipe_resultdirs_snapcraft() {
167 # our results are already in OTHER