aboutsummaryrefslogtreecommitdiffstats
path: root/build-updated-packages.bash
blob: 48edafbc28145e5a730d3635b08c50f061c69a98 (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
#!/usr/bin/env bash

source "$HOME"/.makepkg.conf
source $(dirname $0)/package-list.bash

cd "$HOME"/packaging/pkgbuilds

##
# Get commit of the laste built package from pkgver of PKGBUILD
#
# Arguments:
#    $1    Path to the directory of the PKGBUILD to get te old commit from.
get_old_commit() {
	(source "$1"/PKGBUILD
	printf "%s" "$(sed -r 's/.*\.r[0-9]*\.g?//' <<<$pkgver)")
}

##
# Get newest commit of VCS repo.
#
# Arguments:
#    $1    Path to the directory of the VCS repo.
#    $2    Name of the ref to get the newest commit of
get_new_commit() {
	if [[ -d "$1" ]]; then
		(cd "$1"
		if [[ -d .hg ]]; then
			hg update &>/dev/null
			printf "%s" "$(hg log -r "." --template "{node|short}")"
		elif [[ -n "$(git config --get core.bare)" ]]; then
			if [[ -n "$2" ]]; then
				local ref="$2"
			else
				local ref=HEAD
			fi
			printf "%s" "$(git rev-parse --short $ref)"
		fi)
	else
		printf "%s\n" "Repository to get commit from not found" 1>&2
	fi
}

build_repository() {
	REPOSE_BINARY="$HOME"/packaging/vodik-repose/repose
	DATABASE=kyriasis
	ROOT="$HOME"/packaging/repo
	POOL="$HOME"/packaging/built_packages
	"$REPOSE_BINARY" "$DATABASE" --root "$ROOT" --pool "$POOL" -v
}

main() {
	for package in "${!packages[@]}"; do
		(cd "$package"
		makepkg --nobuild &>/dev/null) &
	done
	wait

	local needs_rebuild=()
	for package in "${!packages[@]}"; do
		old_commit=$(get_old_commit $package)
		new_head=$(get_new_commit "$SRCDEST"/"${packages[$package]}" "${branches[$package]}")

		if [[ "$old_commit" != "$new_head" ]]; then
			needs_rebuild+=("$package")
		fi
	done

	if [[ ${#needs_rebuild[@]} -eq 0 ]]; then
		printf "%s\n" "No VCS packages found that needs rebuilding."
	else
		print "Packages that needs rebuilding:"
		printf "%s\n" "${needs_rebuild[@]}"

		for package in "${needs_rebuild[@]}"; do
			(cd "$package"
			makepkg -src --noconfirm 2>/dev/null) &
		done
	fi
	wait

	build_repository
}

main "$@"