Skip to content

Instantly share code, notes, and snippets.

@growtopiajaw
Forked from natemcmaster/zip2tgz.sh
Last active December 29, 2018 15:37
Show Gist options
  • Save growtopiajaw/1cf82688e22a499b7ec665935e4a4491 to your computer and use it in GitHub Desktop.
Save growtopiajaw/1cf82688e22a499b7ec665935e4a4491 to your computer and use it in GitHub Desktop.
Convert zip to tar.gz file
#!/usr/bin/env bash
if [[ $# < 2 ]]; then
echo "Usage: [src] [dest]"
exit 1
fi
function realpath() {
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}
src="$(realpath $1)"
dest="$(realpath $2)"
echo "Converting:"
echo " - $src"
echo " => $dest"
tmp="$(mktemp -dp /app/tmp)"
echo "Using temp dir $tmp"
function cleanup() {
echo "Cleaning up"
rm -rf $tmp
echo "Done"
}
trap cleanup INT TERM EXIT
set -e
unzip -q $src -d $tmp
chmod -R +r $tmp
tar -c -z -f $dest -C $tmp .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment