Skip to content

Commit

Permalink
Add ziptotar.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Frenzie authored Oct 24, 2017
1 parent 8292cc3 commit 235cefd
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions ziptotar.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh
# Usage: ziptotar.sh <filename1> <filename2> …
# 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

0 comments on commit 235cefd

Please sign in to comment.