#!/bin/sh

# Usage: dacopy NEW_SUFFIX OLD_SUFFIX SOURCE_PACKAGE

# Copy the source package from the old suffix to the new suffix, where
# a suffix is probably one of "", "-proposed", or "-development"
#
# This copies any source or binary package built from the source
# package PACKAGE

: ${DA_SCRIPTS_DIR="$(dirname "$0")"}
. "$DA_SCRIPTS_DIR"/debian-versions.sh

if [ "$#" -lt 3 ]; then
    echo "Usage: dacopy NEW_SUFFIX OLD_SUFFIX SOURCE_PACKAGE" >&2
    exit 1
fi

if [ "$1" = "-bleeding" ] || [ "$2" = "-bleeding" ]; then
    echo "You're not supposed to move or copy things to or from -bleeding."
    if [ "${DA_SHOOT_SELF_IN_FOOT:-x}" != "yesplease" ]; then
	echo "Exiting..."
	exit 1
    fi
    echo -n "This is a terrible idea.  Type 'y' to continue anyway: "
    read answer
    if [ "$answer" != "y" ]; then
	echo "You have chosen wisely."
	exit 1
    fi
fi


case "${1}/${2}" in
  /-proposed) ;;
  /-development) ;;
  -proposed/-development) ;;
  *)
    echo "WAIT. You are about to copy $3"
    echo "  FROM debathena$2 TO debathena$1,"
    echo -n "which is probably backwards. Is that a good idea [yes/N]? "
    read yn
    if [ "$yn" != "yes" ]; then
      echo "that's what I thought. Exiting."
      exit 1
    fi ;;
esac

for code in $DEBIAN_CODES; do
    dareprepro copysrc "${code}${1}" "${code}${2}" "$3"
done
