#!/bin/bash

if [ $# -ne 2 ]; then
  echo "Usage: $0 /dev/sdX /path/to/image.iso"
  exit 1
fi

if [ "$(stat -c %F $1)" != "block special file" ]; then
  echo "Error: device not found $1" >/dev/stderr
  exit 2
fi

if [ ! -r "$2" ]; then
  echo "Error: ISO file not found $2" >/dev/stderr
  exit 3
fi

if [ ! -r $1 ]; then
  echo "Error: Permission denied reading $1" >/dev/stderr
  exit 4
fi

SIZE=$(stat -c %s ${2})
SHA1=$(dd if=$1 bs=${SIZE} count=1 2>/dev/null | sha1sum)

echo "SHA1: $SHA1"
exit 0
