summaryrefslogtreecommitdiff
path: root/build-recipe-snapcraft
blob: ae27c12e5213a6bfe986e7b94d52ec689513492c (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#################################################################
#
# Debian live-build specific functions.
#
# Author: Adrian Schroeter <adrian@suse.de>
#
# This file is part of build.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (see the file COPYING); if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
#################################################################

recipe_setup_snapcraft() {
    TOPDIR=/usr/src/packages
    test "$DO_INIT_TOPDIR" = false || rm -rf "$BUILD_ROOT$TOPDIR"
    for i in OTHER SOURCES SNAPCRAFT_ROOT ; do
	mkdir -p "$BUILD_ROOT$TOPDIR/$i"
    done
    chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
    if test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
	mv "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
    else
	cp -p "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
    fi
}

recipe_prepare_snapcraft() {
    :
}

createrepo_debian() {
    local DIR=${1}
    local ARCH=${2}
    local DIST=${3}

    if [ -z "${DIR}" -o ! -d ${DIR} -o ${DIR} = ${DIR##${BUILD_ROOT}} ] ; then
        return
    fi

    pushd ${DIR} >/dev/null

    # cleanup existing repository files
    rm -f Packages Packages.gz Release
    rm -fr dists

    mkdir -p dists/${DIST}
    # Suite is symlinked to Codename
    ln -s ${DIST} dists/stable

    # create Packages and Sources files
    mkdir -p dists/${DIST}/main/binary-${ARCH}
    mkdir -p dists/${DIST}/main/source
    cat > ${BUILD_ROOT}/.createrepo_debian.tmp.sh <<-EOF
	cd /.build.binaries || exit 1
	dpkg-scanpackages -m . > dists/${DIST}/main/binary-${ARCH}/Packages
	gzip -c9 < dists/${DIST}/main/binary-${ARCH}/Packages \
	    > dists/${DIST}/main/binary-${ARCH}/Packages.gz
	dpkg-scansources . > dists/${DIST}/main/source/Sources
	gzip -c9 dists/${DIST}/main/source/Sources \
	    > dists/${DIST}/main/source/Sources.gz
	EOF
    chroot $BUILD_ROOT su -c "sh /.createrepo_debian.tmp.sh" - root
    local RESULT=$?
    rm -f $BUILD_ROOT/.createrepo_debian.tmp.sh
    [ "${RESULT}" != 0 ] && return

    # create Release file
    pushd dists/${DIST} >/dev/null
    cat > Release <<-EOF
	Origin: Debian
	Label: Debian
	Suite: stable
	Version: 7.1
	Codename: ${DIST}
	Date: Sat, 15 Jun 2013 10:55:26 UTC
	Description: Debian repository created by build-recipe-livebuild
	Components: main
	EOF
    echo "SHA256:" >> Release
    for file in main/binary-${ARCH}/Packages* ; do
        local SUM=( $(sha256sum ${file}) )
        local SIZE=$(stat -c '%s' ${file})
        echo " ${SUM} ${SIZE} ${file}" >> Release
    done
    for file in main/source/Sources* ; do
        local SUM=( $(sha256sum ${file}) )
        local SIZE=$(stat -c '%s' ${file})
        echo " ${SUM} ${SIZE} ${file}" >> Release
    done
    popd >/dev/null

    # TODO: this is missing the signature with the private key

    popd >/dev/null
}

# This script expects that the $BUILD_ROOT is a Debian installation with
# snapcraft already installed!
#
# Variables:
# $BUILD_ROOT the Debian chroot
# $TOPDIR/SOURCES includes the snapcraft sources
# $TOPDIR/$SNAPCRAFT_ROOT where snapcraft will be called
# $RECIPEFILE the name of the snapcraft.yaml config file

recipe_build_snapcraft() {
    local ARCH=$(chroot $BUILD_ROOT su -c "dpkg-architecture -qDEB_BUILD_ARCH")
#    local DIST=$(chroot $BUILD_ROOT su -c "lsb_release --codename" | awk '{ print $2 }')
    local SNAPCRAFT_ROOT="SNAPCRAFT_ROOT"

#    [ -z "${ARCH}" -o -z "${DIST}" ] && cleanup_and_exit 1

    test -d $BUILD_ROOT/.build.binaries || cleanup_and_exit 1
    if test "$DO_INIT" = true -o ! -d "$BUILD_ROOT/.build.binaries/dists" ; then
	echo "creating repository metadata..."
        createrepo_debian $BUILD_ROOT/.build.binaries ${ARCH} ${DIST}
    fi

    chroot $BUILD_ROOT su -c "cd $TOPDIR/SOURCES && snapcraft build" - root \
	|| cleanup_and_exit 1
    chroot $BUILD_ROOT su -c "cd $TOPDIR/SOURCES && snapcraft snap" - root \
	|| cleanup_and_exit 1

    # extract build result basenames
    local build_results=""
    for i in $BUILD_ROOT/$TOPDIR/SOURCES/* ; do
	test -f "$i" || continue
	case "${i##*/}" in
	    *.snap)
		build_results="${build_results}\n${i%%.snap}"
		;;
	    *)
		;;
	esac
    done

    # Fail the build if no build results are found
    if [ -z "${build_results}" ] ; then
	echo "No live-build result found"
	cleanup_and_exit 1
    fi

    # move created products (and their metadata files) to destination
    local buildnum="${RELEASE:+-Build${RELEASE}}"
    for prefix in $(echo -e ${build_results} | sort | uniq) ; do
	for f in ${prefix}.* ; do
	    mv ${f} \
		$BUILD_ROOT/$TOPDIR/OTHER/${prefix##*/}${buildnum}${f#${prefix}}
	    BUILD_SUCCEEDED=true
	done
    done
}

recipe_resultdirs_snapcraft() {
    # our results are already in OTHER
    :
}

# Local Variables:
# mode: Shell-script
# End: