#!/bin/bash # Convert .pem certificates from to an sqlite # nssdb at . The destination DB will be created # if it does not exist, otherwise the certificates will # be added to the existing nssdb. # cert_to_db cert_to_nssdb() { local db="$2" local src="$1" if ! [ -f "$db/cert9.db" ] && ! [ -f "$db/key4.db" ]; then mkdir -p "$db" || return 1 certutil -N --empty-password -d sql:"$db" || return 1 fi if [ -f "$src" ]; then certutil -A -d sql:"$db" -n "$( basename "$src" )" -t C,C,C -i "$src" return # pass exit code fi if [ -d "$src" ]; then find "$src" -type l -name "*.?" | while read -r file; do file="$( readlink -f "$file" )" # Make sure there's nothing after this call so the exit code survives the loop end certutil -A -d sql:"$db" -n "$( basename "$file" )" -t C,C,C -i "$file" done return # pass exit code from within loop fi echo "Source is not a file or directory" >&2 return 1 }