#!/bin/sh -e

cmd=${0##*/}

case $cmd in
    apt-get)
	echo "fake-$cmd: $*"
        if [ "$1" = source ]; then
	    cp /testpkg_* .
	fi ;;
    apt-cache)
	case "$1" in
	    showsrc)
		cat <<-EOF
		Package: $2
		Package-List:
		 $2 deb utils optional arch=any
		Format: 1.0
		EOF
		;;
	    policy)
		cat <<-EOF
		$2:
		  Installed: 42
		  Candidate: 42
		  Version table:
		 *** 42 500
		        500 http://mirror.invalid/ fluffy/main amd65 Packages
		EOF
		;;
	    *)
		echo "fake-$cmd: $*"
		;;
	esac
	;;
    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
