Debian Codegraph @

jetring-build

raw
1 #!/bin/sh
2 # Creates a keyring from a set of changesets. Can run in incremental or
3 # full build mode.
4 set -e
5
6 incremental=
7 if [ "$1" = "-i" ]; then
8 shift 1
9 incremental=1
10 elif [ "$1" = "-I" ]; then
11 shift 1
12 incremental=1
13 force=1
14 fi
15
16 if [ -z "$1" ] || [ -z "$2" ]; then
17 echo "Usage: jetring-build [-i] keyring changesetdir" >&2
18 exit 1
19 fi
20
21 # avoid gnupg touching ~/.gnupg
22 GNUPGHOME=$(mktemp -d -t jetring.XXXXXXXX)
23 export GNUPGHOME
24 trap cleanup exit
25 cleanup () {
26 rm -rf "$GNUPGHOME"
27 }
28
29 keyring=$(readlink -f "$1") # gpg works better with absolute keyring paths
30 changesetdir="$2"
31
32 if [ ! -e "$changesetdir/index" ]; then
33 echo "$changesetdir/index not found" >&2
34 exit 1
35 fi
36
37 if [ -s "$changesetdir/index" ]; then
38 jetring-checksum "$changesetdir"
39 fi
40
41 if [ -n "$JETRING_SIGN" ]; then
42 JETRING_SIGN=$(readlink -f "$JETRING_SIGN")
43 gpg --no-auto-check-trustdb --options /dev/null \
44 --no-default-keyring --keyring "$JETRING_SIGN" \
45 --verify "$changesetdir/index.gpg" "$changesetdir/index"
46 fi
47
48 if [ "$incremental" ]; then
49 if [ ! -e "$keyring.lastchangeset" ]; then
50 if [ ! "$force" ]; then
51 echo "$keyring.lastchangeset not found, cannot do incremental update" >&2
52 exit 1
53 else
54 incremental=
55 fi
56 else
57 if [ ! -e "$keyring" ]; then
58 if [ ! "$force" ]; then
59 echo "$keyring not found, cannot do incremental update" >&2
60 else
61 incremental=
62 fi
63 else
64 skiptil=$(cat $keyring.lastchangeset)
65 echo "Skipping forward past changeset $skiptil ..."
66 fi
67 fi
68 else
69 if [ -e "$keyring" ]; then
70 echo "$keyring already exists, and not in incremental mode, not modifying" >&2
71 exit 1
72 fi
73 fi
74 touch "$keyring"
75
76 for changeset in $(cut -d " " -f 3 "$changesetdir/index"); do
77 if [ -n "$skiptil" ]; then
78 if [ "$changeset" = "$skiptil" ]; then
79 skiptil=
80 fi
81 continue
82 fi
83 echo "Applying $changesetdir/$changeset ..."
84 if ! jetring-apply "$keyring" "$changesetdir/$changeset"; then
85 echo "Failed! Leaving keyring in $keyring.error" >&2
86 mv -f "$keyring" "$keyring.error"
87 exit 1
88 fi
89 done
90
91 if [ -n "$skiptil" ]; then
92 echo "Did not find last applied changeset, $skiptil, incremental update failed" >&2
93 exit 1
94 fi
95
96 echo "$changeset" > "$keyring.lastchangeset"
97 echo "All changesets applied ok."