Skip to content
archbuild.in 2.51 KiB
Newer Older
m4_include(lib/common.sh)

base_packages=(base-devel)
makechrootpkg_args=(-c -n)
cmd="${0##*/}"
if [[ "${cmd%%-*}" == 'multilib' ]]; then
	repo="${cmd%-build}"
Jan Steffens's avatar
Jan Steffens committed
	arch='x86_64'
	base_packages+=(multilib-devel)
	tag="${cmd%-build}"
	repo=${tag%-*}
	arch=${tag##*-}
chroots='/var/lib/archbuild'
	echo "Usage: $cmd [options] -- [makechrootpkg args]"
	echo '    -h         This help'
	echo '    -c         Recreate the root chroot before building'
	echo '    -U         Do not update chroots before building'
	echo '    -r <dir>   Create chroots in this directory'
Seblu's avatar
Seblu committed
	echo '    -R         Repackage (fastpass to makepkg -R)'
	echo '    -n         Do not build (used to create/update the root chroot)'
	echo ''
	echo "Default makechrootpkg args: ${makechrootpkg_args[*]}"
	echo ''
while getopts 'hcr:URn' arg; do
	case "${arg}" in
		c) clean_first=true ;;
		U) update=false
		   makechrootpkg_args=(-n) ;;
Seblu's avatar
Seblu committed
		R) update=false
		   clean_first=false
		   makechrootpkg_args=(-n -- -R -f);;
		n) build=false ;;
check_root "$0" "${orig_argv[@]}"

# Override default makechrootpkg arguments when specified
[[ -n ${@:$OPTIND} ]] && makechrootpkg_args=("${@:$OPTIND}")
if ${clean_first} || [[ ! -d "${chroots}/${repo}-${arch}" ]]; then
	msg "Creating root chroot for [${repo}] (${arch})..."
	for copy in "${chroots}/${repo}-${arch}"/*; do
		[[ -d $copy ]] || continue
		msg2 "Deleting chroot copy '$(basename "${copy}")'..."
		lock 9 "$copy.lock" "Locking chroot copy '$copy'"
		if [[ "$(stat -f -c %T "${copy}")" == btrfs ]]; then
			{ type -P btrfs && btrfs subvolume delete "${copy}"; } &>/dev/null
		fi
		rm -rf --one-file-system "${copy}"
	rm -rf --one-file-system "${chroots}/${repo}-${arch}"
	mkdir -p "${chroots}/${repo}-${arch}"
	setarch "${arch}" mkarchroot \
Pierre Schmitz's avatar
Pierre Schmitz committed
		-C "@pkgdatadir@/pacman-${repo}.conf" \
		-M "@pkgdatadir@/makepkg-${arch}.conf" \
		"${chroots}/${repo}-${arch}/root" \
		"${base_packages[@]}" || abort
elif $update; then
	msg "Updating chroot for [${repo}] (${arch})..."

	lock 9 "${chroots}/${repo}-${arch}/root.lock" "Locking clean chroot"
		-C "@pkgdatadir@/pacman-${repo}.conf" \
		-M "@pkgdatadir@/makepkg-${arch}.conf" \
		"${chroots}/${repo}-${arch}/root" \
                pacman -Syu --noconfirm || abort
if $build; then
	msg "Building in chroot for [${repo}] (${arch})..."
	exec makechrootpkg -r "${chroots}/${repo}-${arch}" "${makechrootpkg_args[@]}"
fi