1 # vim: set ts=4 sw=4 et:
3 install_base_chroot
() {
4 [ "$CHROOT_READY" ] && return
5 if [ "$1" = "bootstrap" ]; then
6 unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
11 msg_normal
"xbps-src: installing base-chroot...\n"
12 # XBPS_TARGET_PKG == arch
13 if [ "$XBPS_TARGET_PKG" ]; then
14 _bootstrap_arch
="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
16 (export XBPS_MACHINE
=$XBPS_TARGET_PKG XBPS_ARCH
=$XBPS_TARGET_PKG; chroot_sync_repodata
)
17 ${_bootstrap_arch} $XBPS_INSTALL_CMD ${XBPS_INSTALL_ARGS} -y base-chroot
19 msg_error
"xbps-src: failed to install base-chroot!\n"
21 # Reconfigure base-files to create dirs/symlinks.
22 if xbps-query
-r $XBPS_MASTERDIR base-files
&>/dev
/null
; then
23 XBPS_ARCH
=$XBPS_TARGET_PKG xbps-reconfigure
-r $XBPS_MASTERDIR -f base-files
&>/dev
/null
26 msg_normal
"xbps-src: installed base-chroot successfully!\n"
27 chroot_prepare
$XBPS_TARGET_PKG || msg_error
"xbps-src: failed to initialize chroot!\n"
32 reconfigure_base_chroot
() {
33 local statefile
="$XBPS_MASTERDIR/.xbps_chroot_configured"
34 local pkgs
="glibc-locales ca-certificates"
35 [ -z "$IN_CHROOT" -o -e $statefile ] && return 0
36 # Reconfigure ca-certificates.
37 msg_normal
"xbps-src: reconfiguring base-chroot...\n"
39 if xbps-query
-r $XBPS_MASTERDIR $f &>/dev
/null
; then
40 xbps-reconfigure
-r $XBPS_MASTERDIR -f $f
46 update_base_chroot
() {
47 local keep_all_force
=$1
48 [ -z "$CHROOT_READY" ] && return
49 msg_normal
"xbps-src: updating software in $XBPS_MASTERDIR masterdir...\n"
50 # no need to sync repodata, chroot_sync_repodata() does it for us.
51 if $
(${XBPS_INSTALL_CMD} ${XBPS_INSTALL_ARGS} -nu|
grep -q xbps
); then
52 ${XBPS_INSTALL_CMD} ${XBPS_INSTALL_ARGS} -yu xbps || msg_error
"xbps-src: failed to update xbps!\n"
54 ${XBPS_INSTALL_CMD} ${XBPS_INSTALL_ARGS} -yu || msg_error
"xbps-src: failed to update base-chroot!\n"
55 msg_normal
"xbps-src: cleaning up $XBPS_MASTERDIR masterdir...\n"
56 [ -z "$XBPS_KEEP_ALL" -a -z "$XBPS_SKIP_DEPS" ] && remove_pkg_autodeps
57 [ -z "$XBPS_KEEP_ALL" -a -z "$keep_all_force" ] && rm -rf $XBPS_MASTERDIR/builddir
$XBPS_MASTERDIR/destdir
60 # FIXME: $XBPS_FFLAGS is not set when chroot_init() is run
61 # It is set in common/build-profiles/bootstrap.sh but lost somewhere?
63 mkdir
-p $XBPS_MASTERDIR/etc
/xbps
65 : ${XBPS_CONFIG_FILE:=/dev/null}
66 cat > $XBPS_MASTERDIR/etc
/xbps
/xbps-src.conf
<<_EOF
67 # Generated configuration file by xbps-src, DO NOT EDIT!
68 $(grep -E '^XBPS_.*' "$XBPS_CONFIG_FILE")
70 XBPS_CFLAGS="$XBPS_CFLAGS"
71 XBPS_CXXFLAGS="$XBPS_CXXFLAGS"
72 XBPS_FFLAGS="$XBPS_FFLAGS"
73 XBPS_CPPFLAGS="$XBPS_CPPFLAGS"
74 XBPS_LDFLAGS="$XBPS_LDFLAGS"
76 # End of configuration file.
79 # Create custom script to start the chroot bash shell.
80 cat > $XBPS_MASTERDIR/bin
/xbps-shell
<<_EOF
83 XBPS_SRC_VERSION="$XBPS_SRC_VERSION"
85 . /etc/xbps/xbps-src.conf
87 PATH=/void-packages:/usr/bin
89 exec env -i -- SHELL=/bin/sh PATH="\$PATH" DISTCC_HOSTS="\$XBPS_DISTCC_HOSTS" DISTCC_DIR="/host/distcc" \
90 ${XBPS_ARCH+XBPS_ARCH=$XBPS_ARCH} ${XBPS_CHECK_PKGS+XBPS_CHECK_PKGS=$XBPS_CHECK_PKGS} \
91 CCACHE_DIR="/host/ccache" IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 TERM=linux HOME="/tmp" \
92 PS1="[\u@$XBPS_MASTERDIR \W]$ " /bin/bash +h "\$@"
95 chmod 755 $XBPS_MASTERDIR/bin
/xbps-shell
96 cp -f /etc
/resolv.conf
$XBPS_MASTERDIR/etc
103 if [ -f $XBPS_MASTERDIR/.xbps_chroot_init
]; then
105 elif [ ! -f $XBPS_MASTERDIR/bin
/bash
]; then
106 msg_error
"Bootstrap not installed in $XBPS_MASTERDIR, can't continue.\n"
109 # Some software expects /etc/localtime to be a symbolic link it can read to
110 # determine the name of the time zone, so set up the expected link
112 ln -sf ..
/usr
/share
/zoneinfo
/UTC
$XBPS_MASTERDIR/etc
/localtime
114 for f
in dev sys tmp proc
host boot
; do
115 [ ! -d $XBPS_MASTERDIR/$f ] && mkdir
-p $XBPS_MASTERDIR/$f
118 # Copy /etc/passwd and /etc/group from base-files.
119 cp -f $XBPS_SRCPKGDIR/base-files
/files
/passwd
$XBPS_MASTERDIR/etc
120 echo "$(whoami):x:$(id -u):$(id -g):$(whoami) user:/tmp:/bin/xbps-shell" \
121 >> $XBPS_MASTERDIR/etc
/passwd
122 cp -f $XBPS_SRCPKGDIR/base-files
/files
/group
$XBPS_MASTERDIR/etc
123 echo "$(whoami):x:$(id -g):" >> $XBPS_MASTERDIR/etc
/group
125 # Copy /etc/hosts from base-files.
126 cp -f $XBPS_SRCPKGDIR/base-files
/files
/hosts
$XBPS_MASTERDIR/etc
128 # Prepare default locale: en_US.UTF-8.
129 if [ -s ${XBPS_MASTERDIR}/etc
/default
/libc-locales
]; then
132 'en_US.UTF-8 UTF-8' \
133 >> ${XBPS_MASTERDIR}/etc
/default
/libc-locales
136 touch -f $XBPS_MASTERDIR/.xbps_chroot_init
137 [ -n "$1" ] && echo $1 >> $XBPS_MASTERDIR/.xbps_chroot_init
143 local action
="$1" pkg
="$2" rv
=0 arg
= _envargs
=
145 [ -z "$action" -a -z "$pkg" ] && return 1
147 if [ -n "$IN_CHROOT" -o -z "$CHROOT_READY" ]; then
150 if [ ! -d $XBPS_MASTERDIR/void-packages
]; then
151 mkdir
-p $XBPS_MASTERDIR/void-packages
155 fetch|extract|
patch|configure|build|check|
install|pkg|bootstrap-update|chroot|clean
)
156 chroot_prepare ||
return $?
157 chroot_init ||
return $?
161 if [ "$action" = "chroot" ]; then
162 $XBPS_COMMONDIR/chroot-style
/${XBPS_CHROOT_CMD:=uunshare}.sh \
163 $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin
/xbps-shell
166 env
-i -- PATH
="/usr/bin:$PATH" SHELL
=/bin
/sh \
167 HOME
=/tmp IN_CHROOT
=1 LC_COLLATE
=C LANG
=en_US.UTF-8 \
168 ${http_proxy:+http_proxy="${http_proxy}"} \
169 ${https_proxy:+https_proxy="${https_proxy}"} \
170 ${ftp_proxy:+ftp_proxy="${ftp_proxy}"} \
171 ${all_proxy:+all_proxy="${all_proxy}"} \
172 ${no_proxy:+no_proxy="${no_proxy}"} \
173 ${HTTP_PROXY:+HTTP_PROXY="${HTTP_PROXY}"} \
174 ${HTTPS_PROXY:+HTTPS_PROXY="${HTTPS_PROXY}"} \
175 ${FTP_PROXY:+FTP_PROXY="${FTP_PROXY}"} \
176 ${SOCKS_PROXY:+SOCKS_PROXY="${SOCKS_PROXY}"} \
177 ${NO_PROXY:+NO_PROXY="${NO_PROXY}"} \
178 ${HTTP_PROXY_AUTH:+HTTP_PROXY_AUTH="${HTTP_PROXY_AUTH}"} \
179 ${FTP_RETRIES:+FTP_RETRIES="${FTP_RETRIES}"} \
180 SOURCE_DATE_EPOCH
="$SOURCE_DATE_EPOCH" \
181 XBPS_GIT_REVS
="$XBPS_GIT_REVS" \
182 XBPS_ALLOW_CHROOT_BREAKOUT
="$XBPS_ALLOW_CHROOT_BREAKOUT" \
183 ${XBPS_ALT_REPOSITORY:+XBPS_ALT_REPOSITORY=$XBPS_ALT_REPOSITORY} \
184 $XBPS_COMMONDIR/chroot-style
/${XBPS_CHROOT_CMD:=uunshare}.sh \
185 $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
186 /void-packages
/xbps-src
$XBPS_OPTIONS $action $pkg
193 chroot_sync_repodata
() {
194 local f
= hostdir
= confdir
= crossconfdir
=
196 # always start with an empty xbps.d
197 confdir
=$XBPS_MASTERDIR/etc
/xbps.d
198 crossconfdir
=$XBPS_MASTERDIR/$XBPS_CROSS_BASE/etc
/xbps.d
200 [ -d $confdir ] && rm -rf $confdir
201 [ -d $crossconfdir ] && rm -rf $crossconfdir
203 if [ -d $XBPS_DISTDIR/etc
/xbps.d
/custom
]; then
204 mkdir
-p $confdir $crossconfdir
205 cp -f $XBPS_DISTDIR/etc
/xbps.d
/custom
/*.conf
$confdir
206 cp -f $XBPS_DISTDIR/etc
/xbps.d
/custom
/*.conf
$crossconfdir
208 if [ "$CHROOT_READY" ]; then
211 hostdir
=$XBPS_HOSTDIR
214 # Update xbps alternative repository if set.
216 if [ -n "$XBPS_ALT_REPOSITORY" ]; then
217 cat <<- ! > $confdir/00-repository-alt-local.conf
218 repository=$hostdir/binpkgs/${XBPS_ALT_REPOSITORY}/bootstrap
219 repository=$hostdir/binpkgs/${XBPS_ALT_REPOSITORY}
220 repository=$hostdir/binpkgs/${XBPS_ALT_REPOSITORY}/nonfree
221 repository=$hostdir/binpkgs/${XBPS_ALT_REPOSITORY}/debug
223 if [ "$XBPS_MACHINE" = "x86_64" ]; then
224 cat <<- ! >> $confdir/00-repository-alt-local.conf
225 repository=$hostdir/binpkgs/${XBPS_ALT_REPOSITORY}/multilib/bootstrap
226 repository=$hostdir/binpkgs/${XBPS_ALT_REPOSITORY}/multilib
227 repository=$hostdir/binpkgs/${XBPS_ALT_REPOSITORY}/multilib/nonfree
231 rm -f $confdir/00-repository-alt-local.conf
234 # Disable 00-repository-main.conf from share/xbps.d (part of xbps)
235 ln -s /dev/null $confdir/00-repository-main.conf
237 # Generate xbps.d(5) configuration files for repositories
238 sed -e "s,/host,$hostdir,g" ${XBPS_DISTDIR}/etc/xbps.d/repos-local.conf \
239 > $confdir/10-repository-local.conf
241 # Install multilib conf for local repos if it exists for the architecture
242 if [ -s "${XBPS_DISTDIR}/etc/xbps.d/repos-local-${XBPS_MACHINE}-multilib.conf" ]; then
243 install -Dm644 ${XBPS_DISTDIR}/etc/xbps.d/repos-local-${XBPS_MACHINE}-multilib.conf \
244 $confdir/12-repository-local-multilib.conf
247 # mirror_sed is a sed script: nop by default
249 if [ -n "$XBPS_MIRROR" ]; then
250 # when XBPS_MIRROR is set, mirror_sed rewrites remote repos
251 mirror_sed="s|^repository=http.*/current|repository=${XBPS_MIRROR}|"
254 if [ "$XBPS_SKIP_REMOTEREPOS" ]; then
255 rm -f $confdir/*remote*
257 if [ -s "${XBPS_DISTDIR}/etc/xbps.d/repos-remote-${XBPS_MACHINE}.conf" ]; then
258 # If per-architecture base remote repo config exists, use that
259 sed -e "$mirror_sed" ${XBPS_DISTDIR}/etc/xbps.d/repos-remote-${XBPS_MACHINE}.conf \
260 > $confdir/20-repository-remote.conf
262 # Otherwise use generic base for musl or glibc
264 case "$XBPS_MACHINE" in
265 *-musl) suffix="-musl";;
267 sed -e "$mirror_sed" ${XBPS_DISTDIR}/etc/xbps.d/repos-remote${suffix}.conf \
268 > $confdir/20-repository-remote.conf
270 # Install multilib conf for remote repos if it exists for the architecture
271 if [ -s "${XBPS_DISTDIR}/etc/xbps.d/repos-remote-${XBPS_MACHINE}-multilib.conf" ]; then
272 sed -e "$mirror_sed" ${XBPS_DISTDIR}/etc/xbps.d/repos-remote-${XBPS_MACHINE}-multilib.conf \
273 > $confdir/22-repository-remote-multilib.conf
277 echo "syslog=false" > $confdir/00-xbps-src.conf
279 # Copy host repos to the cross root.
280 if [ -n "$XBPS_CROSS_BUILD" ]; then
281 rm -rf $XBPS_MASTERDIR/$XBPS_CROSS_BASE/etc/xbps.d
282 mkdir -p $XBPS_MASTERDIR/$XBPS_CROSS_BASE/etc/xbps.d
283 # Disable 00-repository-main.conf from share/xbps.d (part of xbps)
284 ln -s /dev/null $XBPS_MASTERDIR/$XBPS_CROSS_BASE/etc/xbps.d/00-repository-main.conf
285 # copy xbps.d files from host for local repos
286 cp ${XBPS_MASTERDIR}/etc/xbps.d/*local*.conf \
287 $XBPS_MASTERDIR/$XBPS_CROSS_BASE/etc/xbps.d
288 if [ "$XBPS_SKIP_REMOTEREPOS" ]; then
289 rm -f $crossconfdir/*remote*
291 # Same general logic as above, just into cross root, and no multilib
292 if [ -s "${XBPS_DISTDIR}/etc/xbps.d/repos-remote-${XBPS_TARGET_MACHINE}.conf" ]; then
293 sed -e "$mirror_sed" ${XBPS_DISTDIR}/etc/xbps.d/repos-remote-${XBPS_TARGET_MACHINE}.conf \
294 > $crossconfdir/20-repository-remote.conf
297 case "$XBPS_TARGET_MACHINE" in
298 *-musl) suffix="-musl"
300 sed -e "$mirror_sed" ${XBPS_DISTDIR}/etc/xbps.d/repos-remote${suffix}.conf \
301 > $crossconfdir/20-repository-remote.conf
305 echo "syslog=false" > $crossconfdir/00-xbps-src.conf
309 # Copy xbps repository keys to the masterdir.
310 mkdir -p $XBPS_MASTERDIR/var/db/xbps/keys
311 cp -f $XBPS_COMMONDIR/repo-keys/*.plist $XBPS_MASTERDIR/var/db/xbps/keys
312 if [ -n "$(shopt -s nullglob; echo "$XBPS_DISTDIR"/etc/repo-keys/*.plist)" ]; then
313 cp -f "$XBPS_DISTDIR"/etc/repo-keys/*.plist "$XBPS_MASTERDIR"/var/db/xbps/keys
316 # Make sure to sync index for remote repositories.
317 if [ -z "$XBPS_SKIP_REMOTEREPOS" ]; then
318 msg_normal "xbps-src: updating repositories for host ($XBPS_MACHINE)...\n"
319 $XBPS_INSTALL_CMD $XBPS_INSTALL_ARGS -S
322 if [ -n "$XBPS_CROSS_BUILD" ]; then
323 # Copy host keys to the target rootdir.
324 mkdir -p $XBPS_MASTERDIR/$XBPS_CROSS_BASE/var/db/xbps/keys
325 cp $XBPS_MASTERDIR/var/db/xbps/keys/*.plist \
326 $XBPS_MASTERDIR/$XBPS_CROSS_BASE/var/db/xbps/keys
327 # Make sure to sync index for remote repositories.
328 if [ -z "$XBPS_SKIP_REMOTEREPOS" ]; then
329 msg_normal "xbps-src: updating repositories for target ($XBPS_TARGET_MACHINE)...\n"
330 env -- XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE \
331 $XBPS_INSTALL_CMD $XBPS_INSTALL_ARGS -r $XBPS_MASTERDIR/$XBPS_CROSS_BASE -S