summary refs log tree commit diff
path: root/xgensum
blob: 2b24bf12048e6301fa690814b96ff5022536f981 (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
45
46
47
48
49
50
#!/bin/bash
# xgensum [-f] [-i] TEMPLATE - update SHA256 sums in templates

case "$1" in
	-f) FLAG_f=$1; shift
esac

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

if [ -f "$1" ]; then
	template="$1"
elif [ -f "$1/template" ]; then
	template="$1/template"
else
	echo 'Usage: xgensum [-f] [-i] TEMPLATE' 1>&2
	exit 1
fi

. "$template"

XBPS_DISTDIR=$(xdistdir)
XBPS_SRCDISTDIR=$($XBPS_DISTDIR/xbps-src show-var XBPS_SRCDISTDIR | tail -1)
srcdir="$XBPS_SRCDISTDIR/$pkgname-$version"

if [ "$FLAG_f" = -f ]; then
	for f in $distfiles; do
		curfile=$(basename "${f#*>}")
		distfile="$srcdir/$curfile"
		rm -vf "$distfile"
	done
	$XBPS_DISTDIR/xbps-src -I clean $pkgname
fi

$XBPS_DISTDIR/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 $FLAG_i -e "/^checksum=/,/^[^ \t]/{
		/^[ \t]/d
		s/^checksum=.*/checksum=\"${sums%\n }\"/
		/^checksum=\"[^ ]*\"/s/\"//g
	}" "$template"