#!/bin/sh

# Usage: damove NEW_SUFFIX OLD_SUFFIX SOURCE_PACKAGE

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

set -e

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

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

new_suffix="$1"; shift
old_suffix="$1"; shift

for pkg in "$@"; do
    dacopy "$new_suffix" "$old_suffix" "$pkg"
    if [ "$new_suffix" != "$old_suffix" ]; then
	daremove "$old_suffix" "$pkg"
    fi
    if hash zwrite 2>/dev/null; then
	zwrite -d -c debathena -i apt -m "Moved $pkg from $old_suffix to ${new_suffix:-production}"
    fi
done
