#!/bin/bash
#
# Copyright (c) 2012, James C. McPherson. All rights reserved.
#
# This script takes an installed build of Xpra (see http://xpra.org)
# and turns it into a new IPS package for distribution.
#

PKGSEND=/usr/bin/pkgsend
PKGRECV=/usr/bin/pkgrecv
PKGREPO=/usr/bin/pkgrepo
PKGDEPOT=/usr/lib/pkg.depotd

MKDIR=/usr/bin/mkdir
ECHO=/usr/bin/echo
SVN=/usr/bin/svn
GZIP=/usr/bin/gzip
SED=/usr/bin/sed
SLEEP=/usr/bin/sleep
KILL=/usr/bin/kill
PGREP=/usr/bin/pgrep

REPODIR=/tmp/Xpra.repo.$$
# change MYPUBLISHER if you want
MYPUBLISHER=
CSET=`svn info ../src |awk '/^Revision: / {print $2}'`
# change the REV depending on what the latest is
REV=0.3.11

# update the manifest...
${SED} -e"s,@REV@,$REV,g" -e"s,@CSET@,$CSET,g" < manifest.base > Xpra.manifest.$CSET
${MKDIR} -p ${REPODIR}
${PKGREPO} create ${REPODIR}
${PKGREPO} add-publisher -s ${REPODIR} ${MYPUBLISHER:-JMCP}

# startup the pkg.depotd server on a high (>1024) port number
${PKGDEPOT} -p 24699 -d ${REPODIR} > /tmp/Xpra.depotd.log.$$ 2>&1 &
${SLEEP} 30
${PKGSEND} publish -s http://localhost:24699 --fmri-in-manifest \
	-d / Xpra.manifest.$CSET

${PKGRECV} -s http://localhost:24699 -d Xpra.$CSET.p5p -a winswitch/xpra
${GZIP} -9 Xpra.$CSET.p5p

# kill off the depotd:
${KILL} $( ${PGREP} -n pkg.depotd )


