catalyst_packages.sh 3.89 KB
Newer Older
1 2 3 4
#!/bin/bash
#
# Builds and releases Mahara to the debian repo
# 
5
# This script can release just one version (stable|unstable), or both at once
6 7
#
set -e
8 9 10

BUILDDIR="/tmp/mahara/release"
REPODIR="/tmp/mahara/repo"
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
ARCHLIST="i386 amd64"
DATE="`date`"


echo " *** STOP *** "
echo " Make sure you have merged master into pkg-catalyst, and the latest"
echo " stable branch into the appropriate pkg-catalyst-* branch. If you"
echo " have not done this, hit Ctrl-C now and do so."
read junk

RELEASE=$1
if [ "$RELEASE" = "" ]; then
    echo -n "Building ALL versions: are you sure? (y/N) "
    read ANS
    if [ "$ANS" != "y" ] && [ "$ANS" != "Y" ]; then
        echo "Abort."
        exit 1
    fi
    RELEASELIST="stable unstable"
elif [ "$RELEASE" != "stable" ] && [ "$RELEASE" != "unstable" ]; then
    echo "Invalid release: $RELEASE"
    exit 1
else
    RELEASELIST=$RELEASE
fi

if [ -d ${BUILDDIR} ]; then
    rm -rf ${BUILDDIR}
fi
if [ -d ${REPODIR} ]; then
    rm -rf ${REPODIR}
fi

44
mkdir -p ${BUILDDIR}
45 46 47 48 49 50 51 52 53 54 55

# Create repo dirs
for release in $RELEASELIST; do
    mkdir -p ${REPODIR}/dists/${release}/mahara
    pushd ${REPODIR}/dists/${release}/mahara
    mkdir binary-all
    for arch in ${ARCHLIST}; do mkdir binary-${arch}; done
    popd
    mkdir -p ${REPODIR}/pool/${release}
done

56 57 58 59 60 61
pushd ${BUILDDIR}

# Get a checkout of Mahara for working with, and find out what the stable
# release is currently
git clone -n "git+ssh://git.catalyst.net.nz/git/public/mahara.git" mahara
pushd mahara
62 63
STABLE_RELEASE="`ls -1 .git/refs/tags | egrep '[0-9]+\.[0-9]+\.[0-9]+_RELEASE$' | tail -n1`"
STABLE_DEBIAN_BRANCH=${STABLE_RELEASE:0:3}
64
popd
65 66 67 68 69 70 71 72


# Build Stable
if [ "$RELEASE" = "" ] || [ "$RELEASE" = "stable" ]; then
    echo
    echo "Building ${STABLE_RELEASE} ..."

    pushd ${BUILDDIR}/mahara
73
    git checkout -b "pkg-catalyst-${STABLE_DEBIAN_BRANCH}" "origin/pkg-catalyst-${STABLE_DEBIAN_BRANCH}"
74 75
    make
    popd
76
    mv *.deb ${REPODIR}/pool/stable/
77 78 79 80 81 82 83 84
fi

# Build Unstable
if [ "$RELEASE" = "" ] || [ "$RELEASE" = "unstable" ]; then
    echo
    echo "Building Unstable ..."

    pushd ${BUILDDIR}/mahara
85
    git checkout -b pkg-catalyst origin/pkg-catalyst
86 87
    make
    popd
88
    mv *.deb ${REPODIR}/pool/unstable/
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
fi

# Link other arches into all and build packages
for release in $RELEASELIST; do
    pushd ${REPODIR}/pool

    for arch in all ${ARCHLIST}; do
        dpkg-scanpackages ${release} /dev/null /pool/ | /bin/gzip -9 > ${REPODIR}/dists/${release}/mahara/binary-${arch}/Packages.gz
        dpkg-scanpackages ${release} /dev/null /pool/ > ${REPODIR}/dists/${release}/mahara/binary-${arch}/Packages
    done

    popd

    pushd ${REPODIR}/dists/${release}

    # Create Release file
    cat <<EOHDR >Release
Origin: Mahara
Label: Mahara
Suite: ${release}
Date: ${DATE}
Architectures: ${ARCHLIST}
Components: mahara
Description: Mahara ${release} repository
MD5Sum:
EOHDR
    
    for file in `find mahara -type f -name 'Packages*'`; do
        MD5="`md5sum $file | cut -c1-32`"
        SIZE="`cat $file | wc -c`"
        printf " %s %16d %s\n" "${MD5}" "${SIZE}" "${file}" >>Release
    done

    gpg --yes --armour --sign-with 1D18A55D --detach-sign --output Release.gpg Release

    popd
done

# Steal the latest index.html and dump into 
128
pushd ${BUILDDIR}/mahara
129
git cat-file blob origin/pkg-catalyst:debian/index.html > ${REPODIR}/index.html
130 131 132
popd

popd
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149

# Now (optionally) sync the repo to the git repository
echo " The repo has now been set up in ${REPODIR}. If you're really sure,"
echo " this script can rsync this to the git repository."
echo " rsync to git repository? [y/N] "
read ANS
if [ "$ANS" != "y" ] && [ "$ANS" != "Y" ]; then
    echo "Abort."
    exit 1
fi

if [ "$RELEASE" = "" ]; then
    rsync -PIlvr --delete-after --no-p --no-g --chmod=Dg+ws,Fg+w ${REPODIR}/* locke.catalyst.net.nz:/home/ftp/pub/mahara/
else
    rsync -PIlvr --no-p --no-g --chmod=Dg+ws,Fg+w ${REPODIR}/* locke.catalyst.net.nz:/home/ftp/pub/mahara/
fi

150 151
rm -rf ${BUILDDIR}
rm -rf ${REPODIR}