Separate, privileged, script for id-pbuild.sh.
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 3 Aug 2011 12:52:42 +0000 (14:52 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 3 Aug 2011 12:53:04 +0000 (14:53 +0200)
The separate script, id-pbuild-root.sh, might be specified in
/etc/sudoers as follows, to prevent interactive password typing..
For example, for "adam":
adam  ALL=NOPASSWD: /home/adam/proj/git-tools/id-deb-build/id-pbuild-root.sh

id-deb-build/id-pbuild-root.sh [new file with mode: 0755]
id-deb-build/id-pbuild.sh

diff --git a/id-deb-build/id-pbuild-root.sh b/id-deb-build/id-pbuild-root.sh
new file mode 100755 (executable)
index 0000000..f1f8239
--- /dev/null
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+usage()
+{
+    cat <<EOF
+Usage: id-pbuild1.sh [OPTIONS]
+Options:
+        [--dsc=dscfile]
+       [--dist=distribution]
+       [--arch=architecture]
+EOF
+    exit $1
+}
+
+while test $# -gt 0; do
+    case "$1" in
+       -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
+       *) optarg= ;;
+    esac
+    
+    case $1 in
+       --dist=*)
+           dist=$optarg
+           ;;
+       --arch=*)
+           arch=$optarg
+           ;;
+       --dsc=*)
+           dsc=$optarg
+           ;;
+       -*)
+           do_help=yes
+           ;;
+    esac
+    shift
+done
+
+PBUILDER=/usr/sbin/pbuilder
+
+rm -fr ${dist}-${arch}
+if test ! -f /var/cache/pbuilder/${dist}-${arch}-base.tgz; then
+    DIST=$dist ARCH=$arch $PBUILDER --create
+fi
+DIST=$dist ARCH=$arch $PBUILDER --update --override-config
+DIST=$dist ARCH=$arch $PBUILDER --build $dsc
+
+# Local Variables:
+# mode:shell-script
+# sh-indentation: 2
+# sh-basic-offset: 4
+# End:
index 888b482..b9cd94d 100755 (executable)
@@ -6,7 +6,7 @@
 usage()
 {
     cat <<EOF
-Usage: id-pbuild-all.sh [OPTIONS]
+Usage: id-pbuild.sh [OPTIONS]
 Options:
        [--debian=distros]
        [--ubuntu=distros]
@@ -47,9 +47,6 @@ while test $# -gt 0; do
         --product=*)
            PRODUCT=$optarg
            ;;
-        --remote=*)
-           REMOTE=$optarg
-           ;;
        -*)
            do_help=yes
            ;;
@@ -61,27 +58,16 @@ if test "$do_help" = "yes"; then
     usage 1 1>&2
 fi
 
-if test "$REMOTE"; then
-    if test ! -d deb-src; then
-       echo "deb-src not in current directory"
-       exit 1
-    fi
-    cd deb-src
-    PRODUCT=`echo *.dsc|sed 's/_.*//g'`
-    cd ..
-    ssh $REMOTE "mkdir -p $PRODUCT/deb-src"
-    scp IDMETA $REMOTE:$PRODUCT
-    scp deb-src/*.gz deb-src/*.dsc $REMOTE:$PRODUCT/deb-src
-    if $upload; then
-       ssh $REMOTE "cd $PRODUCT; \$HOME/proj/git-tools/id-deb-build/id-pbuild.sh --upload"
-    else
-       ssh $REMOTE "cd $PRODUCT; sudo \$HOME/proj/git-tools/id-deb-build/id-pbuild.sh"
-    fi
-    exit 0
+PBUILDROOT=`dirname $0`/id-pbuild-root.sh
+if test ! -x $PBUILDROOT; then
+    echo "$PBUILDROOT not found"
+    exit 1
 fi
+
 if test -d deb-src; then
     cd deb-src
 fi
+
 for f in *.dsc; do
     if test -f "$f"; then
        PKG=$f
@@ -95,9 +81,8 @@ if test ! -e "$PKG"; then
     echo "${PKG} does not exist"
     exit 1
 fi
-PBUILDER=/usr/sbin/pbuilder
 if test -z "$PRODUCT"; then
-       PRODUCT=`echo *.dsc|sed 's/_.*//g'`
+    PRODUCT=`echo *.dsc|sed 's/_.*//g'`
 fi
 ARCHS="i386 amd64"
 if grep "Architecture: all" $PKG >/dev/null; then
@@ -126,12 +111,6 @@ if $upload; then
     echo "===================================================="
     exit 0
 fi
-# remove existing package directories
-for f in [a-z]*; do
-    if test -d $f; then
-       rm -fr $f
-    fi
-done
 rm -f *.log
 
 i=0
@@ -139,18 +118,18 @@ date
 
 for dist in ${DEBIAN_DIST} ${UBUNTU_DIST}; do
     for arch in ${USE_ARCHS}; do
-        rm -fr ${dist}-${arch}
-       (
-           if test ! -f /var/cache/pbuilder/${dist}-${arch}-base.tgz; then
-               DIST=$dist ARCH=$arch $PBUILDER create
-           fi
-           DIST=$dist ARCH=$arch $PBUILDER update --override-config
-           DIST=$dist ARCH=$arch $PBUILDER --build $PKG
-           ) >${dist}-${arch}.log 2>&1 &
+       sudo -n $PBUILDROOT \
+           --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 "No .dsc file for ${dist}-${arch}"
+               exit 1
+           fi
        fi
     done
 done