summaryrefslogtreecommitdiff
path: root/archbuild
blob: 7e8c45698ec9c79fcbb6fe501e7395eb5e3208b3 (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
#!/bin/bash

base_packages='base base-devel sudo'

cmd="$(basename "${0%-build}")"
if [ "${cmd%-*}" == 'multilib' ]; then
	repo="${cmd}"
	arch='x86_64'
	base_packages+=' multilib-devel'
else
	repo=${cmd%-*}
	arch=${cmd##*-}
fi
chroots='/var/tmp/archbuild'
clean_first=false

usage() {
	echo "usage $(basename "$0")"
	echo '    -c         Recreate the chroot before building'
	echo '    -r <dir>   Create chroots in this directory'
	exit 1
}

while getopts 'cr:' arg; do
	case "${arg}" in
		c) clean_first=true ;;
		r) chroots="$OPTARG" ;;
		*) usage ;;
	esac
done

if [ "$EUID" != '0' ]; then
	echo 'This script must be run as root.'
	exit 1
fi

if ${clean_first} || [ ! -d "${chroots}/${repo}-${arch}" ]; then
	echo "Creating chroot for [${repo}] (${arch})..."
	rm -rf ${chroots}/${repo}-${arch}
	mkdir -p ${chroots}/${repo}-${arch}
	setarch ${arch} mkarchroot \
		-C /usr/share/devtools/pacman-${repo}.conf \
		-M /usr/share/devtools/makepkg-${arch}.conf \
		${chroots}/${repo}-${arch}/root \
		${base_packages}
else
	setarch ${arch} mkarchroot \
		-u \
		${chroots}/${repo}-${arch}/root
fi

echo "Building in chroot for [${repo}] (${arch})..."
setarch ${arch} makechrootpkg -c -r ${chroots}/${repo}-${arch}