It is currently Sun May 27, 2018 9:07 pm


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.....

#! /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):

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

## Assign args:
test -z "${1}"  &&
    { echo -e "\tUsage: ${PROG} [filename.tar]"; exit 1;}
## 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... ;-)


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: No registered users and 7 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