build: add integration for managing opkg package feed keys
[openwrt/svn-archive/archive.git] / package / system / opkg / files / opkg-key
1 #!/bin/sh
2
3 usage() {
4 cat <<EOF
5 Usage: $0 <command> <arguments...>
6 Commands:
7 add <file>: Add keyfile <file> to opkg trusted keys
8 remove <file>: Remove keyfile matching <file> from opkg trusted keys
9 verify <sigfile> <list>: Check list file <list> against signature file <sigfile>
10
11 EOF
12 exit 1
13 }
14
15 opkg_key_verify() {
16 local sigfile="$1"
17 local msgfile="$2"
18
19 (
20 zcat "$msgfile" 2>/dev/null ||
21 cat "$msgfile" 2>/dev/null
22 ) | usign -V -P /etc/opkg/keys -q -x "$sigfile" -m -
23 }
24
25 opkg_key_add() {
26 local key="$1"
27 [ -n "$key" ] || usage
28 [ -f "$key" ] || echo "Cannot open file $1"
29 local fingerprint="$(usign -F -p "$key")"
30 mkdir -p "/etc/opkg/keys"
31 cp "$key" "/etc/opkg/keys/$fingerprint"
32 }
33
34 opkg_key_remove() {
35 local key="$1"
36 [ -n "$key" ] || usage
37 [ -f "$key" ] || echo "Cannot open file $1"
38 local fingerprint="$(usign -F -p "$key")"
39 rm -f "/etc/opkg/keys/$fingerprint"
40 }
41
42 case "$1" in
43 add)
44 shift
45 opkg_key_add "$@"
46 ;;
47 remove)
48 shift
49 opkg_key_remove "$@"
50 ;;
51 verify)
52 shift
53 opkg_key_verify "$@"
54 ;;
55 *) usage ;;
56 esac