#!/bin/sh
# This script builds Debian packages for one or more distributions
# in i386/amd64 architectures. It uses pbuilder. pbuilder requires root
-# privilege and is invoked with sudo.
-#
-# In order to avoid having to type-in the password for it, you might
-# use something like this in sudoers
-# user ALL=NOPASSWD,SETENV: /usr/sbin/pbuilder
-# where user is your username.
+# privilege and so this script should be invoked with sudo.
usage()
{
cat <<EOF
-Usage: id-pbuild-all.sh [OPTIONS]
+Usage: id-pbuild.sh [OPTIONS]
Options:
[--debian=distros]
[--ubuntu=distros]
+ [--centos=distros]
[--upload]
[--concurrency=N]
+ [--product=X]
EOF
exit $1
}
upload=false
do_help=false
concurrency=4
+ARCHS="i386 amd64"
if test -f IDMETA; then
. ./IDMETA
esac
case $1 in
+ --debian=*)
+ DEBIAN_DIST=$optarg
+ ;;
--ubuntu=*)
UBUNTU_DIST=$optarg
;;
- --debian=*)
- DEBIAN_DIST=$optarg
+ --centos=*)
+ CENTOS_DIST=$optarg
+ ;;
+ --upload)
+ upload=true
;;
--concurrency=*)
concurrency=$optarg
;;
- --upload)
- upload=true
+ --product=*)
+ PRODUCT=$optarg
;;
-*)
do_help=yes
usage 1 1>&2
fi
-if test -d deb-src; then
- cd deb-src
+D0=`dirname $0`
+ID_DEB_BUILD=`cd $D0; pwd`
+PBUILDROOT=${ID_DEB_BUILD}/id-pbuild-root.sh
+if test ! -x $PBUILDROOT; then
+ echo "$PBUILDROOT not found"
+ exit 1
fi
+
+MKDEBSRC=${ID_DEB_BUILD}/id-mk-deb-src.sh
+if test ! -x $MKDEBSRC; then
+ echo "$MKDEBSRC not found"
+ exit 1
+fi
+
+if $upload; then
+ :
+else
+ if test "${SUDO_USER}"; then
+ if test ! -d deb-src; then
+ $MKDEBSRC
+ fi
+ else
+ if test -d deb-src; then
+ rm -f deb-src/*.gz
+ if test $? -ne 0; then
+ echo "deb-src could not be removed. Remove deb-src manually"
+ exit 1
+ fi
+ fi
+ $MKDEBSRC
+ fi
+fi
+cd deb-src
+
for f in *.dsc; do
if test -f "$f"; then
PKG=$f
echo "${PKG} does not exist"
exit 1
fi
-PBUILDER=/usr/sbin/pbuilder
-PRODUCT=`echo *.dsc|sed 's/_.*//g'`
-ARCHS="i386 amd64"
+if test -z "$PRODUCT"; then
+ PRODUCT=`echo *.dsc|sed 's/_.*//g'`
+fi
+if grep "Architecture: all" $PKG >/dev/null; then
+ USE_ARCHS=i386
+else
+ USE_ARCHS=$ARCHS
+fi
echo "Dsc $PKG . Product $PRODUCT"
echo "Ubuntu distros: $UBUNTU_DIST"
echo "Debian distros: $DEBIAN_DIST"
+echo "Centos distros: $CENTOS_DIST"
+if test "${SUDO_USER}"; then
+ echo "Running as sudo."
+ echo "Tip: You can avoid it by adding the following in /etc/sudoers"
+ echo "${SUDO_USER} ALL=NOPASSWD: ${ID_DEB_BUILD}/id-pbuild-root.sh"
+ HOME_EXPORT=/home/${SUDO_USER}
+else
+ sudo -k
+ HOME_EXPORT=$HOME
+fi
+if test ! -f ${HOME_EXPORT}/.pbuilderrc; then
+ echo "${HOME_EXPORT}/.pbuilderrc missing"
+ exit 1
+fi
+
if $upload; then
+ for dist in ${CENTOS_DIST}; do
+ arch=amd64
+ prodver=${PRODUCT}-${VERSION}
+ if ssh $dist "cd rpmbuild/SOURCES/${prodver} && ../../../proj/git-tools/id-rpm-build/upload-rpms.sh ${PRODUCT}.spec"; then
+ :
+ else
+ echo "Upload failed for $dist"
+ exit 1
+ fi
+ done
for dist in ${UBUNTU_DIST}; do
scp ${dist}-*/* ftp.indexdata.dk:/home/ftp/pub/${PRODUCT}/ubuntu/${dist}
done
for dist in ${DEBIAN_DIST}; do
scp ${dist}-*/* ftp.indexdata.dk:/home/ftp/pub/${PRODUCT}/debian/${dist}
done
- echo "Remember to update APT on ftp.indexdata.dk"
- echo "cd git-tools/update-archive"
+ echo ""
+ echo "===================================================="
+ echo "Remember to update APT/YUM on ftp.indexdata.dk !!!"
+ echo ""
+ echo "ssh ftp.indexdata.dk"
+ echo "cd ~/proj/git-tools/update-archive"
echo "sudo su"
echo "./update-archive.sh"
+ if test ${CENTOS_DIST}; then
+ echo "./update-yum-archive.sh"
+ fi
+ echo "===================================================="
exit 0
fi
+
+rm -f *.log
+
+# copy tars to centos build hosts
+for dist in ${CENTOS_DIST}; do
+ arch=amd64
+ prodver=${PRODUCT}-${VERSION}
+ tarname=${prodver}.tar.gz
+ if test ! -f ../${tarname}; then
+ echo "$tarname: missing"
+ exit 1
+ fi
+
+ if ssh $dist "test -f .rpmmacros && test -d rpmbuild/SOURCES && test -d rpmbuild/RPMS && test -d rpmbuild/SRPMS && test -x proj/git-tools/id-rpm-build/upload-rpms.sh"; then
+ :
+ else
+ echo "Host $dist does not seem to be prepared with git-tools and rpmbuild directories"
+ exit 1
+ fi
+
+ if scp ../${tarname} $dist:rpmbuild/SOURCES/ ; then
+ :
+ else
+ echo "Could not copy $tarname to $dist"
+ exit 1
+ fi
+ if ssh $dist "cd rpmbuild/SOURCES && rm -fr $prodver && tar zxf $tarname && cd ${prodver} && rpmbuild -ba ${PRODUCT}.spec" >${dist}-${arch}.log 2>&1; then
+ :
+ else
+ echo "FAILED: See ${dist}-${arch}.log"
+ exit 1
+ fi
+done
+
+# call our privileged wrapper to clean the directories, no --dsc option
+for dist in ${DEBIAN_DIST} ${UBUNTU_DIST}; do
+ for arch in ${USE_ARCHS}; do
+ sudo -n $PBUILDROOT --home=${HOME_EXPORT} --dist=$dist --arch=$arch
+ if test $? -ne 0; then
+ echo "FAILED"
+ echo "Run id-pbuild.sh using sudo or add yourself to /etc/sudoers:"
+ echo "${USER} ALL=NOPASSWD: ${ID_DEB_BUILD}/id-pbuild-root.sh"
+ exit 1
+ fi
+ done
+done
+
+# call our privileged wrapper to do the real work, with --dsc option
i=0
date
for dist in ${DEBIAN_DIST} ${UBUNTU_DIST}; do
- for arch in ${ARCHS}; do
- rm -fr ${dist}-${arch}
- (
- if test ! -f /var/cache/pbuilder/${dist}-${arch}-base.tgz; then
- sudo DIST=$dist ARCH=$arch $PBUILDER create
- fi
- for f in `find /var/cache/pbuilder/${dist}-${arch}-base.tgz -ctime +7`; do
- sudo DIST=$dist ARCH=$arch $PBUILDER update --override-config
- done
- sudo DIST=$dist ARCH=$arch $PBUILDER --build $PKG
- ) >${dist}-${arch}.log 2>&1 &
+ for arch in ${USE_ARCHS}; do
+ sudo -n $PBUILDROOT --home=${HOME_EXPORT} \
+ --dist=$dist --arch=$arch --dsc=$PKG >${dist}-${arch}.log 2>&1 &
i=`expr $i + 1`
if test $i -eq $concurrency; then
i=0
wait
+ if test -f ${dist}-${arch}/*.dsc; then
+ :
+ else
+ echo "FAILED: No .dsc file for ${dist}-${arch}"
+ exit 1
+ fi
fi
done
done
wait
for dist in ${DEBIAN_DIST} ${UBUNTU_DIST}; do
- for arch in ${ARCHS}; do
+ for arch in ${USE_ARCHS}; do
if test -f ${dist}-${arch}/*.dsc; then
:
else
- echo "No .dsc file for ${dist}-${arch}"
+ echo "FAILED: No .dsc file for ${dist}-${arch}"
exit 1
fi
done
done
+
date
echo "Done"
# Local Variables: