nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1#!@shell@
2
3rootdb="/etc/pki/nssdb"
4userdb="$HOME/.pki/nssdb"
5dbentry="Belgium eID"
6libfile="/run/current-system/sw/lib/libbeidpkcs11.so"
7
8dbdir="$userdb"
9
10while true; do
11 case "$1" in
12 --help|"") cat << EOF
13(Un)register $dbentry with NSS-compatible browsers.
14
15Usage: `basename "$0"` [OPTION] ACTION [LIBRARY]
16
17Options:
18 --db PATH use custom NSS database directory PATH
19 --user use user NSS database $userdb (default)
20 --system use global NSS database $rootdb
21 --help show this message
22
23Actions:
24 add add $dbentry to NSS database
25 remove remove $dbentry from NSS database
26 show show $dbentry NSS database entry
27
28Default arguments if unspecified:
29 LIBRARY $libfile
30EOF
31 exit ;;
32 --db) dbdir="$2"
33 shift 2 ;;
34 --user) dbdir="$userdb"
35 shift ;;
36 --system)
37 dbdir="$rootdb"
38 shift ;;
39 -*) echo "$0: unknown option: '$1'" >&2
40 echo "Try --help for usage information."
41 exit 1 ;;
42 *) break ;;
43 esac
44done
45
46if [ "$2" ]; then
47 libfile="$2"
48 if ! [ -f "$libfile" ]; then
49 echo "$0: error: '$libfile' not found" >&2
50 exit 1
51 fi
52fi
53
54mkdir -p "$dbdir"
55if ! [ -d "$dbdir" ]; then
56 echo "$0: error: '$dbdir' must be a writable directory" >&2
57 exit 1
58fi
59
60dbdir="sql:$dbdir"
61
62echo "NSS database: $dbdir"
63echo "BEID library: $libfile"
64
65case "$1" in
66add) echo "Adding $dbentry to database:"
67 modutil -dbdir "$dbdir" -add "$dbentry" -libfile "$libfile" ||
68 echo "Tip: try removing the module before adding it again." ;;
69remove) echo "Removing $dbentry from database:"
70 modutil -dbdir "$dbdir" -delete "$dbentry" ;;
71show) echo "Displaying $dbentry database entry, if any:"
72 echo "Note: this may fail if you don't have the correct permissions." ;;
73'') exec "$0" --help ;;
74*) echo "$0: unknown action: '$1'" >&2
75 echo "Try --help for usage information."
76 exit 1 ;;
77esac
78
79ret=$?
80
81modutil -dbdir "$dbdir" -list "$dbentry" 2>/dev/null
82
83exit $ret