Merge branch 'master' of ssh://hummus/home/git/pub/git-tools
[git-tools-moved-to-github.git] / id-deb-build / id-pbuild-root.sh
index 1707786..e0d1e14 100755 (executable)
@@ -1,69 +1,87 @@
 #!/bin/sh
-
 usage()
 {
     cat <<EOF
 Usage: id-pbuild-root.sh [OPTIONS]
 Options:
+        [--arch=architecture]
+        [--dist=distribution]
         [--dsc=dscfile]
-       [--dist=distribution]
-       [--arch=architecture]
-        [--home=home]
-
-This script is should be called with root privilege. It is meant to be
-called by id-pbuild.sh.
+        [--update=true|false]
 EOF
     exit $1
 }
+D0=`dirname $0`
 
+do_help=false
+update=true
 while test $# -gt 0; do
     case "$1" in
-       -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
-       *) optarg= ;;
+        -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
+        *) optarg= ;;
     esac
-    
     case $1 in
-       --dist=*)
-           dist=$optarg
-           ;;
-       --arch=*)
-           arch=$optarg
-           ;;
-       --dsc=*)
-           dsc=$optarg
-           ;;
-       --home=*)
-           HOME=$optarg
-           ;;
-       -*)
-           usage 1
-           ;;
+        --dist=*)
+            DIST=$optarg
+            ;;
+        --arch=*)
+            ARCH=$optarg
+            ;;
+        --dsc=*)
+            DSC=$optarg
+            ;;
+        --update=*)
+            update=$optarg
+            ;;
+        -*)
+            do_help=yes
+            ;;
     esac
     shift
 done
-
-PBUILDER=/usr/sbin/pbuilder
-
-if test -z "$dist" -o -z "$arch"; then
-    echo "dist and arch must be given"
-    usage 1
+if test "$do_help" = "yes"; then
+    usage 1 1>&2
 fi
-rm -fr ${dist}-${arch}
-
-if test ! -f $HOME/.pbuilderrc; then
-    echo "$HOME/.pbuilderrc missing"
+if test -z "$DIST"; then
+    echo "id-pbuild-root.sh: missing --dist"
     exit 1
 fi
-if test "$dsc"; then
-    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
+if test -z "$ARCH"; then
+    echo "id-pbuild-root.sh: missing --arch"
+    exit 1
 fi
+if test -z "$DSC"; then
+    echo "id-pbuild-root.sh: missing --dsc"
+    exit 1
+fi
+if test ! -x /usr/bin/lxc-attach; then
+    echo "No lxc-attach. Probably not running on mochi!!"
+    exit 1
+fi
+export DIST ARCH # export for pbuilder to see
+echo "$DIST-$ARCH begin"
+if $update; then
+    if ! lxc-attach -n pbuilder -- pbuilder --update --override-config >update-${DIST}-${ARCH}.log 2>&1; then
+        if ! lxc-attach -n pbuilder -- pbuilder --create >create-${DIST}-${ARCH}.log 2>&1; then
+            echo "$DIST-$ARCH failed. Inspect deb-src/create-${DIST}-${ARCH}.log"
+            exit 2
+        fi
+        if ! lxc-attach -n pbuilder -- pbuilder --update --override-config >update-${DIST}-${ARCH}.log 2>&1; then
+            echo "$DIST-$ARCH failed. Inspect deb-src/update-${DIST}-${ARCH}.log"
+           exit 2
+       fi
+   fi
+fi
+if ! lxc-attach -n pbuilder -- pbuilder --build $DSC >build-${DIST}-${ARCH}.log 2>&1; then
+    echo "$DIST-$ARCH failed. Inspect deb-src/build-${DIST}-${ARCH}.log"
+    exit 3
+fi
+echo "$DIST-$ARCH done"
+exit 0
 
 # Local Variables:
 # mode:shell-script
-# sh-indentation: 2
+# sh-indentation: 4
 # sh-basic-offset: 4
 # End:
+