aboutsummaryrefslogtreecommitdiff
path: root/kiss
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2020-05-04 12:44:45 +0000
committermerakor <cem@ckyln.com>2020-05-04 12:44:45 +0000
commit5cf463c4ff0d1e36c76bf157fe52c0106c256bb0 (patch)
treecda164e08671cc46ceda926b540631167653209f /kiss
parent1f8a7fc928ea694264835c7b06d5cab7f66484c9 (diff)
downloadcpt-5cf463c4ff0d1e36c76bf157fe52c0106c256bb0.tar.gz
kiss: accomplish tar portability
FossilOrigin-Name: fb55846108c2045bd0245a16ae989e1d1a075d089158659ee75d6a819698ef06
Diffstat (limited to 'kiss')
-rwxr-xr-xkiss41
1 files changed, 39 insertions, 2 deletions
diff --git a/kiss b/kiss
index 45d6023..893cf38 100755
--- a/kiss
+++ b/kiss
@@ -310,9 +310,46 @@ pkg_extract() {
# extraction. Other filetypes are simply copied to '$mak_dir'
# which allows for manual extraction.
*://*.tar|*://*.tar.??|*://*.tar.???|*://*.tar.????|*://*.tgz)
- decompress "$src_dir/$1/${src##*/}" |
- "$tar" xf - --strip-components 1 ||
+ decompress "$src_dir/$1/${src##*/}" | "$tar" xf - ||
die "$1" "Couldn't extract ${src##*/}"
+
+ # Again, decompress but to 'tar tf -' this time. We get the
+ # base files in the package. We use this to do our version
+ # of 'strip-components'.
+ decompress "$src_dir/$1/${src##*/}" | "$tar" tf - |
+ while read -r file; do
+ printf '%s\n' "${file%%/*}"
+ done | uniq |
+
+ # For every directory in the base we move each file
+ # to the upper directory.
+ while read -r dir ; do
+ # Skip if we are not dealing with a directory here.
+ [ -d "$dir" ] || continue
+
+ # Change into the directory in a subshell so we don't
+ # need to cd back to the upper directory.
+ (
+ cd "$dir"
+
+ # We use find because we want to move hidden files
+ # as well.
+ #
+ # Skip the file if it has the same name as the directory.
+ # We will deal with it later.
+ find . \( ! -name . -prune \) \
+ ! -name "$dir" -exec mv {} .. +
+
+ # If a file/directory with the same name as the directory
+ # exists, append a '.kissbak' to it and move it to the
+ # upper directory.
+ ! [ -e "$dir" ] || mv "$dir" "../${dir}.kissbak"
+ )
+ rmdir "$dir"
+
+ # If a backup file exists, move it into the original location.
+ ! [ -e "${dir}.kissbak" ] || mv "${dir}.kissbak" "$dir"
+ done
;;
*://*.zip)