#!/bin/sh -e # Create/destroy temporary chroots case "$1" in --help|-h) printf '\033[1;33m-> \033[m%s\n' "usage: ${0##*/} [pkg...]"; exit 0 esac # shellcheck disable=1091 . cpt-lib die() { rm -f carbs-rootfs.tar.xz carbs-rootfs.tar.xz.sum log "$@" log "Re-run 'cpt-chbuild' to try again." exit 1 } case "$(uname -m)" in i*86) arch=i686; esac url="https://dl.carbslinux.org/releases/${arch:-$(uname -m)}/carbs-rootfs.tar.xz" pid=$$ cd "$cac_dir" [ -f carbs-rootfs.tar.xz ] || { log "Downloading chroot tarball" curl -fLO "$url" } [ -f carbs-rootfs.tar.xz.sum ] || { log "Downloading checksums" curl -fLo- "${url%/*}/sha256sums.txt" | grep ' carbs-rootfs.tar.xz$' > carbs-rootfs.tar.xz.sum } log "Verifying checksums" sh256 carbs-rootfs.tar.xz | diff - carbs-rootfs.tar.xz.sum || die "Checksum verification failed" [ -d carbs-chroot ] || { log "Extracting chroot" mkdir -p carbs-chroot ( cd carbs-chroot; tar xf ../carbs-rootfs.tar.xz ) } log "Creating temporary chroot" cp -a carbs-chroot "chroot-$pid" [ "$1" ] && { log "Installing extra packages" CPT_ROOT=$PWD/chroot-$pid cpt-install "$@" } run_hook pre-chroot "" "$PWD/chroot-$pid" log "Entering chroot" if [ "$(id -u)" -eq 0 ]; then cpt-chroot "chroot-$pid" rm -rf "chroot-$pid" else as_root sh -c "cpt-chroot chroot-$pid; rm -rf chroot-$pid" fi