Merge "Support BuildFlags: nocumulaterpms" into devel
[tools/build.git] / build-recipe-simpleimage
1 recipe_setup_simpleimage() {
2     TOPDIR=/usr/src/packages
3     rm -rf "$BUILD_ROOT$TOPDIR"
4     for i in OTHER SOURCES LIVEBUILD_ROOT ; do
5         mkdir -p "$BUILD_ROOT$TOPDIR/$i"
6     done
7     chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
8     if test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
9         mv "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
10     else
11         cp -p "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
12     fi
13 }
14
15 recipe_prepare_simpleimage() {
16     BUILD_USER="root"
17 }
18
19 recipe_build_simpleimage() {
20     TOPDIR=/usr/src/packages
21
22     echo "creating simple image..."
23     cd $BUILD_ROOT || cleanup_and_exit 1
24     export SRCDIR="$TOPDIR/SOURCES"
25
26     NAME="`sed -n 's|Name:[[:blank:]]*||p' $BUILD_ROOT$TOPDIR/SOURCES/simpleimage`"
27     [ -n "$NAME" ] || NAME="simpleimage"
28     VERSION="`sed -n 's|Version:[[:blank:]]*||p' $BUILD_ROOT$TOPDIR/SOURCES/simpleimage`"
29     [ -n "$VERSION" ] || VERSION="`date -u +%y.%m.%d-%H.%M.%S`"
30
31     SHELL="/bin/sh"
32     [ -x $BUILD_ROOT/bin/bash ] && SHELL="/bin/bash"
33     if [ "`grep '^%build$' $BUILD_ROOT$TOPDIR/SOURCES/simpleimage`" ]; then
34       echo "Running integration script..."
35       sed -n '/%build/,$ p' $BUILD_ROOT$TOPDIR/SOURCES/simpleimage | tail -n +2 | chroot $BUILD_ROOT $SHELL -x || cleanup_and_exit 1
36       echo "Integration script finished."
37     fi
38
39     echo "Compresing the final image, this can take a while..."
40     echo
41     TAR="tar"
42     if test -x /usr/bin/bsdtar; then
43         TAR="/usr/bin/bsdtar --format gnutar --chroot"
44     fi
45     TOPDIRS=
46     for DIR  in .* * ; do
47       case "$DIR" in
48         .|..) continue ;;
49         .build*) continue ;;
50         .simpleimage*) continue ;;
51         .srcfiles*) continue ;;
52         .pkgs) continue ;;
53         .rpm-cache) continue ;;
54         .tmp) continue ;;
55         installed-pkg) continue ;;
56         proc|sys) continue ;;
57       esac
58       TOPDIRS="$TOPDIRS $DIR"
59     done
60         rm -rf "$BUILD_ROOT$TOPDIR"
61     mkdir -p .tmp/{proc,sys}
62     if ! $TAR -cvzf .simpleimage.tar.gz --one-file-system $TOPDIRS -C .tmp proc sys; then
63       cleanup_and_exit 1
64     fi
65     if [ -x "`which mksquashfs 2> /dev/null`" ]; then
66       echo
67       echo "Tarball done, creating squashfs image as well"
68       echo
69       mksquashfs $TOPDIRS .tmp/proc .tmp/sys .simpleimage.squashfs -info -keep-as-directory -no-progress || cleanup_and_exit 1
70     fi
71     echo "simple image created."
72
73     DEST="$BUILD_ROOT$TOPDIR/OTHER"
74     mkdir -p "$DEST"
75     mv $BUILD_ROOT/.simpleimage.tar.gz $DEST/$NAME-${VERSION}_${BUILD_ARCH%%:*}.tar.gz
76     if [ -r .simpleimage.squashfs ]; then
77       mv $BUILD_ROOT/.simpleimage.squashfs $DEST/$NAME-${VERSION}_${BUILD_ARCH%%:*}.squashfs
78     fi
79     rm -f $BUILD_ROOT/.build.packages
80     ln -s ${TOPDIR#/} $BUILD_ROOT/.build.packages
81     test -d "$SRCDIR" && cd "$SRCDIR"
82     cleanup_and_exit 0
83 }
84
85 recipe_resultdirs_simpleimage() {
86     :
87 }
88