Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- TAR_FILE="$1"
- shift
- TMP_ROOT="/dev/shm" # ...or /tmp
- TMP_DIR="$(mktemp -d "$TMP_ROOT/xargs-tar-XXXXXX")"
- UNTAR_DIR="$TMP_DIR/untar"
- FILE_LIST="$TMP_DIR/files-list"
- EXEC_FILE="$TMP_DIR/exec-file"
- mkdir -p "$UNTAR_DIR"
- mkfifo "$FILE_LIST"
- (
- # single quotes for user's command and args
- for i in "$@"; do
- echo -n "'$i' "
- done
- echo '"$@"'
- echo 'rm "$@"'
- ) > "$EXEC_FILE"
- chmod u+x "$EXEC_FILE"
- # Background untar. Write file list (zero terminated, no directories) to named
- # pipe. The output is one line delayed to make sure we print only finished file
- # names.
- (
- tar -v -C "$UNTAR_DIR" -xf "$TAR_FILE"
- | awk 'BEGIN {last = "";}
- !//$/ {if (last != "") print last; last=$0;}
- END {if (last != "") print last;}'
- | tr 'n' '