Upstream changes for adding S3 support and fixing for alternate versions of sed