#!/bin/sh
# script from Jamin W. Collins  BTS: #255165
# name this script 'pbuilder-woody', 'pbuilder-sid', 'pbuilder-sarge', 'pbuilder-experimental' etc.

OPERATION=$1
DIST=`basename $0 | cut -f2 -d '-'`
PROCEED=false
BASE_DIR="$HOME/pbuilder"
ARCH=`basename $0 | cut -f3 -d '-'`
APTCACHE="$BASE_DIR/cache/apt/$DIST-$ARCH"
case $OPERATION in
   create|update|build|clean|login|execute )
      PROCEED=true
      ;;
esac
if [ ! -d $APTCACHE ] ; then
    mkdir -p $APTCACHE
fi
if ( $PROCEED == true ) then
   shift 
   sudo pbuilder $OPERATION \
      --architecture $ARCH \
      --basetgz $BASE_DIR/$DIST-$ARCH-base.tgz \
      --distribution $DIST \
      --components "main contrib" \
      --aptcache $APTCACHE \
      --buildresult $BASE_DIR/result/$DIST/$ARCH \
      "$@"
else
   echo "Invalid command..."
   echo "Valid commands are:"
   echo "   create"
   echo "   update"
   echo "   build"
   echo "   clean"
   echo "   login"
   echo "   execute"
   exit 1
fi
