File: jetring-accept

package info (click to toggle)
jetring 0.20
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 464 kB
  • ctags: 26
  • sloc: perl: 462; sh: 171; makefile: 25
file content (53 lines) | stat: -rwxr-xr-x 1,331 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh
# Accepts a changeset, adding it to a directory and an index file.
set -e

if [ -z "$1" ] || [ -z "$2" ]; then
	echo "Usage: jetring-accept changesetdir changeset" >&2
	exit 1
fi

# avoid gnupg touching ~/.gnupg
GNUPGHOME=$(mktemp -d -t jetring.XXXXXXXX)
export GNUPGHOME
trap cleanup exit
cleanup () {
	rm -rf "$GNUPGHOME"
}

changesetdir="$1"
changeset="$2"

if [ -n "$JETRING_SIGN" ] && [ -e "$changesetdir/index" ]; then
	JETRING_SIGN=$(readlink -f "$JETRING_SIGN")
	gpg --no-auto-check-trustdb --options /dev/null \
		--no-default-keyring --keyring "$JETRING_SIGN" \
		--verify "$changesetdir/index.gpg" "$changesetdir/index"
fi

mkdir -p "$changesetdir"
touch "$changesetdir/index"

basename=$(basename "$changeset")
sha1sum=$(sha1sum "$changeset" | cut -d " " -f 1)
checksum=sha256-$(sha256sum "$changeset" | cut -d " " -f 1)

if grep "^$checksum " "$changesetdir/index" || 
   grep "^$sha1sum " "$changesetdir/index"; then
	echo "This changeset is already included." >&2
	exit 1
fi

c=1
origbasename="$basename"
while [ -e "$changesetdir/$basename" ]; do
	c=$(expr "$c" + 1)
	basename="$origbasename.$c"
done

echo "$checksum  $basename" >> "$changesetdir/index"
mv "$changeset" "$changesetdir/$basename"

if [ -n "$JETRING_SIGN" ] || [ -e "$changesetdir/index.gpg" ] ; then
	jetring-signindex "$changesetdir"
fi