about summary refs log tree commit diff
path: root/xgensum
blob: b9658dded5a616fd4faf9570321640a83a35feac (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
# xgensum [-f] [-c] [-i] [-H hostdir] TEMPLATE - update SHA256 sums in templates

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

case "$1" in
	-c) FLAG_c=$1; shift
esac

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

case "$1" in
	-H*) FLAG_h=$2; shift; shift
esac

: ${FLAG_h:=hostdir}

XBPS_DISTDIR=$(xdistdir) || exit 1

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

. "$template"

# Try to source the build-style as well. This is required for R-cran packages.
if [ -f "${XBPS_DISTDIR}/common/environment/build-style/${build_style}.sh"  ]; then
	. "${XBPS_DISTDIR}/common/environment/build-style/${build_style}.sh"
fi

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

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

"$XBPS_DISTDIR/xbps-src" -H $FLAG_h -I fetch $pkgname

sums=""
for f in $distfiles; do
	curfile="${f#*>}"
	curfile="${curfile##*/}"
	distfile="$srcdir/$curfile"
	if [ "$FLAG_c" = -c ];then
		sum="@"
		case ${distfile} in
		*tar.lzma|*.tar|*.txz|*.tar.xz|*.tbz|*.tar.gz)
			sum+=$(xbps-uhelper digest <(tar xf "$distfile" --to-stdout))
			;;
		*.gz)
			sum+=$(xbps-uhelper digest <(gunzip -c "$distfile"))
			;;
		*.tar.bz2|*.bz2)
			sum+=$(xbps-uhelper digest <(bunzip2 -c "$distfile"))
			;;
		*.zip)
			if command -v unzip &>/dev/null; then
				sum+=$(xbps-uhelper digest <(unzip -p "$distfile"))
				if [ $? -ne 0 ]; then
					echo "$pkgver: extracting $curfile to pipe."
				fi
			else
				echo "$pkgver: cannot find unzip bin for extraction."
			fi
			;;
		*.rpm)
			if command -v rpmextract &>/dev/null; then
				sum+=$(xbps-uhelper digest <(rpm2cpio "$distfile" | bsdtar xf - --to-stdout))
				if [ $? -ne 0 ]; then
					echo "$pkgver: extracting $curfile to pipe."
				fi
			else
				echo "$pkgver: cannot find rpmextract for extraction."
			fi
			;;
		*.7z)
			if command -v 7z &>/dev/null; then
				sum+=$(xbps-uhelper digest <(7z x -o "$distfile"))
				if [ $? -ne 0 ]; then
					echo "$pkgver: extracting $curfile to pipe."
				fi
			else
				echo "$pkgver: cannot find 7z bin for extraction."
			fi
			;;
		*.txt|*.patch|*.diff)
			sum+=$(xbps-uhelper digest "$distfile")
			;;
		*)
			sum=$(xbps-uhelper digest $distfile)

		esac
	else
		sum=$(xbps-uhelper digest $distfile)
	fi
	sums+="${sum%  *}\n "
done

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