diff options
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/cpt-cat | 32 | ||||
-rwxr-xr-x | contrib/cpt-chbuild | 53 | ||||
-rwxr-xr-x | contrib/cpt-export | 46 | ||||
-rwxr-xr-x | contrib/cpt-fork | 4 | ||||
-rwxr-xr-x | contrib/cpt-manifest-tree | 2 | ||||
-rwxr-xr-x | contrib/cpt-owns | 2 | ||||
-rwxr-xr-x | contrib/cpt-reset | 24 | ||||
-rwxr-xr-x | contrib/cpt-size | 35 |
8 files changed, 120 insertions, 78 deletions
diff --git a/contrib/cpt-cat b/contrib/cpt-cat index bfc9d66..45e0dd9 100755 --- a/contrib/cpt-cat +++ b/contrib/cpt-cat @@ -28,23 +28,29 @@ ## .Em version ## files. -case "$1" in - --help|-h) - printf 'usage: %s [pkg] [file...]\n' "${0##*/}" - exit 0 - ;; - '') - [ "$#" -gt 1 ] && shift - set -- "${PWD##*/}" "$@" -esac +parser_definition() { + setup REST help:usage -- "usage: ${0##*/} [pkg] [file...]" + global_options silent +} + +# shellcheck disable=1091 +. cpt-lib + +[ "$1" ] || { + # Usage such as `cpt-cat '' build` is also valid. + [ "$#" -gt 1 ] && shift + set -- "${PWD##*/}" "$@" +} pkg=$1; shift -cpt-list "$pkg" >/dev/null +pkg_list "$pkg" >/dev/null [ "$1" ] || set -- build depends sources version +# $sys_db and color variables are defined by cpt-lib +# shellcheck disable=2154 for file; do - [ -f "$CPT_ROOT/var/db/cpt/installed/$pkg/$file" ] || continue - printf '\033[1m%s:\033[m\n' "$file" >&2 - cat "$CPT_ROOT/var/db/cpt/installed/$pkg/$file" + [ -f "$sys_db/$pkg/$file" ] || continue + printf '%b%s:%b\n' "$colbold" "$file" "$colre" >&2 + cat "$sys_db/$pkg/$file" done diff --git a/contrib/cpt-chbuild b/contrib/cpt-chbuild index a58d2ee..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() { @@ -36,23 +43,34 @@ url="https://dl.carbslinux.org/releases/${arch:-$(uname -m)}/carbs-rootfs.tar.xz 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; xz -cd ../carbs-rootfs.tar.xz | pax -r) @@ -61,7 +79,8 @@ sh256 carbs-rootfs.tar.xz | diff - carbs-rootfs.tar.xz.sum || 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" diff --git a/contrib/cpt-export b/contrib/cpt-export index d90fb6f..478ae27 100755 --- a/contrib/cpt-export +++ b/contrib/cpt-export @@ -12,41 +12,29 @@ ## .Nm ## will use the name of the current directory as the package. -case "$1" in - --help|-h) - printf 'usage: %s [pkg]\n' "${0##*/}" - exit 0 - ;; - '') set -- "${PWD##*/}" -esac - -cpt-list "$1" >/dev/null -db=$CPT_ROOT/var/db/cpt/installed - -# Grab the package's version.. -read -r ver rel 2>/dev/null < "$db/$1/version" - ### Environment variables: ### The compression method can be changed while creating a tarball, using the ### .Ev CPT_COMPRESS ### environment variable. -# Fallback to gzip if there is a typo -case "$CPT_COMPRESS" in bz2|gz|xz|zst|lz) ;; *) CPT_COMPRESS=gz; esac -# Reset the argument list. +parser_definition() { + setup REST help:usage -- "usage: ${0##*/} [pkg]" + global_options silent +} + +# shellcheck disable=1091 +. cpt-lib + +[ "$1" ] || set -- "${PWD##*/}" + +(pkg_list "$1" >/dev/null) + +# Grab the package's version.. +read -r ver rel 2>/dev/null < "$sys_db/$1/version" + tarball="$PWD/$1#$ver-$rel.tar.$CPT_COMPRESS" # Turn the list of files back into a package. cd "$CPT_ROOT/" -sed 's/^/./' "$db/$1/manifest" | -pax -wd | - -case "$CPT_COMPRESS" in - bz2) bzip2 -z ;; - gz) gzip -6 ;; - xz) xz -zT 0 ;; - zst) zstd -3 ;; - lz) lzip -6 ;; -esac > "$tarball" - -printf 'tarball created in %s\n' "$tarball" +sed 's/^/./' "$sys_db/$1/manifest" | pax -wd | compress > "$tarball" +out "tarball created in $tarball" diff --git a/contrib/cpt-fork b/contrib/cpt-fork index 21e1618..733c942 100755 --- a/contrib/cpt-fork +++ b/contrib/cpt-fork @@ -31,12 +31,12 @@ for pkg; do case "$pkg" in */*) [ -d "$pkg" ] || die "$pkg is not a directory" - cp -r "$pkg" . + cp -Hr "$pkg" . pkg=${pkg##*/} ;; *) cpt-search "$pkg" >/dev/null - cp -r "$(cpt-search --single "$pkg")" . + cp -Hr "$(cpt-search --single "$pkg")" . esac # Sometimes forked packages are from the database and not from a repository. diff --git a/contrib/cpt-manifest-tree b/contrib/cpt-manifest-tree index 599c0bd..bc38bc2 100755 --- a/contrib/cpt-manifest-tree +++ b/contrib/cpt-manifest-tree @@ -21,4 +21,4 @@ case "$1" in esac cpt-list "$1" >/dev/null printf '%s\n' "[$1]:" -tree -C --fromfile "$CPT_ROOT/var/db/cpt/installed/$1/manifest" | sed 1,2d +tree -C --fromfile "$CPT_ROOT/var/db/cpt/installed/$1/manifest" | sed 1d diff --git a/contrib/cpt-owns b/contrib/cpt-owns index 9bc7d77..1f362d7 100755 --- a/contrib/cpt-owns +++ b/contrib/cpt-owns @@ -40,7 +40,7 @@ case "$1" in esac # Strip 'CPT_ROOT' from the file path if passed and follow symlinks. -file="${1#$CPT_ROOT}" +file="${1#"$CPT_ROOT"}" dirname=$(_readlinkf "$CPT_ROOT/${file%/*}") file="$dirname/${file##*/}" diff --git a/contrib/cpt-reset b/contrib/cpt-reset index 2a1b66e..a2336e3 100755 --- a/contrib/cpt-reset +++ b/contrib/cpt-reset @@ -3,6 +3,7 @@ # # Disable word-splittng warnings as they're safe here. # shellcheck disable=SC2046 +# shellcheck source=../src/cpt-lib ## SYNOPSIS: ## .Nm @@ -11,10 +12,10 @@ ## removes all packages from the system that is not defined as a base package in ## .Pa /etc/cpt-base . -[ "$1" ] && { - printf 'usage: %s\n\nRemove all packages not defined in the base.\n' \ - "${0##*/}" - exit 0 +parser_definition() { + setup REST help:usage -- "usage: ${0##*/}" + global_options compact + msg -- '' "Remove all packages outside of base definition" } . cpt-lib @@ -27,9 +28,14 @@ set +f; for pkg in *; do contains "$base" "$pkg" || set -- "$pkg" "$@" done -[ "$1" ] && { - printf 'WARNING: This will remove \033[1m%s\033[m package(s).\n' "$#" - printf 'Base packages can be redefined in %s\n' "$CPT_ROOT/etc/cpt-base" - printf 'Continue? [Enter/Ctrl+C]\n' - read -r _ && CPT_FORCE=1 cpt-remove "$@" +[ -z "$1" ] && { + log "No package outside of the base definition could be found, not continuing." + exit 0 } + +warn "" "This is a potentially harmful operation, do NOT continue unless" +warn "" "you know exactly what you are doing. Continuing will remove $#" +warn "" "packages that are not listed in the base definition or that the" +warn "" "base packages don't depend on. See the CPT BASE section on the" +warn "" "user manual to learn more." +prompt && cpt-remove "$@" diff --git a/contrib/cpt-size b/contrib/cpt-size index 4b983a1..22a77b7 100755 --- a/contrib/cpt-size +++ b/contrib/cpt-size @@ -3,6 +3,7 @@ ## SYNOPSIS: ## .Nm +## .Op Fl st ## .Op Ar pkg... ## DESCRIPTION: @@ -10,9 +11,21 @@ ## calculates the sizes of given ## .Ar packages ## using the files from the package manifest and outputs a total size of the -## packages along with all the files associated with them. +## packages along with all the files associated with them. If no arguments have +## been given, +## .Nm +## will use the name of the current directory as an argument. +## .Pp +## The options are as follows: +## .Bl -tag -width 13n +## .It Fl s +## Sort the output by size. +## .It Fl t +## Output only the size of given packages and not individual files. parser_definition() { - setup REST help:usage -- "usage: ${0##*/} [pkg...]" + setup REST help:usage -- "usage: ${0##*/} [-st] [pkg...]" + flag sort -s hidden:1 + flag total -t hidden:1 disp :usage -h --help hidden:1 } @@ -20,14 +33,28 @@ parser_definition() { # shellcheck disable=1091 . cpt-lib +# Use the current directory if no arguments have been given. +[ "$1" ] || set -- "${PWD##*/}" + # Ensure that all the packages given as arguments are installed. pkg_list "$@" >/dev/null mkdir -p "$tmp_dir" # We don't immediately pipe into awk as we want to exit in an error. -for pkg; do sed '/\/$/d;s/./\\&/g' "$sys_db/$pkg/manifest"; done | - xargs du -k > "$tmp_dir/size" +if [ "$total" ]; then + for pkg; do + sed '/\/$/d;s/./\\&/g' "$sys_db/$pkg/manifest" | + xargs du -k | + awk -v name="$pkg" '{size+=$1}END{printf("%s %s\n", size, name)}' >> "$tmp_dir/size" + done +else + for pkg; do sed '/\/$/d;s/./\\&/g' "$sys_db/$pkg/manifest"; done | + xargs du -k > "$tmp_dir/size" +fi + +# Do a numerical sort on the file if requested. +[ "$sort" ] && sort -no "$tmp_dir/size" "$tmp_dir/size" # This awk function formats the `du` output similar to the '-hc' flags. We # could have used a shell `while read` loop to do the exact same thing, but that |