forked from QubesOS/qubes-builder-archlinux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare-chroot-base
executable file
·69 lines (55 loc) · 2.41 KB
/
prepare-chroot-base
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
#!/bin/bash
# vim: set ts=4 sw=4 sts=4 et :
### prepare-chroot-base : Create a (any) chroot instance of Archlinux
### May be called from ./template_archlinux/01_install_core.sh or ./prepare-chroot-archlinux
echo "--> Archlinux prepare-chroot-base"
set -e
if [ "$VERBOSE" -ge 2 ] || [ "$DEBUG" -gt 0 ]; then
set -x
fi
INSTALL_DIR="$1"
BOOTSTRAP_DIR="${CACHE_DIR}/bootstrap"
DEFAULT_ARCHLINUX_MIRROR="\
https://mirror.rackspace.com/archlinux\
,https://arch.mirror.constant.com\
,https://mirror.f4st.host/archlinux\
,https://mirrors.edge.kernel.org/archlinux\
"
ARCHLINUX_MIRROR="${ARCHLINUX_MIRROR:-$DEFAULT_ARCHLINUX_MIRROR}"
IFS="," read -r -a ARCHLINUX_MIRROR <<< "$ARCHLINUX_MIRROR"
PACMAN_CACHE_DIR="${CACHE_DIR}/pacman_cache"
export PACMAN_CACHE_DIR
exit_prepare() {
local exit_code=$?
echo " --> Unbinding INSTALL_DIR..."
umount "${BOOTSTRAP_DIR}/mnt" || true
exit $exit_code
}
trap 'exit_prepare' 0 1 2 3 6 15
if ! { [ -f "${BOOTSTRAP_DIR}/.extracted" ] && [ -d "${CACHE_DIR}/pacman_cache" ] ;}; then
# XXX: Potential infinite loop in certain error conditions?
echo " --> Bootstrap chroot environment may not exist, calling 00_prepare.sh..."
"${TEMPLATE_CONTENT_DIR}/00_prepare.sh"
fi
# XXX: Also run if .extracted is newer than .prepared_base ??
if [ -f "${INSTALL_DIR}/.prepared_base" ]; then
echo " --> NB: INSTALL_DIR '${INSTALL_DIR}' already appears to have an environment; will leave as-is!"
exit 0
fi
echo " --> Binding INSTALL_DIR '${INSTALL_DIR}' to bootstrap environment..."
mount --bind "$INSTALL_DIR" "${BOOTSTRAP_DIR}/mnt"
echo -e " --> Setting pacman mirrorlist as:\n$(echo "${ARCHLINUX_MIRROR[@]}" | tr ' ' '\n')\n"
for MIRROR_ENTRY in "${ARCHLINUX_MIRROR[@]}"; do
echo "Server = $MIRROR_ENTRY/\$repo/os/\$arch"
done > "${BOOTSTRAP_DIR}/etc/pacman.d/mirrorlist"
cp /etc/resolv.conf "${BOOTSTRAP_DIR}/etc/"
echo " --> Initializing pacman keychain..."
"${TEMPLATE_CONTENT_DIR}/arch-chroot-lite" "$BOOTSTRAP_DIR" /bin/sh -c \
"pacman-key --init && pacman-key --populate"
echo " --> Installing core pacman packages..."
export PACMAN_CACHE_MOUNT_DIR="${BOOTSTRAP_DIR}/mnt/var/cache/pacman"
# shellcheck disable=SC2016
"${TEMPLATE_CONTENT_DIR}/arch-chroot-lite" "$BOOTSTRAP_DIR" /bin/sh -c \
'for i in 1 2 3 4 5; do ALL_PROXY=$1 http_proxy=$1 https_proxy=$1 pacstrap /mnt base && exit 0; done' sh "$REPO_PROXY"
unset PACMAN_CACHE_MOUNT_DIR
touch "${INSTALL_DIR}/.prepared_base"