projects/aports·blob v2.16.0 · refs

102 lines · 2.1 KiB

1#!/bin/sh
2
3# abuild-sign - sign indexes
4# Copyright (c) 2009 Natanael Copa <[email protected]>
5#
6# Distributed under GPL-2
7#
8
9abuild_ver=@VERSION@
10datadir=@datadir@
11
12if ! [ -f "$datadir/functions.sh" ]; then
13 echo "$datadir/functions.sh: not found" >&2
14 exit 1
15fi
16. "$datadir/functions.sh"
17
18do_sign() {
19 local f i keyname repo
20
21 # we are actually only interested in the name, not the file itself
22 keyname=${pubkey##*/}
23
24 for f; do
25 i=$(readlink -f $f)
26 [ -d "$i" ] && i="$i/APKINDEX.tar.gz"
27 repo="${i%/*}"
28 (
29 set -e
30 cd "$repo"
31 sig=".SIGN.RSA.$keyname"
32 openssl dgst -sha1 -sign "$privkey" -out "$sig" "$i"
33 tmptargz=$(mktemp)
34 tar -c "$sig" | abuild-tar --cut | gzip -9 > "$tmptargz"
35 tmpsigned=$(mktemp)
36 cat "$tmptargz" "$i" > "$tmpsigned"
37 rm -f "$tmptargz" "$sig"
38 chmod 644 "$tmpsigned"
39 mv "$tmpsigned" "$i"
40 msg "Signed $i"
41 ) || die "failed to sign $i"
42 done
43}
44
45usage() {
46 cat >&2 <<__EOF__
47$prog $abuild_ver - sign indexes
48Usage: $prog [-k PRIVKEY] [-p PUBKEY] INDEXFILE...
49Options:
50 -k, --private KEY The private key to use for signing
51 -p, --public KEY The name of public key. apk add will look for /etc/apk/keys/KEY
52 -q, --quiet
53 -h, --help Show this help
54
55__EOF__
56}
57
58privkey="$PACKAGER_PRIVKEY"
59pubkey=
60quiet=
61
62args=`getopt -o k:p:qh --long private:,public:,quiet,help -n "$prog" -- "$@"`
63if [ $? -ne 0 ]; then
64 usage
65 exit 2
66fi
67eval set -- "$args"
68while true; do
69 case $1 in
70 -k|--private) privkey=$2; shift;;
71 -p|--public) pubkey=$2; shift;;
72 -q|--quiet) quiet=1;; # suppresses msg
73 -h|--help) usage; exit;;
74 --) shift; break;;
75 *) exit 1;; # getopt error
76 esac
77 shift
78done
79if [ $# -eq 0 ]; then
80 usage
81 exit 2
82fi
83
84if [ -z "$privkey" ]; then
85 cat >&2 << __EOF__
86No private key found. Use 'abuild-keygen' to generate the keys.
87Then you can either:
88 * set the PACKAGER_PRIVKEY in $ABUILD_USERCONF
89 ('abuild-keygen -a' does this for you)
90 * set the PACKAGER_PRIVKEY in $ABUILD_CONF
91 * specify the key with the -k option to $prog
92
93__EOF__
94 exit 1
95fi
96
97if [ -z "$pubkey" ]; then
98 pubkey=${PACKAGER_PUBKEY:-"${privkey}.pub"}
99fi
100
101do_sign "$@"
102exit 0