#!/usr/bin/env bash

export LC_ALL=C

set -euo pipefail

help_message() {
  echo "Output sha256sums from Gitian build output."
  echo "Usage: $0 AssetDirectory > sha256sums"
}

if [ "$#" -ne 1 ]; then
  echo "Error: Expects 1 argument: AssetDirectory"
  exit 1
fi

case $1 in
  -h|--help)
    help_message
    exit 0
    ;;
esac

# Trim off preceding whitespace that exists in the manifest
trim() {
  sed 's/^\s*//'
}

# Get the hash of the source tarball and output that first
cat "$1"/linux/bitcoin-abc-*linux-res.yml | grep -E "bitcoin-abc-[0-9.]+.tar.gz" | trim

# Output hashes of all of the binaries
cat "$1"/linux/bitcoin-abc-*linux-res.yml | grep -E "bitcoin-abc-[0-9.]+.*-linux-.*.tar.gz" | trim
cat "$1"/win/bitcoin-abc-*win-res.yml | grep -E -- "bitcoin-abc-[0-9.]+-win.*.(exe|tar.gz|zip)" | trim
cat "$1"/osx/bitcoin-abc-*osx-res.yml | grep -E -- "bitcoin-abc-[0-9.]+-osx.*.(dmg|tar.gz)" | trim

Add a script to generate sha256sums from Gitian output
Add a script to generate sha256sums from Gitian output

Summary:
Currently, the sha256sums files are assembled by hand (copy-pasting the hash results from the Gitian build).
This patch introduces make-sha256sums.sh to do this automatically.

Test Plan:
```
make-sha256sums.sh -h
make-sha256sums.sh    # errors as expected
make-sha256sums.sh [path to some gitian output]
make-sha256sums.sh path/to/0.20.9 > jasonbcox-sha256sums.0.20.9
```

Reviewers: #bitcoin_abc, deadalnix, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D4893
