projects/aports·blob v2.0_rc8 · refs

88 lines · 2.0 KiB

1#!/bin/sh
2
3# sign indexes
4# Copyright (c) 2009 Natanael Copa <[email protected]>
5#
6# Distributed under GPL-2
7#
8# Depends on: busybox utilities, fakeroot,
9#
10
11abuild_ver=@VERSION@
12sysconfdir=@sysconfdir@
13
14abuild_conf=${ABUILD_CONF:-"$sysconfdir/abuild.conf"}
15abuild_home=${ABUILD_USERDIR:-"$HOME/.abuild"}
16abuild_userconf=${ABUILD_USERCONF:-"$abuild_home/abuild.conf"}
17
18die() {
19 echo "$@" >&2
20 exit 1
21}
22
23usage() {
24 echo "abuild-sign $abuild_ver"
25 echo "usage: abuild-sign [-hq] [-k PRIVKEY] [-p PUBKEY] INDEXFILE..."
26 echo "options:"
27 echo " -h Show this help"
28 echo " -k The private key to use for signing"
29 echo " -p The name of public key. apk add will look for /etc/apk/keys/PUBKEY"
30 exit 1
31}
32
33# read config
34[ -f "$abuild_conf" ] && . "$abuild_conf"
35
36# read user config if exists
37[ -f "$abuild_userconf" ] && . "$abuild_userconf"
38
39privkey="$PACKAGER_PRIVKEY"
40
41while getopts "hk:p:q" opt; do
42 case $opt in
43 h) usage;;
44 k) privkey=$OPTARG;;
45 p) pubkey=$OPTARG;;
46 q) quiet=yes;;
47 esac
48done
49shift $(( $OPTIND - 1))
50
51if [ -z "$privkey" ]; then
52 echo "No private key found. Use 'abuild-keygen' to generate the keys"
53 echo "Then you can either:"
54 echo " 1. set the PACKAGER_PRIVKEY in $abuild_userconf"
55 echo " (Note that 'abuild-keygen -a' does this for you)"
56 echo " 2. set the PACKAGER_PRIVKEY in $abuild_conf"
57 echo " 3. specify the key with the -k option"
58 echo ""
59 exit 1
60fi
61
62if [ -z "$pubkey" ]; then
63 pubkey=${PACKAGER_PUBKEY:-"${privkey}.pub"}
64fi
65
66# we are actually only interested in the name, not the file itself
67keyname=${pubkey##*/}
68
69for f in "$@"; do
70 i=$(readlink -f $f)
71 [ -d "$i" ] && i="$i/APKINDEX.tar.gz"
72 repo="${i%/*}"
73 cd "$repo" || die "Failed to sign $i"
74 sig=".SIGN.RSA.$keyname"
75 openssl dgst -sha1 -sign "$privkey" -out "$sig" "$i" || die "Failed to sign $i"
76 cd "$repo"
77 tmptargz=$(mktemp)
78 tar -c "$sig" | abuild-tar --cut | gzip -9 > "$tmptargz"
79 tmpsigned=$(mktemp)
80 cat "$tmptargz" "$i" > "$tmpsigned"
81 rm -f "$tmptargz"
82 mv "$tmpsigned" "$i"
83 if [ -z "$quiet" ]; then
84 echo "Signed $i"
85 fi
86done
87
88exit 0