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

source $(dirname $0)/config.bash

cd "$PKGBUILD_DIR"

##
# Get commit sha from PKGVER of PKGBUILD
#
# Arguments:
#    $1    Whether the source is a PKGBUILD or string
#    $2    Path to the directory containing the PKGBUILD
#          to get the sha from
get_pkgver_sha() {
	if [[ "$1" -eq "pkgbuild" ]]; then
		source "$1"/PKGBUILD
	elif [[ "$1" -eq "string" ]]; then
		pkgver="$2"
	else
		printf "%s\n" "get_pkgver_sha failed" 1>&2
	fi

	printf "%s" "$(sed -r 's/.*\.r[0-9]*\.g?//' <<<$pkgver)"
}

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

	local needs_rebuild=()
	for package in "${packages[@]}"; do
		new_head=$(get_pkgver_sha "pkgbuild" "$package")

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

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

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

	$(dirname $0)/db-build
}

main "$@"