projects/aports·blob v2.19.0 · refs

108 lines · 2.3 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
9program_version=@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$program $program_version - sign indexes
48Usage: $program [-k PRIVKEY] [-p PUBKEY] INDEXFILE...
49 $program -e
50Options:
51 -e, --installed Check only of there exist a private key for signing
52 -k, --private KEY The private key to use for signing
53 -p, --public KEY The name of public key. apk add will look for
54 /etc/apk/keys/KEY
55 -q, --quiet
56 -h, --help Show this help
57
58__EOF__
59}
60
61check_installed=false
62privkey="$PACKAGER_PRIVKEY"
63pubkey=
64quiet=
65
66args=`getopt -o ek:p:qh --long installed,private:,public:,quiet,help -n "$program" -- "$@"`
67if [ $? -ne 0 ]; then
68 usage
69 exit 2
70fi
71eval set -- "$args"
72while true; do
73 case $1 in
74 -e|--installed) check_installed=true;;
75 -k|--private) privkey=$2; shift;;
76 -p|--public) pubkey=$2; shift;;
77 -q|--quiet) quiet=1;; # suppresses msg
78 -h|--help) usage; exit;;
79 --) shift; break;;
80 *) exit 1;; # getopt error
81 esac
82 shift
83done
84if [ $# -eq 0 ] && ! $check_installed; then
85 usage
86 exit 2
87fi
88
89if [ -z "$privkey" ]; then
90 cat >&2 << __EOF__
91No private key found. Use 'abuild-keygen' to generate the keys.
92Then you can either:
93 * set the PACKAGER_PRIVKEY in $ABUILD_USERCONF
94 ('abuild-keygen -a' does this for you)
95 * set the PACKAGER_PRIVKEY in $ABUILD_CONF
96 * specify the key with the -k option to $program
97
98__EOF__
99 exit 1
100fi
101
102if [ -z "$pubkey" ]; then
103 pubkey=${PACKAGER_PUBKEY:-"${privkey}.pub"}
104fi
105
106if ! $check_installed; then
107 do_sign "$@"
108fi