aboutsummaryrefslogtreecommitdiff
path: root/contrib/cpt-chbuild
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2020-07-24 09:45:05 +0000
committermerakor <cem@ckyln.com>2020-07-24 09:45:05 +0000
commita5742ec0d46f60fcbeec141744a2e35a9e5dd6d5 (patch)
tree653077a372cea7a5842db627546d2fab72c5f7e2 /contrib/cpt-chbuild
parent453a27cc1b956246c9639555268631abf0687e40 (diff)
downloadcpt-a5742ec0d46f60fcbeec141744a2e35a9e5dd6d5.tar.gz
contrib: rename scripts
FossilOrigin-Name: d35a756a5d603ac894873aeb0a30826cb4b3fe9e257ecf21298225e07f517ddd
Diffstat (limited to 'contrib/cpt-chbuild')
-rwxr-xr-xcontrib/cpt-chbuild73
1 files changed, 73 insertions, 0 deletions
diff --git a/contrib/cpt-chbuild b/contrib/cpt-chbuild
new file mode 100755
index 0000000..3ee7c42
--- /dev/null
+++ b/contrib/cpt-chbuild
@@ -0,0 +1,73 @@
+#!/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
+
+log() { printf '\033[31;1m->\033[m %s.\n' "$@" ;}
+
+die() {
+ rm -f carbs-rootfs.tar.xz carbs-rootfs.tar.xz.sum
+
+ log "$@"
+ log "Re-run 'kiss-chbuild' to try again."
+
+ exit 1
+}
+
+sh256() {
+ # There's no standard utility to generate sha256 checksums.
+ # This is a simple wrapper around sha256sum, sha256, shasum
+ # and openssl which will use whatever is available.
+ #
+ # All utilities must match 'sha256sum' output.
+ #
+ # Example: '<checksum> <file>'
+ [ -e "$1" ] || return 0
+
+ hash=$(sha256sum "$1" ||
+ sha256 -r "$1" ||
+ openssl dgst -sha256 -r "$1" ||
+ shasum -a 256 "$1")
+
+ printf '%s %s\n' "${hash%% *}" "$1"
+} 2>/dev/null
+
+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:=$KISS_ROOT${XDG_CACHE_HOME:-$HOME/.cache}/kiss}"
+
+[ -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"
+ KISS_ROOT=$PWD/chroot-$pid kiss i "$@"
+}
+
+log "Entering chroot"
+su -c "kiss-chroot chroot-$pid; rm -rf chroot-$pid"