blob: 502654ce40948f330581c6ab53893aaef0d22f29 (
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
|
#!/bin/bash
m4_include(lib/common.sh)
# FIXME: temporary added curl until pacman 4.0 moves to [core]
base_packages=(base base-devel sudo curl)
cmd="${0##*/}"
if [[ "${cmd%%-*}" == 'multilib' ]]; then
repo="${cmd%-build}"
arch='x86_64'
base_packages+=(multilib-devel)
else
tag="${cmd%-build}"
repo=${tag%-*}
arch=${tag##*-}
fi
chroots='/var/tmp/archbuild'
clean_first=false
usage() {
echo "usage $cmd"
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
die 'This script must be run as root.'
fi
if ${clean_first} || [[ ! -d "${chroots}/${repo}-${arch}" ]]; then
msg "Creating chroot for [${repo}] (${arch})..."
for copy in "${chroots}/${repo}-${arch}"/*; do
[[ -d $copy ]] || continue
msg2 "Deleting chroot copy '$(basename "${copy}")'..."
# Lock the copy
exec 9>"${copy}.lock"
flock 9
{ type -P btrfs && btrfs subvolume delete "${copy}"; } &>/dev/null
rm -rf "${copy}"
done
exec 9>&-
# FIXME: temporary workaround until pacman 4.0 moves to [core]
if pacman -V | grep -q 'v4.' && ( [[ "$repo" == 'extra' || "$repo" == 'multilib' ]] ); then
pacman_conf=$(mktemp)
cp "@pkgdatadir@/pacman-${repo}.conf" "${pacman_conf}"
sed -r 's/^#(SigLevel = Never)/\1/' -i "${pacman_conf}"
else
pacman_conf="@pkgdatadir@/pacman-${repo}.conf"
fi
rm -rf "${chroots}/${repo}-${arch}"
mkdir -p "${chroots}/${repo}-${arch}"
setarch "${arch}" mkarchroot \
-C "${pacman_conf}" \
-M "@pkgdatadir@/makepkg-${arch}.conf" \
"${chroots}/${repo}-${arch}/root" \
"${base_packages[@]}"
# FIXME: temporary workaround until pacman 4.0 moves to [core]
if pacman -V | grep -q 'v4.' && ( [[ "$repo" == 'extra' || "$repo" == 'multilib' ]] ); then
cp "@pkgdatadir@/pacman-${repo}.conf" "${chroots}/${repo}-${arch}/root/etc/pacman.conf"
fi
else
setarch ${arch} mkarchroot \
-u \
-C "@pkgdatadir@/pacman-${repo}.conf" \
-M "@pkgdatadir@/makepkg-${arch}.conf" \
"${chroots}/${repo}-${arch}/root"
fi
msg "Building in chroot for [${repo}] (${arch})..."
setarch "${arch}" makechrootpkg -c -n -r "${chroots}/${repo}-${arch}"
|