aboutsummaryrefslogtreecommitdiff
path: root/contrib/cpt-export
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/cpt-export')
-rwxr-xr-xcontrib/cpt-export22
1 files changed, 13 insertions, 9 deletions
diff --git a/contrib/cpt-export b/contrib/cpt-export
index 9b4edd1..d0ce36a 100755
--- a/contrib/cpt-export
+++ b/contrib/cpt-export
@@ -3,7 +3,7 @@
case "$1" in
--help|-h)
- printf '\033[1;33m-> \033[m%s\n' "usage: ${0##*/} [pkg]"
+ printf 'usage: %s [pkg]\n' "${0##*/}"
exit 0
;;
'') set -- "${PWD##*/}"
@@ -15,23 +15,27 @@ cpt-list "${1:-null}" >/dev/null
read -r ver rel 2>/dev/null < \
"$CPT_ROOT/var/db/cpt/installed/$1/version"
+# Fallback to gzip if there is a typo
+case "$CPT_COMPRESS" in bz2|gz|xz|zst) ;; *) CPT_COMPRESS=gz; esac
+
# Reset the argument list.
pkg=$1
+tarball="$PWD/$1#$ver-$rel.tar.$CPT_COMPRESS"
set --
# Construct the argument list using each file.
-while read -r file; do
- [ -d "$CPT_ROOT/$file" ] || set -- "$@" ".$file"
-done < "$CPT_ROOT/var/db/cpt/installed/$pkg/manifest"
+eval set -- "$(sed '/\/$/d;s|^|".|;s|$|"|' \
+ "$CPT_ROOT/var/db/cpt/installed/$pkg/manifest" | tr '\n' ' ')"
# Turn the list of files back into a package.
-: "${CPT_COMPRESS:=gz}"
-tar cf - -C / -- "$@" | case "$CPT_COMPRESS" in
+cd "$CPT_ROOT/"
+tar cf - -- "$@" |
+
+case "$CPT_COMPRESS" in
bz2) bzip2 -z ;;
gz) gzip -6 ;;
xz) xz -zT 0 ;;
zst) zstd -3 ;;
- *) gzip -6 ;; # Fallback to gzip
-esac > "$pkg#$ver-$rel.tar.$CPT_COMPRESS"
+esac > "$tarball"
-printf 'tarball created in %s\n' "$PWD/$pkg#$ver-$rel.tar.$CPT_COMPRESS"
+printf 'tarball created in %s\n' "$tarball"