Skip to content

Instantly share code, notes, and snippets.

@simonsj
Last active October 4, 2019 22:35
Show Gist options
  • Select an option

  • Save simonsj/d8366f6c0e46a4d56e517bb3c94c879f to your computer and use it in GitHub Desktop.

Select an option

Save simonsj/d8366f6c0e46a4d56e517bb3c94c879f to your computer and use it in GitHub Desktop.
sd.sh -- spool and sniff stdin stream to dispatch depending on contents
#!/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