From 235cefd124ce5807013520ace1b029824fe77c8b Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Tue, 24 Oct 2017 16:10:25 +0000 Subject: [PATCH] Add ziptotar.sh --- ziptotar.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 ziptotar.sh diff --git a/ziptotar.sh b/ziptotar.sh new file mode 100644 index 0000000..ba03e9d --- /dev/null +++ b/ziptotar.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# Usage: ziptotar.sh … +# Based on https://techoverflow.net/2012/11/22/convert-zip-to-tar-using-linux-shell/ + +set -e +if [ "$#" -lt 1 ]; then + echo "Need at least one filename." + exit 1 +fi + +for file in "$@"; do + tmpdir=$(mktemp -d) + #Copy the zip to the temporary directory + cp "${file}" "${tmpdir}/" + #Unzip + (cd "${tmpdir}" && unzip -q "${file}") + #Remove the original zipfile because we don't want that to be tar'd + rm "$tmpdir/${file}" + #Tar the files + outfilename=$(echo "${file}" | rev | cut -d. -f2- | rev).tar.lz + (cd "${tmpdir}" && tar --lzip -cvf "$outfilename" ./*) + mv "${tmpdir}/${outfilename}" . + #Remove the temporary directory + rm -rf "${tmpdir}" + #Print what we did + echo "Converted ${file} to ${outfilename}" +done