Allow usage with relative path to id-pbuild.sh
[git-tools-moved-to-github.git] / id-deb-build / id-pbuild.sh
index b9cd94d..fdb1442 100755 (executable)
@@ -58,12 +58,26 @@ if test "$do_help" = "yes"; then
     usage 1 1>&2
 fi
 
-PBUILDROOT=`dirname $0`/id-pbuild-root.sh
+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 test -d deb-src; then
+    cd deb-src
+else
+    $MKDEBSRC
+fi
+
 if test -d deb-src; then
     cd deb-src
 fi
@@ -93,6 +107,19 @@ fi
 echo "Dsc $PKG . Product $PRODUCT"
 echo "Ubuntu distros: $UBUNTU_DIST"
 echo "Debian distros: $DEBIAN_DIST"
+if test "${SUDO_USER}"; then
+    echo "Running as sudo."
+    echo "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
+    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 ${UBUNTU_DIST}; do
        scp ${dist}-*/* ftp.indexdata.dk:/home/ftp/pub/${PRODUCT}/ubuntu/${dist}
@@ -113,12 +140,19 @@ if $upload; then
 fi
 rm -f *.log
 
+# 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
+    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 ${USE_ARCHS}; do
-       sudo -n $PBUILDROOT \
+       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