void-packages

Void Source Packages
git clone git://ezup.dev/void-packages.git
Log | Files | Refs | README | LICENSE

chroot.sh (12707B)


      1# vim: set ts=4 sw=4 et:
      2
      3install_base_chroot() {
      4    [ "$CHROOT_READY" ] && return
      5    if [ "$1" = "bootstrap" ]; then
      6        unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
      7    else
      8        XBPS_TARGET_PKG="$1"
      9    fi
     10    # binary bootstrap
     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"
     15    fi
     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
     18    if [ $? -ne 0 ]; then
     19        msg_error "xbps-src: failed to install base-chroot!\n"
     20    fi
     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
     24    fi
     25
     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"
     28    chroot_check
     29    chroot_handler clean
     30}
     31
     32reconfigure_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"
     38    for f in ${pkgs}; do
     39        if xbps-query -r $XBPS_MASTERDIR $f &>/dev/null; then
     40            xbps-reconfigure -r $XBPS_MASTERDIR -f $f
     41        fi
     42    done
     43    touch -f $statefile
     44}
     45
     46update_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"
     53    fi
     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
     58}
     59
     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?
     62chroot_init() {
     63    mkdir -p $XBPS_MASTERDIR/etc/xbps
     64
     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")
     69XBPS_MASTERDIR=/
     70XBPS_CFLAGS="$XBPS_CFLAGS"
     71XBPS_CXXFLAGS="$XBPS_CXXFLAGS"
     72XBPS_FFLAGS="$XBPS_FFLAGS"
     73XBPS_CPPFLAGS="$XBPS_CPPFLAGS"
     74XBPS_LDFLAGS="$XBPS_LDFLAGS"
     75XBPS_HOSTDIR=/host
     76# End of configuration file.
     77_EOF
     78
     79    # Create custom script to start the chroot bash shell.
     80    cat > $XBPS_MASTERDIR/bin/xbps-shell <<_EOF
     81#!/bin/sh
     82
     83XBPS_SRC_VERSION="$XBPS_SRC_VERSION"
     84
     85. /etc/xbps/xbps-src.conf
     86
     87PATH=/void-packages:/usr/bin
     88
     89exec 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
     93_EOF
     94
     95    chmod 755 $XBPS_MASTERDIR/bin/xbps-shell
     96    cp -f /etc/resolv.conf $XBPS_MASTERDIR/etc
     97    return 0
     98}
     99
    100chroot_prepare() {
    101    local f=
    102
    103    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init ]; then
    104        return 0
    105    elif [ ! -f $XBPS_MASTERDIR/bin/bash ]; then
    106        msg_error "Bootstrap not installed in $XBPS_MASTERDIR, can't continue.\n"
    107    fi
    108
    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
    111    # structure.
    112    if [ -f /usr/share/zoneinfo/UTC ]; then
    113        tzfile=/usr/share/zoneinfo/UTC
    114        mkdir -p $XBPS_MASTERDIR/usr/share/zoneinfo
    115        cp /usr/share/zoneinfo/UTC $XBPS_MASTERDIR/usr/share/zoneinfo/UTC
    116        ln -sf ../usr/share/zoneinfo/UTC $XBPS_MASTERDIR/etc/localtime
    117    else
    118        # Should never happen.
    119        msg_warn "No local timezone configuration file created.\n"
    120    fi
    121
    122    for f in dev sys tmp proc host boot; do
    123        [ ! -d $XBPS_MASTERDIR/$f ] && mkdir -p $XBPS_MASTERDIR/$f
    124    done
    125
    126    # Copy /etc/passwd and /etc/group from base-files.
    127    cp -f $XBPS_SRCPKGDIR/base-files/files/passwd $XBPS_MASTERDIR/etc
    128    echo "$(whoami):x:$(id -u):$(id -g):$(whoami) user:/tmp:/bin/xbps-shell" \
    129        >> $XBPS_MASTERDIR/etc/passwd
    130    cp -f $XBPS_SRCPKGDIR/base-files/files/group $XBPS_MASTERDIR/etc
    131    echo "$(whoami):x:$(id -g):" >> $XBPS_MASTERDIR/etc/group
    132
    133    # Copy /etc/hosts from base-files.
    134    cp -f $XBPS_SRCPKGDIR/base-files/files/hosts $XBPS_MASTERDIR/etc
    135
    136    # Prepare default locale: en_US.UTF-8.
    137    if [ -s ${XBPS_MASTERDIR}/etc/default/libc-locales ]; then
    138        printf '%s\n' \
    139            'C.UTF-8 UTF-8' \
    140            'en_US.UTF-8 UTF-8' \
    141            >> ${XBPS_MASTERDIR}/etc/default/libc-locales
    142    fi
    143
    144    touch -f $XBPS_MASTERDIR/.xbps_chroot_init
    145    [ -n "$1" ] && echo $1 >> $XBPS_MASTERDIR/.xbps_chroot_init
    146
    147    return 0
    148}
    149
    150chroot_handler() {
    151    local action="$1" pkg="$2" rv=0 arg= _envargs=
    152
    153    [ -z "$action" -a -z "$pkg" ] && return 1
    154
    155    if [ -n "$IN_CHROOT" -o -z "$CHROOT_READY" ]; then
    156        return 0
    157    fi
    158    if [ ! -d $XBPS_MASTERDIR/void-packages ]; then
    159        mkdir -p $XBPS_MASTERDIR/void-packages
    160    fi
    161
    162    case "$action" in
    163        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot|clean)
    164            chroot_prepare || return $?
    165            chroot_init || return $?
    166            ;;
    167    esac
    168
    169    if [ "$action" = "chroot" ]; then
    170        $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
    171            $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
    172        rv=$?
    173    else
    174        env -i -- PATH="/usr/bin:$PATH" SHELL=/bin/sh \
    175            HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
    176            ${HTTP_PROXY:+HTTP_PROXY="${HTTP_PROXY}"} \
    177            ${HTTPS_PROXY:+HTTPS_PROXY="${HTTPS_PROXY}"} \
    178            ${FTP_PROXY:+FTP_PROXY="${FTP_PROXY}"} \
    179            ${SOCKS_PROXY:+SOCKS_PROXY="${SOCKS_PROXY}"} \
    180            ${NO_PROXY:+NO_PROXY="${NO_PROXY}"} \
    181            ${HTTP_PROXY_AUTH:+HTTP_PROXY_AUTH="${HTTP_PROXY_AUTH}"} \
    182            ${FTP_RETRIES:+FTP_RETRIES="${FTP_RETRIES}"} \
    183            SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
    184            XBPS_GIT_REVS="$XBPS_GIT_REVS" \
    185            XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
    186            ${XBPS_ALT_REPOSITORY:+XBPS_ALT_REPOSITORY=$XBPS_ALT_REPOSITORY} \
    187            $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
    188            $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
    189            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
    190        rv=$?
    191    fi
    192
    193    return $rv
    194}
    195
    196chroot_sync_repodata() {
    197    local f= hostdir= confdir= crossconfdir=
    198
    199    # always start with an empty xbps.d
    200    confdir=$XBPS_MASTERDIR/etc/xbps.d
    201    crossconfdir=$XBPS_MASTERDIR/$XBPS_CROSS_BASE/etc/xbps.d
    202
    203    [ -d $confdir ] && rm -rf $confdir
    204    [ -d $crossconfdir ] && rm -rf $crossconfdir
    205
    206    if [ -d $XBPS_DISTDIR/etc/xbps.d/custom ]; then
    207        mkdir -p $confdir $crossconfdir
    208        cp -f $XBPS_DISTDIR/etc/xbps.d/custom/*.conf $confdir
    209        cp -f $XBPS_DISTDIR/etc/xbps.d/custom/*.conf $crossconfdir
    210    fi
    211    if [ "$CHROOT_READY" ]; then
    212        hostdir=/host
    213    else
    214        hostdir=$XBPS_HOSTDIR
    215    fi
    216
    217    # Update xbps alternative repository if set.
    218    mkdir -p $confdir
    219    if [ -n "$XBPS_ALT_REPOSITORY" ]; then
    220        ( \
    221            echo "repository=$hostdir/binpkgs/${XBPS_ALT_REPOSITORY}"; \
    222            echo "repository=$hostdir/binpkgs/${XBPS_ALT_REPOSITORY}/nonfree"; \
    223            echo "repository=$hostdir/binpkgs/${XBPS_ALT_REPOSITORY}/debug"; \
    224            ) > $confdir/00-repository-alt-local.conf
    225        if [ "$XBPS_MACHINE" = "x86_64" ]; then
    226            ( \
    227                echo "repository=$hostdir/binpkgs/${XBPS_ALT_REPOSITORY}/multilib"; \
    228                echo "repository=$hostdir/binpkgs/${XBPS_ALT_REPOSITORY}/multilib/nonfree"; \
    229            ) >> $confdir/00-repository-alt-local.conf
    230        fi
    231    else
    232        rm -f $confdir/00-repository-alt-local.conf
    233    fi
    234
    235    # Disable 00-repository-main.conf from share/xbps.d (part of xbps)
    236    ln -s /dev/null $confdir/00-repository-main.conf
    237
    238    # Generate xbps.d(5) configuration files for repositories
    239    sed -e "s,/host,$hostdir,g" ${XBPS_DISTDIR}/etc/xbps.d/repos-local.conf \
    240        > $confdir/10-repository-local.conf
    241
    242    # Install multilib conf for local repos if it exists for the architecture
    243    if [ -s "${XBPS_DISTDIR}/etc/xbps.d/repos-local-${XBPS_MACHINE}-multilib.conf" ]; then
    244        install -Dm644 ${XBPS_DISTDIR}/etc/xbps.d/repos-local-${XBPS_MACHINE}-multilib.conf \
    245            $confdir/12-repository-local-multilib.conf
    246    fi
    247
    248    if [ "$XBPS_SKIP_REMOTEREPOS" ]; then
    249        rm -f $confdir/*remote*
    250    else
    251        if [ -s "${XBPS_DISTDIR}/etc/xbps.d/repos-remote-${XBPS_MACHINE}.conf" ]; then
    252            # If per-architecture base remote repo config exists, use that
    253            install -Dm644 ${XBPS_DISTDIR}/etc/xbps.d/repos-remote-${XBPS_MACHINE}.conf \
    254                $confdir/20-repository-remote.conf
    255        else
    256            # Otherwise use generic base for musl or glibc
    257            local suffix=
    258            case "$XBPS_MACHINE" in
    259                *-musl) suffix="-musl";;
    260            esac
    261            install -Dm644 ${XBPS_DISTDIR}/etc/xbps.d/repos-remote${suffix}.conf \
    262                $confdir/20-repository-remote.conf
    263        fi
    264        # Install multilib conf for remote repos if it exists for the architecture
    265        if [ -s "${XBPS_DISTDIR}/etc/xbps.d/repos-remote-${XBPS_MACHINE}-multilib.conf" ]; then
    266            install -Dm644 ${XBPS_DISTDIR}/etc/xbps.d/repos-remote-${XBPS_MACHINE}-multilib.conf \
    267                $confdir/22-repository-remote-multilib.conf
    268        fi
    269    fi
    270
    271    echo "syslog=false" > $confdir/00-xbps-src.conf
    272
    273    # Copy host repos to the cross root.
    274    if [ -n "$XBPS_CROSS_BUILD" ]; then
    275        rm -rf $XBPS_MASTERDIR/$XBPS_CROSS_BASE/etc/xbps.d
    276        mkdir -p $XBPS_MASTERDIR/$XBPS_CROSS_BASE/etc/xbps.d
    277        # copy xbps.d files from host for local repos
    278        cp ${XBPS_MASTERDIR}/etc/xbps.d/*local*.conf \
    279            $XBPS_MASTERDIR/$XBPS_CROSS_BASE/etc/xbps.d
    280        if [ "$XBPS_SKIP_REMOTEREPOS" ]; then
    281            rm -f $crossconfdir/*remote*
    282        else
    283            # Same general logic as above, just into cross root, and no multilib
    284            if [ -s "${XBPS_DISTDIR}/etc/xbps.d/repos-remote-${XBPS_TARGET_MACHINE}.conf" ]; then
    285                install -Dm644 ${XBPS_DISTDIR}/etc/xbps.d/repos-remote-${XBPS_TARGET_MACHINE}.conf \
    286                    $crossconfdir/20-repository-remote.conf
    287            else
    288                local suffix=
    289                case "$XBPS_TARGET_MACHINE" in
    290                    *-musl) suffix="-musl"
    291                esac
    292                install -Dm644 ${XBPS_DISTDIR}/etc/xbps.d/repos-remote${suffix}.conf \
    293                    $crossconfdir/20-repository-remote.conf
    294            fi
    295        fi
    296
    297        echo "syslog=false" > $crossconfdir/00-xbps-src.conf
    298    fi
    299
    300
    301    # Copy xbps repository keys to the masterdir.
    302    mkdir -p $XBPS_MASTERDIR/var/db/xbps/keys
    303    cp -f $XBPS_COMMONDIR/repo-keys/*.plist $XBPS_MASTERDIR/var/db/xbps/keys
    304
    305    # Make sure to sync index for remote repositories.
    306    if [ -z "$XBPS_SKIP_REMOTEREPOS" ]; then
    307        msg_normal "xbps-src: updating repositories for host ($XBPS_MACHINE)...\n"
    308        $XBPS_INSTALL_CMD $XBPS_INSTALL_ARGS -S
    309    fi
    310
    311    if [ -n "$XBPS_CROSS_BUILD" ]; then
    312        # Copy host keys to the target rootdir.
    313        mkdir -p $XBPS_MASTERDIR/$XBPS_CROSS_BASE/var/db/xbps/keys
    314        cp $XBPS_MASTERDIR/var/db/xbps/keys/*.plist \
    315            $XBPS_MASTERDIR/$XBPS_CROSS_BASE/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 target ($XBPS_TARGET_MACHINE)...\n"
    319            env -- XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE \
    320                $XBPS_INSTALL_CMD $XBPS_INSTALL_ARGS -r $XBPS_MASTERDIR/$XBPS_CROSS_BASE -S
    321        fi
    322    fi
    323
    324    return 0
    325}