FREIGHT_SCRIPT = """
cd "$1"; shift
DISTNAME=$1; shift
-aptly repo add "$DISTNAME" "$@"
-aptly publish update "$DISTNAME" filesystem:"${DISTNAME%-*}":
-rm "$@"
+set +e
+aptly repo search "$DISTNAME" "${@%.deb}" >/dev/null 2>&1
+RET=$?
+set -e
+if [[ $RET -eq 0 ]]; then
+ echo "Not adding $@, it is already present in repo $DISTNAME"
+ rm "$@"
+else
+ aptly repo add -remove-files "$DISTNAME" "$@"
+ aptly publish update "$DISTNAME" filesystem:"${DISTNAME%-*}":
+fi
"""
def __init__(self, glob_root, rel_globs, target, ssh_host, ssh_opts, repo):