summaryrefslogtreecommitdiff
path: root/pcr/ring/upd-helper
blob: c48bdf7c50424b23c42847060c1c9ac0a8bb9829 (plain)
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
#!/usr/bin/env bash
#!/usr/bin/env python3
# Copyright 2017 Luke Shumaker <lukeshu@parabola.nu>
#
# This is a little program to automate some tedious bits of
# maintaining the GNU Ring package.

set -euE
. "$(librelib messages)"
startdir="$(dirname -- "$(readlink -f -- "$0")")"

prune-pkgnames() {
	xargs "$startdir"/prune-pkgnames "$@"
}

diff-filter() {
	awk '
BEGIN{p=0}
/^diff/{p=0}
/^diff.*make-ring\.py/{p=1}
/^diff.*scripts\/install\.sh/{p=1}
/^diff.*daemon\/contrib\/.*\/rules\.mak/{p=1}
{if (p) print}
'
}

notable-diff() {
	if [[ $# != 2 ]]; then
		>&2 echo "Usage $0 notable-diff OLD-SRCDIR NEW-SRCDIR"
	fi

	diff_flags=(
		-ruN
		--no-dereference
		--exclude='*.bz2'
		--exclude='*.xz'
		--exclude='*.gz'
		--exclude='*.png'
	)

	diff "${diff_flags[@]}" "$1"/ring-project "$2"/ring-project | diff-filter
}

set-pkgver() {
	if [[ $# != 1 ]]; then
		>&2 echo "Usage $0 set-pkgver NEW-VALUE-FOR-_pkgver"
	fi

	rm -rf src

	# get the old sources, for diffing later
	makepkg -o
	. PKGBUILD
	oldpkgver=$_pkgver
	mv src src-$oldpkgver

	# update _pkgver
	sed -i "s/^_pkgver=.*/_pkgver=$1/" PKGBUILD
	# update *sums
	updpkgsums

	# update _SOURCE_DATE_EPOCH
	gitget bare https://gerrit-ring.savoirfairelinux.com/ring-project ring-project.git
	date=$(cd ring-project.git && git log -n1 --format=%ct "${1##*.}")
	sed -i "s/^_SOURCE_DATE_EPOCH=.*/_SOURCE_DATE_EPOCH=$date/" PKGBUILD

	# get the new sources
	makepkg -o

	# diff the old and new sources
	notable-diff src-$oldpkgver src > notable-changes-${oldpkgver}--$1.patch
	msg 'As the packager, you should be aware of changes in:'
	diffstat -C < notable-changes-${oldpkgver}--$1.patch
}

ignored-depends() {
	pacman -Sgq base-devel
	COLUMNS= LC_ALL=C pacman -Qi ffmpeg <&-|sed -n 's/^Depends On\s*://p'|xargs printf '%s\n'|sed -e 's/=.*//' -e 's/\.so$//'
}

diff-depends() {
	if [[ $# != 0 ]]; then
		>&2 echo "Usage $0 diff-depends"
	fi
	makepkg -o # for make-ring.py
	. PKGBUILD
	cd src/ring-project
	comm \
	    <(printf '%s\n' "${makedepends[@]}" "${_depends_daemon[@]}" "${_depends_lrc[@]}" "${_depends_client_gnome[@]}" | prune-pkgnames base base-devel | sort) \
	    <(python3 -c 'print("\n".join(__import__("make-ring").ARCH_LINUX_DEPENDENCIES))' | prune-pkgnames base base-devel | sort) \
	    | tr $'\t' , | column -s, -t -o ' | ' -N 'only PKGBUILD,only make-ring.py,both'
}

find-dups() {
	. PKGBUILD
	msg 'Duplicated build-time depends:'
	printf '%s\n' "${makedepends[@]}" | prune-pkgnames -d base-devel
	msg 'Duplicated run-time depends:'
	printf '%s\n' "${_depends_daemon[@]}" "${_depends_lrc[@]}" "${_depends_client_gnome[@]}" | prune-pkgnames -d base
}

{
	cmds=(set-pkgver notable-diff diff-depends find-dups)
	if ! in_array "${1:-}" "${cmds[@]}"; then
		>&2 print 'Commands are: %s' "${cmds[*]}"
		exit 1
	fi
	"$@"
}