diff options
Diffstat (limited to 'contrib/cpt-chbuild')
-rwxr-xr-x | contrib/cpt-chbuild | 59 |
1 files changed, 37 insertions, 22 deletions
diff --git a/contrib/cpt-chbuild b/contrib/cpt-chbuild index e53d903..7a71c33 100755 --- a/contrib/cpt-chbuild +++ b/contrib/cpt-chbuild @@ -3,6 +3,7 @@ ## SYNOPSIS: ## .Nm +## .Op Fl r ## .Op Ar pkg... ## DESCRIPTION: @@ -13,13 +14,19 @@ ## exist in the user's cache directory, it will download it from the Carbs Linux ## website. If any packages are given as arguments, ## .Nm -## will install those packages to this temporary chroot. +## will install those packages to this temporary chroot. If the +## .Fl r +## flag is given, +## .Nm +## will remove the rootfs tarball and directory to download it again. -case "$1" in - --help|-h) printf '\033[1;33m-> \033[m%s\n' "usage: ${0##*/} [pkg...]"; exit 0 -esac +parser_definition() { + setup REST help:usage -- "usage: ${0##*/} [-r] [pkg...]" + flag redownload -r hidden:1 + global_options silent +} -# shellcheck disable=1091 +# shellcheck source=../src/cpt-lib . cpt-lib die() { @@ -34,34 +41,46 @@ die() { case "$(uname -m)" in i*86) arch=i686; esac url="https://dl.carbslinux.org/releases/${arch:-$(uname -m)}/carbs-rootfs.tar.xz" -cd "$cac_dir" +cd "${cac_dir:?}" + +# Remove the existing tarball and the chroot directory, so that they can be +# downloaded again. +[ "$redownload" ] && as_root rm -rf carbs-rootfs.tar.xz \ + carbs-rootfs.tar.xz.sum \ + carbs-chroot [ -f carbs-rootfs.tar.xz ] || { log "Downloading chroot tarball" - curl -fLO "$url" + pkg_download "$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 + pkg_download "$url.sha256" carbs-rootfs.tar.xz.sum } -log "Verifying checksums" -sh256 carbs-rootfs.tar.xz | diff - carbs-rootfs.tar.xz.sum || - die "Checksum verification failed" - +# We don't want to create the rootfs as a non-priviliged user, because there may +# arise certain problems if the files inside the chroot don't belong to root. +[ "$uid" = 0 ] || { + as_root "$0" "$@" + exit $? +} [ -d carbs-chroot ] || { + log "Verifying checksums" + sh256 carbs-rootfs.tar.xz | diff - carbs-rootfs.tar.xz.sum || + die "Checksum verification failed" + log "Extracting chroot" mkdir -p carbs-chroot - ( cd carbs-chroot; tar xf ../carbs-rootfs.tar.xz ) + (cd carbs-chroot; xz -cd ../carbs-rootfs.tar.xz | pax -r) } -create_cache empty +mkdir -p "${tmp_dir:?}" log "Creating temporary chroot" -cp -a carbs-chroot "${chr_dir:=$tmp_dir/chroot}" +mkdir -p "${chr_dir:=$tmp_dir/chroot}" +rsync -a carbs-chroot/ "$chr_dir" [ "$1" ] && { log "Installing extra packages" @@ -71,9 +90,5 @@ cp -a carbs-chroot "${chr_dir:=$tmp_dir/chroot}" run_hook pre-chroot "" "$chr_dir" log "Entering chroot" -if [ "$(id -u)" -eq 0 ]; then - cpt-chroot "$chr_dir" - rm -rf "$chr_dir" -else - as_root sh -c "cpt-chroot $chr_dir; rm -rf $chr_dir" -fi +cpt-chroot "$chr_dir" +rm -rf "$chr_dir" |