Last active
October 4, 2019 22:35
-
-
Save simonsj/d8366f6c0e46a4d56e517bb3c94c879f to your computer and use it in GitHub Desktop.
sd.sh -- spool and sniff stdin stream to dispatch depending on contents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # sd.sh -- spool and sniff stdin stream to dispatch depending on contents | |
| # | |
| # Dependencies: basename, bash, cat, head, mktemp, stat, tail, tr. | |
| # | |
| set -e | |
| header=$(mktemp -t $(basename $0)-XXXXXX) | |
| trap "rm -f $header" EXIT | |
| head -c 262 > $header | |
| size=$(stat --printf="%s" $header) | |
| if [ $size -eq 262 -a "$(tail --bytes=5 $header | tr -d '\0')" = "ustar" ]; then | |
| echo "tarball: yes" 1>&2 | |
| else | |
| echo "tarball: no" 1>&2 | |
| fi | |
| exec cat $header - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment