#!/bin/sh
Usage="
Usage: $0 [{password|-} [{salt|salt depth}]]"
test -z "$1" -o "$1" = "-" && read Passwd || Passwd="$1"
case "$2" in
  "")   Salt="`python3 -c "import bcrypt,sys; sys.stdout.write(bcrypt.gensalt(8).decode())"`";;
  [$]*) Salt="$2" ;;
  [1-9]*) Salt="`python3 -c "import bcrypt,sys; sys.stdout.write(bcrypt.gensalt($2).decode())"`";;
  *) echo "$Usage" >&2; exit 1;
esac
test "$?" = "0" || { echo "$Usage" >&2; exit 2; }
python3 -c "import bcrypt,sys; sys.stdout.write(bcrypt.hashpw('$Passwd'.encode(),b'$Salt').decode())"
test "$?" = "0" || { echo "$Usage" >&2; exit 3; }
