owrelease 9.49 KB
Newer Older
1
#!/bin/bash
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

#---------------------------------------------------------------------------
#
# Project: OpenWalnut ( http://www.openwalnut.org )
#
# Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
# For more information see http://www.openwalnut.org/copying
#
# This file is part of OpenWalnut.
#
# OpenWalnut is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OpenWalnut 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
#
#---------------------------------------------------------------------------

#############################################################################################################
# Release Configuration Variables
#############################################################################################################

31
# Which version?
32
VERSION_BASE=1.3.0
33

34
# Any additonal tags?
35
VERSION_TAGS=""
36

37
# Should the package number contain the HG revision?
38
VERSION_INCLUDE_HG=1
39

40 41
# Where to grab the sources?
REPO="ssh://openwalnut.com//srv/hg/ow"
42
REPO_BRANCH="OpenWalnut_1.3"
43 44
# build from a release branch?
#REPO_BRANCH="OpenWalnut_$VESION"
45 46

# Which packages to build
47
PACKAGES="deb src"
48 49

# Define which chroot/distribution to use for build the packages
50
# NOTE: supported are "sid wheezy squeeze lucid maverick natty"
51 52 53

# As we only need a source DEB, we do not build the deb for all supported distributions. The NeuroDebian project is doing this.
# DISTRIBUTIONS_DEB="sid wheezy squeeze lucid maverick natty"
54
DISTRIBUTIONS_DEB="sid wheezy quantal precise oneiric"
55 56

# use these distributions to build binary tgz
57 58 59
#DISTRIBUTIONS_TGZ="sid wheezy squeeze lucid maverick natty"
# I am not sure whether this is useful? The binary would depend on a very specific boost version ... maybe we fix this by providing the boost libs too?
DISTRIBUTIONS_TGZ=""
60 61 62

# Architectures to build for
# NOTE: we need the debsrc package.
63
ARCHITECTURES_DEB="i386 amd64"
64
# Build binary tgz for 386 and amd64
65
ARCHITECTURES_TGZ="amd64"
66 67 68

# where to put the created stuff?
RELEASE_DIR="OpenWalnut-Release"
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

#############################################################################################################
# Internal Variables
#############################################################################################################

# Ensure english warning/error text (easier googling)
export LC_ALL=C

# Where to put the files
CHECKOUT_DIR="OpenWalnut-hg"

# the source config file
CONFIG_FILE=owrelease.config

# Where to put logs from this script not distri/arch or pack specific.
MAINLOGFILE="$0.log"

#############################################################################################################
# Functions
#############################################################################################################

#########################################################################################################
# Checkout a fresh OW copy and create config file. Copy newest script versions.
Bootstrap()
{
    echo "* Removing old checkout."
    rm -rf "$CHECKOUT_DIR"
    if [ $? -ne 0 ]; then
        echo " * Remove failed."
        exit 1
    fi

    # get code
    echo "* Cloning OpenWalnut repository \"$REPO\"."
    hg clone --branch $REPO_BRANCH "$REPO" "$CHECKOUT_DIR"
    if [ $? -ne 0 ]; then
105 106 107 108 109 110 111 112
        echo " * Cloning failed. Wrong repository?"
        exit 1
    fi

    echo "* Creating release directory \"$RELEASE_DIR\"."
    mkdir -p $RELEASE_DIR
    if [ $? -ne 0 ]; then
        echo " * Creating release directory failed."
113 114 115 116 117
        exit 1
    fi

    # write config file
    echo "SRC_DIR=$CHECKOUT_DIR" > $CONFIG_FILE
118
    echo "RELEASE_DIR=$RELEASE_DIR" >> $CONFIG_FILE
119 120 121
    # The version. You can use shell commands to evaluate this. The command is
    # called inside the working dir of owpack script.
    echo "VERSION_BASE=$VERSION_BASE" >> $CONFIG_FILE
122
    if [ $VERSION_INCLUDE_HG -ne 0 ]; then
123
        echo "VERSION=$VERSION_BASE$VERSION_TAGS+hg`cd $CHECKOUT_DIR;hg parents --template "{rev}"`" >> $CONFIG_FILE
124
    else
125
        echo "VERSION=$VERSION_BASE$VERSION_TAGS" >> $CONFIG_FILE
126
    fi
127 128 129 130 131 132 133 134

    # get the latest scripts
    cp $CHECKOUT_DIR/tools/release/owpack .
    cp $CHECKOUT_DIR/tools/release/owbuildchroot .
    cp $CHECKOUT_DIR/tools/release/owrelease .
}

#########################################################################################################
135
# Cleanup any mess. Remove build stuff but keeps config and checkout (and scripts), like after bootstrap.
136 137 138 139 140 141 142 143 144 145 146
CleanUp()
{
    echo "* Removing logs."
    # we need root since the build-user in the chroot is root and created some
    # files
    rm -f $0-*.log
    rm -f $MAINLOGFILE

    echo "* Removing buildfiles."
    sudo ./owpack clean || exit $?

147 148 149 150 151 152 153 154 155 156
    echo "* Removing packages."
    rm -rf $RELEASE_DIR/*
}

#########################################################################################################
# Complete cleanup. Removes everything created.
Purge()
{
    CleanUp

157 158 159 160 161 162 163 164 165 166
    echo "* Removing checkout."
    rm -rf $CHECKOUT_DIR

    echo "* Removing scripts."
    rm -f owpack
    rm -f owbuildchroot
    rm -f owrelease

    echo "* Removing config."
    rm -f $CONFIG_FILE
167 168 169

    echo "* Removing releases."
    rm -rf $RELEASE_DIR
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
}

#########################################################################################################
# Build for different target systems
BuildAll()
{
    echo "LOG created by $0 on `date`" > $MAINLOGFILE

    # does config exist? Needed. If not found, abort
    if [ ! -f $CONFIG_FILE ]; then
        echo " * File \"$CONFIG_FILE\" not found! Forgot to bootstrap?"
        exit 1
    fi

    for pack in $PACKAGES
    do
        # gather information on the needed distributions and architectures for this type of package
        PkgDistributions="sid" # default
        PkgArchitectures="i386 amd64"
        case "$pack" in
            src)
                PkgDistributions="sid"
                PkgArchitectures="amd64"
                ;;
            deb)
                PkgDistributions=$DISTRIBUTIONS_DEB
                PkgArchitectures=$ARCHITECTURES_DEB
                ;;
            tgz)
                PkgDistributions=$DISTRIBUTIONS_TGZ
                PkgArchitectures=$ARCHITECTURES_TGZ
                ;;
            *)
                echo "* Unknown package \"$pack\"" | tee -a $MAINLOGFILE
                exit 1
                ;;
        esac

208
        # build package for each of its distributions and architectures
209 210 211 212 213 214 215 216
        for distri in $PkgDistributions
        do
            for arch in $PkgArchitectures
            do
                LOGFILE=$0-$pack-$distri-$arch.log
                echo "LOG created by $0 on `date`" > $LOGFILE

                # check for chroot existence
217 218
                echo "* Check build chroot for $pack-$distri-$arch." | tee -a $MAINLOGFILE
                sudo ./owbuildchroot $arch $distri check &>> $MAINLOGFILE
219 220
                if [ $? -ne 0 ]; then
                    echo " * Build chroot not found. Creating." | tee -a $MAINLOGFILE
221
                    sudo ./owbuildchroot $arch $distri create &>> $MAINLOGFILE
222 223 224 225 226 227 228 229
                    if [ $? -ne 0 ]; then
                        echo " * Error. Build chroot not found." | tee -a $MAINLOGFILE
                        # do not be very tolerant. A missing chroot is a fatal error
                        exit 1
                    fi
                fi

                # do
230 231
                echo "* Building $pack for \"$distri-$arch\". Log: $LOGFILE" | tee -a $MAINLOGFILE
                sudo ./owbuildchroot $arch $distri run /build/owpack $pack $distri-$arch /build &>> $LOGFILE
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258

                # for later error reporting
                if [ $? -ne 0 ]; then
                    echo " * Error while building for \"$distri\", $arch. Check \"$LOGFILE\" for details" | tee -a $MAINLOGFILE
                    continue
                fi
            done
        done
    done
}

#########################################################################################################
# Something went wrong. Quit.
#
# Param 1 the error code to return.
Exit()
{
    echo "*** Failed. Exiting."
    exit $1
}

#########################################################################################################
# Quit and print usage info.
UsageExit()
{
        echo "Central script for release management. Bootstraps the OpenWalnut Release code and starts the building."
        echo ""
259
        echo "Usage: $0 {clean|purge|bootstrap|do}"
260
        echo "  COMMANDS:"
261 262
        echo "    clean: removes created build sub-directories and logs but keeps bootstrap status."
        echo "    purge: like clean but also removes checkouts and scripts."
263 264 265 266 267 268 269 270 271 272 273 274 275 276
        echo "    bootstrap: gets a fresh copy of OpenWalnut."
        echo "    do: does the actual building."
        echo ""
        Exit 2
}

#########################################################################################################
# Main

# Handle user command
case "$1" in
    clean)
        CleanUp
        ;;
277 278 279
    purge)
        Purge
        ;;
280 281 282 283 284 285 286 287 288 289
    bootstrap)
        Bootstrap || Exit $?
        ;;
    do)
        BuildAll || Exit $?
        ;;
    *)
        UsageExit
        ;;
esac