#!/bin/sh -e

cmd=${0##*/}

case $cmd in
    apt-get)
	echo "fake-$cmd: $*"
        if [ "$1" = source ]; then
	    cp /testpkg_* .
	fi ;;
    apt-cache)
#	echo "fake-$cmd: $*"
        if [ "$1" = showsrc ]; then
	    printf "Package: %s
Package-List:
 %s deb utils optional arch=any
Format: 1.0
" "$3" "$3"
	fi ;;
    dpkg)
	if [ "$1" = "--print-architecture" ]; then
	    echo powerpc
	else
	    echo "fake-$cmd: $*"
	fi ;;
    dpkg-query)
	# shellcheck disable=SC2016
        if [ "$*" = '-W -f ${Version} apt' ]; then
	    printf "99:9.9.9"
	else
	    echo "fake-$cmd: $*"
	fi ;;
    dpkg-source)
	echo "fake-$cmd: $*"
        if [ "$1" = "-x" ]; then
	    mkdir "$3"
	    tar -C "$3" --strip-components=1 -xf "${2%.dsc}".tar.*
	fi ;;
    id)
       echo root ;;
    su)
	shift 4
	exec bash -c "$@" ;;
    *)
	echo "fake-$cmd: $*" ;;
esac
