build: remove automake/autoconf build system
[oweals/opkg-lede.git] / utils / opkg-key
1 #!/bin/sh
2
3 # Based on apt-key from apt-0.6.25
4 # Licensed under GPL Version 2
5
6 set -e
7
8 usage() {
9     echo "Usage: opkg-key [options] command [arguments]"
10     echo
11     echo "Manage opkg's list of trusted keys"
12     echo
13     echo "  opkg-key add <file>          - add the key contained in <file> ('-' for stdin)"
14     echo "  opkg-key del <keyid>         - remove the key <keyid>"
15     echo "  opkg-key list                - list keys"
16     echo
17     echo "Options:"
18     echo "  -o <root>  Use <root> as the offline root directory"
19     echo
20 }
21
22 if [ "$1" = "-o" ]; then
23   ROOT=$2
24   shift 2
25   echo "Note: using \"$ROOT\" as root path"
26 else
27   ROOT=""
28 fi
29
30 command="$1"
31 if [ -z "$command" ]; then
32     usage
33     exit 1
34 fi
35 shift
36
37 if [ "$command" != "help" ] && ! which gpg >/dev/null 2>&1; then
38     echo >&2 "Warning: gnupg does not seem to be installed."
39     echo >&2 "Warning: opkg-key requires gnupg for most operations."
40     echo >&2
41 fi
42
43 # We don't use a secret keyring, of course, but gpg panics and
44 # implodes if there isn't one available
45
46 GPG="gpg --no-options --no-default-keyring --keyring $ROOT/etc/opkg/trusted.gpg --secret-keyring $ROOT/etc/opkg/secring.gpg --trustdb-name $ROOT/etc/opkg/trustdb.gpg"
47
48 case "$command" in
49     add)
50         $GPG --quiet --batch --import "$1"
51         echo "OK"
52         ;;
53     del|rm|remove)
54         $GPG --quiet --batch --delete-key --yes "$1"
55         echo "OK"
56         ;;
57     list)
58         $GPG --batch --list-keys
59         ;;
60     finger*)
61         $GPG --batch --fingerprint
62         ;;
63     adv*)
64         echo "Executing: $GPG $*"
65         $GPG $*
66         ;;
67     help)
68         usage
69         ;;
70     *)
71         usage
72         exit 1
73         ;;
74 esac