summaryrefslogtreecommitdiffstats
path: root/rebuildpkgs.in
blob: a4c896909a36cd7a2afce85bbef0c9b8b4429e40 (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
#!/bin/bash
# This script rebuilds a list of packages in order
# and reports anything that fails
# 
# Due to sudo usage, it is recommended to allow makechrootpkg
# to be run with NOPASSWD in your sudoers file
#
# FIXME
# Currently uses $(pwd)/rebuilds as the directory for rebuilding...
# TODO make this work for community too

m4_include(lib/common.sh)

if (( $# < 1 )); then
	echo "Usage: $(basename $0) <chrootdir> <packages to rebuild>"
	echo "  example: $(basename $0) ~/chroot readline bash foo bar baz"
	exit 1
fi

# Source makepkg.conf; fail if it is not found
if [[ -r '/etc/makepkg.conf' ]]; then
	source '/etc/makepkg.conf'
else
	die '/etc/makepkg.conf not found!'
fi

bump_pkgrel() {
	# Get the current pkgrel from SVN and update the working copy with it
	# This prevents us from incrementing out of control :)
	pbuild='.svn/text-base/PKGBUILD.svn-base'
	oldrel=$(grep 'pkgrel=' $pbuild | cut -d= -f2)

	#remove decimals
	rel=$(echo $oldrel | cut -d. -f1)

	newrel=$(($rel + 1))

	sed -i "s/pkgrel=$oldrel/pkgrel=$newrel/" PKGBUILD
}

pkg_from_pkgbuild() {
	# we want the sourcing to be done in a subshell so we don't pollute our current namespace
	export CARCH PKGEXT
	(source PKGBUILD; echo "$pkgname-$pkgver-$pkgrel-$CARCH$PKGEXT")
}

chrootdir="$1"; shift
pkgs="$@"

SVNPATH='svn+ssh://gerolde.archlinux.org/srv/svn-packages'

msg "Work will be done in $(pwd)/rebuilds"

REBUILD_ROOT="$(pwd)/rebuilds"
mkdir -p "$REBUILD_ROOT"
cd "$REBUILD_ROOT"

/usr/bin/svn co -N $SVNPATH

FAILED=""
for pkg in $pkgs; do
	cd "$REBUILD_ROOT/svn-packages"

	msg2 "Building '$pkg'"
	/usr/bin/svn update "$pkg"
	if [[ ! -d "$pkg/trunk" ]]; then
		FAILED="$FAILED $pkg"
		warning "$pkg does not exist in SVN"
		continue
	fi
	cd "$pkg/trunk/"

	bump_pkgrel

	if ! sudo makechrootpkg -u -d -r "$chrootdir" -- --noconfirm; then
		FAILED="$FAILED $pkg"
		error "$pkg Failed!"
	else
		pkgfile=$(pkg_from_pkgbuild)
		if [[ -e $pkgfile ]]; then
			msg2 "$pkg Complete"
		else
			FAILED="$FAILED $pkg"
			error "$pkg Failed, no package built!"
		fi
	fi
done

cd "$REBUILD_ROOT"
if [[ -n $FAILED ]]; then
	msg 'Packages failed:'
	for pkg in $FAILED; do
		msg2 "$pkg"
	done
fi

msg 'SVN pkgbumps in svn-packages/ - commit when ready'