Subversion Repositories general

Rev

Rev 1181 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/bin/sh

#
# make a FreeBSD port of the project
#

PROJ=rebootd

OUTDIR=output
FREEBSDDIR=${OUTDIR}/freebsd-port
COMMITDIR=releases
WEBDIR=26th.net:www/26th.net/html/public/projects/rebootd/bin    # scp format

# only commited revisions are allowed for release
CUR_REVISION=`svnversion .`
if ( ! echo ${CUR_REVISION} | grep -E '^[0-9]+$' > /dev/null ) ; then
        echo "Cannot make release - current revision ${CUR_REVISION} not commited" >> /dev/stderr
        #exit 1;
fi

# get last release version
(ls ${COMMITDIR}/${PROJ}-[0-9]*.tar.gz \
        | awk '
                BEGIN { maj=-1; min=0; rev=0; } 
                {       split($0,n,"-"); split(n[2],nn,"\.");
                        if(maj>nn[1]) next; if(maj<nn[1]) {maj=nn[1];min=nn[2];rev=nn[3];next;}
                        if(min>nn[2]) next; if(min<nn[2]) {min=nn[2];rev=nn[3];next}
                        if(rev<nn[3]) rev=nn[3];}
                END {print maj, min, rev;}' \
        | read VER_MAJOR VER_MINOR VER_REVISION ) \
        || { echo "Cannot find releases in ${COMMITDIR}" >> /dev/stderr; exit 2; }
[ ${VER_MAJOR} = "-1" ] || { echo "Cannot determine release version" >> /dev/stderr; exit 1; }

RELEASE_NAME=${PROJ}-${VER_MAJOR}.${VER_MINOR}.${VER_REVISION}
RELEASE_TAR=${RELEASE_NAME}.tar.gz

# create the tar
rm -rf ${FREEBSDDIR} \
        || { echo "Cannot delete ${FREEBSDDIR} dir" >> /dev/stderr; exit 2; }
mkdir ${FREEBSDDIR} \
        || { echo "Cannot create ${FREEBSDDIR} dir" >> /dev/stderr; exit 2; }
cp -r ports/freebsd ${FREEBSDDIR}/${PROJ} \
        || { echo "Cannot copy ports/freebsd to ${FREEBSDDIR}/${PROJ}" >> /dev/stderr; exit 2; }
sed -e 's/%VER_MAJOR%/${VER_MAJOR}/' -e 's/%VER_MINOR%/${VER_MINOR}/' \
        -e 's/%VER_REVISION%/${VER_REVISION}/' ports/freebsd/Makefile \
        > ${FREEBSDDIR}/${PROJ}/Makefile \
        || { echo "Cannot generate ${FREEBSDDIR}/${PROJ}/Makefile" >> /dev/stderr; exit 2; }
( cd ${COMMITDIR}; md5 ${RELEASE_TAR} ) > ${FREEBSDDIR}/${PROJ}/distinfo \
        || { echo "Cannot get MD5 of ${COMMITDIR}/${RELEASE_TAR}" >> /dev/stderr; exit 2; }
echo "SIZE (${RELEASE_TAR}) =" `stat -f '%z' ${COMMITDIR}/${RELEASE_TAR}` >> ${FREEBSDDIR}/${PROJ}/distinfo \
        || { echo "Cannot stat ${COMMITDIR}/${RELEASE_TAR}" >> /dev/stderr; exit 2; }
tar cf - --exclude '*/.svn' -C ${FREEBSDDIR} ${PROJ} | gzip > ${OUTDIR}/${PROJ}-freebsd-port.tar.gz \
        || { echo "Cannot create ${OUTDIR}/${PROJ}-freebsd-port.tar.gz" >> /dev/stderr; exit 2; }
rm -rf ${FREEBSDDIR} \
        || { echo "Cannot clear ${FREEBSDDIR} dir" >> /dev/stderr; exit 2; }

# commit the release
echo "Relase made successfully. Enter YES to commit it."
read confirm
if [ "$confirm" != "YES" ] ; then
        echo "you have to answer 'YES' to continue"
        exit 1
fi

cp ${OUTDIR}/${PROJ}-freebsd-port.tar.gz ${COMMITDIR} \
        || { echo "Cannot copy ${OUTDIR}/${PROJ}-freebsd-port.tar.gz to releases" >> /dev/stderr; exit 2; }
svn commit ${COMMITDIR}/${PROJ}-freebsd-port.tar.gz \
        -m "${PROJ}: auto commit of FreeBSD port for release ${VER_MAJOR}.${VER_MINOR}.${VER_REVISION}" \
        || { echo "Cannot commit ${COMMITDIR}/${PROJ}-freebsd-port.tar.gz" >> /dev/stderr; exit 2; }
svn up \
        || { echo "Cannot update working copy" >> /dev/stderr; exit 2; }

# publish to web
scp ${COMMITDIR}/${PROJ}-freebsd-port.tar.gz ${WEBDIR} \
        || { echo "Cannot publish ${COMMITDIR}/${PROJ}-freebsd-port.tar.gz to ${WEBDIR}" >> /dev/stderr; \
                exit 2; }

echo "FreeBSD port for relase ${RELEASE_NAME} is commited and published"