Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archbuild.in
blob: f60bc30c7288d43762b1a453b12f9849db8b5cd9 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
# License: Unspecified

m4_include(lib/common.sh)
m4_include(lib/archroot.sh)

base_packages=(base base-devel)
makechrootpkg_args=(-c -n -C)

cmd="${0##*/}"
if [[ "${cmd%%-*}" == 'multilib' ]]; then
	repo="${cmd%-build}"
	arch='x86_64'
	base_packages+=(multilib-devel)
else
	if [[ "${cmd%%-*}" == 'archlinuxewe' ]]; then
		base_packages+=(local-certificates)
	fi
	tag="${cmd%-build}"
	repo=${tag%-*}
	arch=${tag##*-}
fi
if [[ -f "@pkgdatadir@/setarch-aliases.d/${arch}" ]]; then
	read -r set_arch < "@pkgdatadir@/setarch-aliases.d/${arch}"
else
	set_arch="${arch}"
fi
chroots='/var/lib/archbuild'
clean_first=false

pacman_config="@pkgdatadir@/pacman-${repo}.conf"
if [[ -f @pkgdatadir@/pacman-${repo}-${arch}.conf ]]; then
    pacman_config="@pkgdatadir@/pacman-${repo}-${arch}.conf"
fi
makepkg_config="@pkgdatadir@/makepkg-${arch}.conf"
if [[ -f @pkgdatadir@/makepkg-${repo}-${arch}.conf ]]; then
    makepkg_config="@pkgdatadir@/makepkg-${repo}-${arch}.conf"
fi

usage() {
	echo "Usage: $cmd [options] -- [makechrootpkg args]"
	echo '    -h         This help'
	echo '    -c         Recreate the chroot before building'
	echo '    -r <dir>   Create chroots in this directory'
	echo ''
	echo "Default makechrootpkg args: ${makechrootpkg_args[*]}"
	echo ''
	exit 1
}

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

check_root SOURCE_DATE_EPOCH,SRCDEST,SRCPKGDEST,PKGDEST,LOGDEST,MAKEFLAGS,PACKAGER,GNUPGHOME

if [ "${arch}" = "x86_64" ]; then
	cache_dir=''
else
	mkdir -p '/var/cache/archbuild32'
	cache_dir='-c/var/cache/archbuild32'
	makechrootpkg_args+=('-d/var/cache/archbuild32:/var/cache/pacman/pkg')
fi

if [ "${arch}" = "x86_64" ]; then
	cache_dir=''
else
	mkdir -p '/var/cache/archbuild32'
	cache_dir='-c/var/cache/archbuild32'
	makechrootpkg_args+=('-d/var/cache/archbuild32:/var/cache/pacman/pkg')
fi

# Pass all arguments after -- right to makepkg
makechrootpkg_args+=("${@:$OPTIND}")

if ${clean_first} || [[ ! -d "${chroots}/${repo}-${arch}" ]]; then
	msg "Creating chroot for [%s] (%s)..." "${repo}" "${arch}"

	for copy in "${chroots}/${repo}-${arch}"/*; do
		[[ -d $copy ]] || continue
		msg2 "Deleting chroot copy '%s'..." "$(basename "${copy}")"

		lock 9 "$copy.lock" "Locking chroot copy '%s'" "$copy"

		subvolume_delete_recursive "${copy}"
		find "${copy}" \
			-mindepth 1 \
			-type d \
			-exec mountpoint -q {} \; \
			-prune \
			-exec umount -l {} \;
		rm -rf --one-file-system "${copy}"
	done
	lock_close 9

	rm -rf --one-file-system "${chroots}/${repo}-${arch}"
	(umask 0022; mkdir -p "${chroots}/${repo}-${arch}")
	setarch "${set_arch}" mkarchroot \
		-C "${pacman_config}" \
		-M "${makepkg_config}" \
		${cache_dir} \
		"${chroots}/${repo}-${arch}/root" \
		"${base_packages[@]}" || abort
else
	lock 9 "${chroots}/${repo}-${arch}/root.lock" "Locking clean chroot"
	arch-nspawn \
		-C "${pacman_config}" \
		-M "${makepkg_config}" \
		${cache_dir} \
		"${chroots}/${repo}-${arch}/root" \
		pacman -Syuu --noconfirm || abort
fi

# Always build official packages reproducibly
if [[ ! -v SOURCE_DATE_EPOCH ]]; then
	export SOURCE_DATE_EPOCH=$(date +%s)
fi

msg "Building in chroot for [%s] (%s)..." "${repo}" "${arch}"
exec makechrootpkg -r "${chroots}/${repo}-${arch}" "${makechrootpkg_args[@]}"