#!/bin/bash
set -e
if test "$#" -ne 2; then
  echo "Usage: $0 <nssdb-dir> <Browser Name>" >&2
  echo >&2
  echo "Example: $0 nssdb-basebrowser 'Base Browser'" >&2
  exit 1
fi
nssdb="$(dirname "$0")/$1"
BrowserName="$2"
if test -d $nssdb
then
    echo "Error: $nssdb already exists" >&2
    exit 1
fi
mkdir -p $nssdb
chmod 700 $nssdb
certutil -d $nssdb -N --empty-password
certutil -d $nssdb -S -x -g 4096 -Z SHA384 -n nightly-marsigner -s "CN=$BrowserName Nightly MAR signing key" -t,,
certutil -d $nssdb -L -r -n nightly-marsigner -o $nssdb/nightly-marsigner.der
