From 5cf463c4ff0d1e36c76bf157fe52c0106c256bb0 Mon Sep 17 00:00:00 2001 From: merakor Date: Mon, 4 May 2020 12:44:45 +0000 Subject: kiss: accomplish tar portability FossilOrigin-Name: fb55846108c2045bd0245a16ae989e1d1a075d089158659ee75d6a819698ef06 --- kiss | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file 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) -- cgit v1.2.3