#!/bin/sh # S3 bucket S3="s3://apt-archive.postgresql.org/pub/repos/apt" set -eu FILE="$1" if [ "${2:-}" ]; then DEST="$2" else DEST="$FILE" fi if ! test -f "$FILE"; then echo "$FILE is missing" >&2 BASE="${FILE##*/}" if test -s "morgue/$BASE"; then FILE="morgue/$BASE" echo "Using $FILE instead" else exit 1 fi fi case $DEST in dists/*|pool/*) ;; *) echo "Refusing to upload file outside of dists/ or pool/" >&2 exit 1 ;; esac [ -t 1 ] && echo "$FILE ..." # upload to S3 aws s3 cp --quiet "$FILE" "$S3/$DEST" # try if we can get the file back RESTORE=$(mktemp --tmpdir upload-to-s3.XXXXXX) trap "rm -f $RESTORE" EXIT aws s3 cp --quiet "$S3/$DEST" "$RESTORE" cmp "$FILE" "$RESTORE"