summary refs log tree commit diff
path: root/gensum
blob: 4eb89ae4dacbe974324dda38a81cfc1137119131 (plain) (blame)
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
#!/bin/bash
# gensum [-i] TEMPLATE - update SHA256 sums in templates

case "$1" in
	-i*) i=$1; shift
esac

if [ -f $1 ]; then
	. "$1"
elif [ -f $1/template ]; then
	exec "$0" $i "$1/template"
elif [ -f template ]; then
	exec "$0" $i template
else
	echo Usage: gensum TEMPLATE
fi

if [ -d ../../hostdir/sources ]; then
	XBPS_SRCDISTDIR=../../hostdir/sources
elif [ -d ../hostdir/sources ]; then
	XBPS_SRCDISTDIR=../hostdir/sources
elif [ -d hostdir/sources ]; then
	XBPS_SRCDISTDIR=hostdir/sources
else
	XBPS_SRCDISTDIR=~/xbps-packages/hostdir/sources/
fi

srcdir="$XBPS_SRCDISTDIR/$pkgname-$version"

$XBPS_SRCDISTDIR/../../xbps-src -I fetch $pkgname

sums=""
for f in $distfiles; do
	curfile=$(basename "${f#*>}")
	distfile="$srcdir/$curfile"
	sum=$(sha256sum $distfile)
	sums+="${sum%  *}\n "
done

sed $i -e "/^checksum=/,/^[^ \t]/{
		/^[ \t]/d
		s/^checksum=.*/checksum=\"${sums%\n }\"/
		/^checksum=\"[^ ]*\"/s/\"//g
	}" "$1"