Register
It is currently Wed Jul 23, 2014 10:22 pm

zip2tar


All times are UTC - 6 hours


Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Sun Oct 22, 2006 2:27 pm   

Joined: Wed Sep 06, 2006 12:19 pm
Posts: 54
Location: Covington, WA
Here's a simple program to convert zip files to tarballs........To keep it simple, this will only create a single tarball, and using wildcards in the zip filename is not supported.........To do multiple archives, you'll need to run it through a loop...... :-)

Output can also be piped to another program, such as gzip or bzip2, by omitting the name of the tar file or using '-' in place of the tarball name.....

Code:
#! /bin/bash
##
## zip2tar: Convert a zip file to a tar file
##

readonly PROG="${0##*/}"

## Change to suit.  ('/var/tmp/tmpfs' is a tmpfs mounted dir on my machine):
TDIR="/var/tmp/tmpfs/${PROG}"

## Cleanup on exit:
trap "rm -rf '${TDIR}'" EXIT

## Assign args:
test -z "${1}"  &&
    { echo -e "\tUsage: ${PROG} filename.zip [filename.tar]"; exit 1;}
ZIP="${1}"
TAR="${2}"
## If no tar file named, we'll assume STDOUT:
test -z "${TAR}"  &&  TAR="-"

## Set up clean temp dir:
rm -rf "${TDIR}"
mkdir -p "${TDIR}"

## Unzip to temp dir, then tarball the contents (only) of the temp dir
## to named tar file (or STDOUT if no tar file was specified):
unzip -qq "${ZIP}" -d "${TDIR}"  ||  exit $?

## List files in directory order (unsorted), not alphabetical order, to speed
## things up a bit:
LIST="$(ls -UA "${TDIR}")"  ||  exit $?
test -z "${LIST}"  &&
    { echo -e "${PROG}: No files or directories found for tarring"; exit 1;}
tar cCf "${TDIR}" "${TAR}" ${LIST}

exit 0

NOTE: To help speed things up a bit, point the temp directory (TDIR) to a tmpfs mounted directory........Just make sure you have enough space allocated for large archives... ;-)

:-)
---thegeekster


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP