forked from QubesOS/qubes-builder-archlinux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare-chroot-builder
executable file
·78 lines (62 loc) · 2.55 KB
/
prepare-chroot-builder
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
#!/bin/sh
# vim: set ts=4 sw=4 sts=4 et :
### prepare-chroot-builder : Create the build chroot instance of Archlinux
### (in which to build Qubes packages)
echo "--> Archlinux prepare-chroot-builder"
PLUGIN_DIR="$(dirname $0)"
INSTALLDIR="$1"
DISTRO="$2"
SCRIPTSDIR=${ARCHLINUX_PLUGIN_DIR}scripts
export INSTALLDIR SCRIPTSDIR
PACMAN_CACHE_DIR="${CACHEDIR}/pacman_cache"
export PACMAN_CACHE_DIR
set -e
[ "$VERBOSE" -ge 1 -o "$DEBUG" -gt 0 ] && echo " --> INSTALLDIR: '$INSTALLDIR'"
[ "$VERBOSE" -ge 2 -o "$DEBUG" -gt 0 ] && set -x
# /home/user will exist if we've completed the build previously
if ! [ -d "${INSTALLDIR}/home/user" ]; then
# It's non-existance means this is likely the initial run, so build it
mkdir -p "$INSTALLDIR"
echo " --> Installing archlinux build root:"
"${PLUGIN_DIR}/prepare-chroot-base" "$INSTALLDIR" "$DISTRO"
echo " --> Configure system accounts..."
[ -n "$SUDO_UID" ] && USER_OPTS="-u ${SUDO_UID}"
[ -n "$USER_UID" ] && USER_OPTS="-u ${USER_UID}"
if [ -n "$USER_GID" ]; then
chroot "$INSTALLDIR" /bin/groupadd -g "$USER_GID" user
elif [ -n "$SUDO_GID" ]; then
chroot "$INSTALLDIR" /bin/groupadd -g "$SUDO_GID" user
else
chroot "$INSTALLDIR" /bin/groupadd user
fi
chroot "$INSTALLDIR" /bin/sh -c \
"useradd -g user -G wheel $USER_OPTS -m user; su -c 'mkdir qubes-src' - user"
echo " --> Synchronize resolv.conf..."
cp /etc/resolv.conf "${INSTALLDIR}/etc/resolv.conf"
# Checking for free disk free space doesn't work in chroots
echo " --> Comment out CheckSpace in pacman.conf..."
sed 's/^ *CheckSpace/#CheckSpace/g' -i "${INSTALLDIR}/etc/pacman.conf"
echo " --> Installing required makepkg dependencies..."
pkgs="base-devel binutils fakeroot sudo"
"${SCRIPTSDIR}/arch-chroot-lite" "$INSTALLDIR" /bin/sh -c \
"http_proxy='${REPO_PROXY}' pacman -Sy --needed --noconfirm --asdeps $pkgs"
# makepkg internally calls sudo without '-E', so we need to add an
# env_keep to honor proxy settings
echo " --> Configure sudo..."
cat > "${INSTALLDIR}/etc/sudoers.d/qubes-build-user" <<EOF
Defaults env_keep += "http_proxy https_proxy ftp_proxy"
%wheel ALL=(ALL) NOPASSWD: ALL
EOF
# Note: Enable x86 repos
tee -a "${INSTALLDIR}/etc/pacman.conf" <<EOF
[multilib]
SigLevel = PackageRequired
Include = /etc/pacman.d/mirrorlist
EOF
# Register custom repository (it will be created later)
tee -a "${INSTALLDIR}/etc/pacman.conf" <<EOF
[qubes]
SigLevel = Optional TrustAll
Server = file:///tmp/qubes-packages-mirror-repo/pkgs
EOF
fi