#!/bin/tcsh -f
# JLdL 24Feb07.
#
# Copyright (C) 2005-2007 by Jorge L. deLyra <delyra@fma.if.usp.br>.
# This program may be copied and/or distributed freely. See the
# _ terms and conditions in /usr/share/doc/<package>/copyright.
#
# This interface calls either multi-dpkg-chroot or multi-dpkg-remote,
# _ depending on whether the --chroot or the --remote option is active;
# _ the default is to use the chroot version; it passes all the options
# _ and arguments onto the called program, except for the two options
# _ above and for the -h and --help options.
#
# Record the name this script was called with.
set name = `basename $0`
#
# Initialize a flag for the options --chroot and --remote.
set chroot = 1
#
# Initialize a variable for the list options and arguments.
set opargs = ""
#
# Process the command-line arguments.
foreach cla ( $* )
    #
    # Detect options.
    if ( "`echo -n $cla | cut -c 1`" == "-" ) then
	#
	# Now process the options.
	switch ( $cla )
	case "-h":
	case "--help":
	    #
	    # Print a usage message.
	    echo "usage: $name [--chroot|--remote] <options-and-arguments>"
	    echo "       --chroot: use the chroot version of the called program"
	    echo "       --remote: use the remote version of the called program"
	    echo "       run either multi-dpkg-chroot or multi-dpkg-remote,"
	    echo "       depending on which option above is active; the default"
	    echo "       is to use the --chroot version; you can use any options"
	    echo "       and arguments understood by the called program; run the"
	    echo "       commands '<program> -h' or 'man <program>' in order to"
	    echo "       look up all the possible options and arguments of these"
	    echo "       two programs; in order to get the details about this"
	    echo "       interface run 'man $name'"
	    exit 0
	    breaksw
	case "--chroot":
	    #
	    # Raise the chroot flag.
	    set chroot = 1
	    breaksw
	case "--remote":
	    #
	    # Lower the chroot flag.
	    set chroot = 0
	    breaksw
	default:
	    #
	    # Accumulate the options.
	    set opargs = ( $opargs $cla )
	    breaksw
	endsw
    #
    # Process non-option arguments.
    else
	#
	# Accumulate the arguments.
	set opargs = ( $opargs $cla )
    endif
end
#
# Define the location of the programs.
set sbindir = /usr/sbin
#
# Execute the chosen program, passing all the
# _ command-line options and arguments to it.
if ( $chroot ) then
    $sbindir/multi-dpkg-chroot $opargs
else
    $sbindir/multi-dpkg-remote $opargs
endif
