Skip to content

Instantly share code, notes, and snippets.

@whiteley
Created April 1, 2016 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whiteley/455a4f66f468632ad53bb638eb821a3f to your computer and use it in GitHub Desktop.
Save whiteley/455a4f66f468632ad53bb638eb821a3f to your computer and use it in GitHub Desktop.
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
umask 077
readonly checksum="sha1sum"
readonly dir="$(dirname ${1})"
readonly gzf="$(basename ${1})"
readonly xzf="$(basename ${gzf} .gz).xz"
pushd ${dir} >/dev/null
sum1=$(gzip -dc ${gzf} | tee >(xz > ${xzf}) | ${checksum})
sum2=$(xz -dc ${xzf} | ${checksum})
chown --reference=${gzf} ${xzf}
chmod --reference=${gzf} ${xzf}
if [[ "${sum1}" == "${sum2}" ]]; then
rm -f ${gzf}
fi
popd >/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment