id-pbuild-all invokes sudo itself. Note about sudosers
[git-tools-moved-to-github.git] / id-deb-build / id-pbuild-all.sh
index b1db5a9..c88ec51 100755 (executable)
 #!/bin/sh
-PKG="$1"
+# 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.
+
+usage()
+{
+    cat <<EOF
+Usage: id-pbuild-all.sh [OPTIONS]
+Options:
+       [--debian=distros]
+       [--ubuntu=distros]
+       [--update=true|false]
+       [--upload]
+       [--concurrency=N]
+EOF
+    exit $1
+}
+
+# things that might be set by options
+upload=false
+update=true
+do_help=false
+concurrency=4
+
+if test -f IDMETA; then
+    . ./IDMETA
+fi
+while test $# -gt 0; do
+    case "$1" in
+       -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
+       *) optarg= ;;
+    esac
+    
+    case $1 in
+       --ubuntu=*)
+           UBUNTU_DIST=$optarg
+           ;;
+       --debian=*)
+           DEBIAN_DIST=$optarg
+           ;;
+        --update=*)
+           update=$optarg
+           ;;
+        --concurrency=*)
+           concurrency=$optarg
+           ;;
+        --upload)
+           upload=true
+           ;;
+       -*)
+           do_help=yes
+           ;;
+    esac
+    shift
+done
+
+if test "$do_help" = "yes"; then
+    usage 1 1>&2
+fi
+
+if test -d deb-src; then
+    cd deb-src
+fi
+for f in *.dsc; do
+    if test -f "$f"; then
+       PKG=$f
+    fi
+done
 if test -z "$PKG"; then
-       echo "Specify .dsc file"
-       exit 1
+    echo "Specify .dsc file"
+    exit 1
 fi
 if test ! -e "$PKG"; then
-       echo "${PKG} does not exist"
-       exit 1
+    echo "${PKG} does not exist"
+    exit 1
+fi
+PBUILDER=/usr/sbin/pbuilder
+PRODUCT=`echo *.dsc|sed 's/_.*//g'`
+ARCHS="i386 amd64"
+echo "Dsc $PKG . Product $PRODUCT"
+echo "Ubuntu distros: $UBUNTU_DIST"
+echo "Debian distros: $DEBIAN_DIST"
+if $upload; then
+    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 "sudo su"
+    echo "./update-archive.sh"
+    exit 0
 fi
-for dist in etch lenny; do
-       for arch in i386 amd64; do
-               DIST=$dist ARCH=$arch pbuilder update --override-config
-               DIST=$dist ARCH=$arch pbuilder --build $PKG
-       done
+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
+           if $update; then
+               sudo DIST=$dist ARCH=$arch $PBUILDER update --override-config
+           fi
+           sudo DIST=$dist ARCH=$arch $PBUILDER --build $PKG
+           ) >${dist}-${arch}.log 2>&1 &
+       i=`expr $i + 1`
+       if test $i -eq $concurrency; then
+           i=0
+           wait
+       fi
+    done
+done
+wait
+for dist in ${DEBIAN_DIST} ${UBUNTU_DIST}; do
+    for arch in ${ARCHS}; do
+       if test -f ${dist}-${arch}/*.dsc; then
+           :
+       else
+           echo "No .dsc file for ${dist}-${arch}"
+           exit 1
+       fi
+    done
 done
+date
+echo "Done"
+# Local Variables:
+# mode:shell-script
+# sh-indentation: 2
+# sh-basic-offset: 4
+# End: