#!/usr/bin/env bash
set -u

get_md5sum() {
    [ $# -gt 0 ] || return 255
    [ -f "$1" ]  || return 255
    local f="$1"
    grep -v "^>" "$f" | tr -d '\n\r' | md5sum | cut -d " " -f 1
    return $?
}


[ $# -ge 1 ] || { echo "usage: $0 <file1> [<file2>]"; exit 255; }
fA="$1"
fB=""
[ $# -gt 1 ] && fB="$2"

mdA=$(get_md5sum $fA)
mdB=0
[ ${#fB} -gt 0 ] && mdB=$(get_md5sum $fB)

[[ "$mdA" == "$mdB" ]] && { echo "same fasta data"; exit 0; }
[[ "$mdB" == "0" ]] && { echo "$mdA"; exit 0; }
echo "differs: <$mdA>   <$mdB>"
exit 255
