forked from QubesOS/qubes-builder-rpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare-chroot-builder
executable file
·178 lines (151 loc) · 5.79 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/sh
# vim: set ts=4 sw=4 sts=4 et :
set -e
if [ "${VERBOSE:-0}" -ge 2 ] || [ "${DEBUG:-0}" -eq "1" ]; then
set -x
else
YUM_OPTS="$YUM_OPTS -q"
fi
PLUGIN_DIR=$(dirname "$0")
DIR=$1
DIST=$2
CHROOT_CACHE_FILE=
YUM=dnf
if [ "${DIST#fc}" != "${DIST}" ]; then
DISTRIBUTION="fedora"
DIST_VER="${DIST#fc}"
elif [ "${DIST#centos-stream}" != "${DIST}" ]; then
DISTRIBUTION="centos-stream"
DIST_VER="${DIST#centos-stream}"
elif [ "${DIST#centos}" != "${DIST}" ]; then
DISTRIBUTION="centos"
DIST_VER="${DIST#centos}"
if [ "$DIST_VER" = "7" ]; then
YUM=yum
fi
fi
YUM_OPTS="$YUM_OPTS --releasever=${DIST_VER}"
if [ -n "$3" ]; then
PKGLISTFILE="$3"
else
if [ -e "${PLUGIN_DIR}/build-pkgs-base-${DISTRIBUTION}-${DIST_VER}.list" ]; then
PKGLISTFILE="${PLUGIN_DIR}/build-pkgs-base-${DISTRIBUTION}-${DIST_VER}.list"
else
PKGLISTFILE="${PLUGIN_DIR}/build-pkgs-base-${DISTRIBUTION}.list"
fi
if [ "0$CACHE_CHROOT" -eq 1 ]; then
CHROOT_CACHE_FILE="${CACHEDIR}/chroot-${DIST}-base.tar"
fi
fi
prepare_chroot_proc () {
mount -t proc proc "$DIR/proc"
chroot "$DIR" ln -nsf /proc/self/fd /dev/fd
chroot "$DIR" ln -nsf /proc/self/fd/0 /dev/stdin
chroot "$DIR" ln -nsf /proc/self/fd/1 /dev/stdout
chroot "$DIR" ln -snf /proc/self/fd/2 /dev/stderr
}
if ! [ -d "$DIR/home/user" ] && [ -r "$CHROOT_CACHE_FILE" ]; then
mkdir -p "$DIR"
tar xf "$CHROOT_CACHE_FILE" "$DIR"
fi
mkdir -p "$DIR"
"${PLUGIN_DIR}/prepare-chroot-base" "$DIR" "$DIST"
mkdir -p "$DIR/etc/dnf/vars"
echo "$DIR" > "$DIR/etc/dnf/vars/sysroot"
echo "$BUILDER_REPO_DIR" > "$DIR/etc/dnf/vars/builder_repo_dir"
if ! [ -e "$DIR/home/user/.prepared_base" ]; then
if ! [ -r "$DIR/proc/cpuinfo" ]; then
prepare_chroot_proc
fi
rm -f "$DIR/etc/resolv.conf"
cp /etc/resolv.conf "$DIR/etc/"
# setup user and group
if [ -z "$USER_UID" ] && [ -n "$SUDO_UID" ]; then
USER_UID="$SUDO_UID"
elif [ -z "$USER_UID" ]; then
USER_UID=1000
fi
if [ -z "$USER_GID" ] && [ -n "$SUDO_GID" ]; then
USER_GID="$SUDO_GID"
elif [ -z "$USER_GID" ]; then
USER_GID=1000
fi
existing_gid=$(chroot "$DIR" id -g user 2>/dev/null || :)
if [ -z "$existing_gid" ]; then
chroot "$DIR" groupadd -g "$USER_GID" user
elif [ "$existing_gid" != "$USER_GID" ]; then
chroot "$DIR" groupmod -g "$USER_GID" user
fi
existing_uid=$(chroot "$DIR" id -u user 2>/dev/null || :)
if [ -z "$existing_uid" ]; then
chroot "$DIR" useradd -g user -u "$USER_UID" user
elif [ "$existing_uid" != "$USER_UID" ]; then
chroot "$DIR" usermod -u "$USER_UID" user
fi
chroot "$DIR" sh -c "chown -R user /home/user;su -c 'mkdir -p qubes-src' - user"
fi
"${PLUGIN_DIR}/update-local-repo.sh" "$DIST"
cp "${PLUGIN_DIR}/repos/builder-local.repo" "$DIR/etc/yum.repos.d/"
sed -i -e "s#ROOT#$PWD#" "$DIR"/etc/yum.repos.d/*-local.repo
if [ -n "$USE_QUBES_REPO_VERSION" ]; then
cp "${PLUGIN_DIR}/repos/qubes-repo-${PACKAGE_SET}-${DISTRIBUTION}.repo" "$DIR/etc/yum.repos.d/"
if [ "x$QUBES_MIRROR" != "x" ]; then
sed -i "s#baseurl.*yum.qubes-os.org#baseurl = $QUBES_MIRROR#" \
"$DIR"/etc/yum.repos.d/qubes-repo-*.repo
fi
sed -i -e "s#%DIST%#$DIST#" "$DIR"/etc/yum.repos.d/qubes-repo-*.repo
sed -i -e "s#%QUBESVER%#$USE_QUBES_REPO_VERSION#" "$DIR"/etc/yum.repos.d/qubes-repo-*.repo
if [ "${DISTRIBUTION}" = "fedora" ]; then
QUBES_SIGNING_KEY="RPM-GPG-KEY-qubes-$USE_QUBES_REPO_VERSION-primary"
fi
if [ "${DISTRIBUTION}" = "centos-stream" ] || [ "${DISTRIBUTION}" = "centos" ]; then
QUBES_SIGNING_KEY="RPM-GPG-KEY-qubes-$USE_QUBES_REPO_VERSION-centos"
fi
if [ -r "${PLUGIN_DIR}/keys/$QUBES_SIGNING_KEY" ]; then
cp "${PLUGIN_DIR}/keys/$QUBES_SIGNING_KEY" "$DIR/etc/pki/rpm-gpg/"
chroot "$DIR" rpm --import "/etc/pki/rpm-gpg/$QUBES_SIGNING_KEY" || true
fi
if [ "0$USE_QUBES_REPO_TESTING" -gt 0 ]; then
if [ "$YUM" = "dnf" ]; then
chroot "$DIR" dnf config-manager --set-enabled 'qubes-builder-*-current-testing'
else
chroot "$DIR" yum-config-manager --enable 'qubes-builder-*-current-testing'
fi
fi
fi
if ! [ -r "$DIR/proc/cpuinfo" ]; then
prepare_chroot_proc
fi
# remove systemd-resolved symlink
rm -f "$DIR/etc/resolv.conf"
cp /etc/resolv.conf "$DIR/etc/"
# some packages assumes existence of this file
touch "$DIR"/etc/fstab
chmod 644 "$DIR"/etc/fstab
printf "%s" "-> Installing build base packages..."
# Disable Fedora modular repos because
# it can make dnf builddep to fail
# resolving dependencies
if [ "$DISTRIBUTION" = "fedora" ] && [ "${DIST_VER}" -ge 28 ] && [ "${DIST_VER}" -le 32 ]; then
chroot "$DIR" dnf config-manager --disable '*modular' || :
fi
if [ "$DISTRIBUTION" = "centos-stream" ]; then
if [ "${DIST_VER}" -eq 8 ]; then
chroot "$DIR" dnf --disablerepo='qubes*' --releasever="$DIST_VER" copr enable -y fepitre/epel-8-qubes
chroot "$DIR" dnf config-manager --disable --releasever="$DIST_VER" '*modular'
fi
fi
if [ "$DISTRIBUTION" = "centos" ]; then
if [ "${DIST_VER}" -eq 8 ]; then
chroot "$DIR" dnf --disablerepo='qubes*' --releasever="$DIST_VER" copr enable -y fepitre/epel-8-qubes
chroot "$DIR" dnf config-manager --disable --releasever="$DIST_VER" '*modular'
# Add Appstream and @fepitre python38 repositories
chroot "$DIR" dnf --disablerepo='qubes*' --releasever="$DIST_VER" module enable -y python38-devel:3.8
chroot "$DIR" dnf --disablerepo='qubes*' --releasever="$DIST_VER" copr enable -y fepitre/epel-8-python38
fi
fi
# shellcheck disable=SC2086,SC2046
$YUM --installroot="$DIR" install -y $YUM_OPTS $(cat ${PKGLISTFILE})
if [ -n "$CHROOT_CACHE_FILE" ]; then
tar cf "$CHROOT_CACHE_FILE" --one-file-system "$DIR"
fi